I finally looked into state machines and made one, then ported my previous game (first SFML project) to it. Everything is working fine, but while porting it I got some questions that maybe I can get an answer to here.
Please note
I don't need help, the game works, these are for future reference, to be honest don't know where to ask, so I will try it here.
I don't want to waste anyone's time, these are dumb questions, they came from my lack of programing and game creation knowledge.
Thank you if you decide to read it anyway.
SFML Relate Q:1. - Should I always draw the screen every frame? Even for screens that never changes, like a High Score list screen. If I only display it once, the only "problem" is if I minimize the window, and it comes back it won't show anything but thats fixable with a "on minimize draw again".
Or drawing it uses so little resources anyway that its pointless to stop it (using a if(bool) in the drawing method.
1.5 - If I draw several lines of text on screen, like on a High Score screen, should I have a SF::text for every line, or use only one, have a string[] to save the strings and a for loop to display them in place.
2. - In my game I earn points every second, except when the game is paused. Since I can't pause a clock, every second I add 1 to a counter Var and restart the clock. So when I pause, it still only counts a sec. Is this a good way to do it? Or there's a smart way I couldn't think of.
3. - The only problem in my game is controls. Here's some of it
sf::Event evt;
while (window.pollEvent(evt)) {
if (evt.type == sf::Event::KeyPressed)
switch (evt.key.code) {
case sf::Keyboard::P:
if(paused)
unpause
else
pause
case sf::keyboad::W:
blablabla...
If I press and hold P it pauses/unpauses the game every frame. I can solve this with a bool. (I don't like the "on key release", I like the responsiveness of "do it on keydown", because sometimes you hold the key just a little longer). I only pause/unpause if the bool is true. As soon as "keypressed" I set it to false, when key is release, I set it to true.
The real problem is... My game is a snake clone, so when I go right, I can't turn left before going up or down.
But, if I while going right, I press up then quickly left, I can move from left to right. I don't know how to solve this.
If I use the bool method, the game doesn't feel very responsive. And I think it still sometimes happens, its just harder to do.
If I use a clock and only process input every X ms... again, the controls don't feel responsive. Maybe I haven't found the right ms timing for it.
How could I solve this? I cant thin of a good solution.
NON SFML Q:As I said, these are dumb questions from my lack of knowledge, feel free to laugh and ignore them.
4. - I use PRAGMA ONCE on my .hpp files. a.hpp includes b.hpp and c.hpp. But then d.hpp includes a.hpp but also b.hpp, that was included in a.hpp... its a mess.
It works, but should I leave it as a mess? (maybe thats how its supposed to be) or should I use a "hppList.hpp" put all of them inside, and include this list only one in the main?
5. - In my game I have to sometimes wait for 1 second in that place before proceding with the code.
I use while (timer.getElapsedTime().asMilliseconds() < 1250) {}.
Is there a better way to pause the code? Ive done it before, but not on c++ and can't remember how.
6. - I don't check for errors, all the textures/soundbuffers/fonts work and load correctly.
The game will work, unless you move/delete the assets. But if you do, its not my fault. Reinstall it.
Still, is it the wrong thing to do? IS there a point of showing a error saying the game crashed because it can't load a texture/whatever when it was the users fault?
7. - I have a lot of warnings (around 15), most of them from "int to float conversion".
Should I try fix those or ignore them since the game works and actually no useful info is lost in the conversion.
If you read this far, thank you for your time, sorry for the wall of text boss.