Minor Update
Posted by Morpork at October 10th, 2008
Between the computer failing to start up, washing machine breaking down and general clogging up of the schedule, progress has really gotten hampered. Curiously, this began so soon after an announcement for a semi-goal oriented project begun spontaneously. It’s like the digital equivalent of people carrying glass panes and crossing the street.
Anyhow, I’d like to share a few bits of things I learned exploring SDL. A game loop is divided into three processes. The first is Input and takes care of user input. Basically setting flags and this equals true that equals false. Next, Logic takes these flags and use them to determine what to do. For example, if user hit fire weapon key, the create ball of plasma block of code runs and sets the projectile to have direction set to the facing of the player and with velocity of a plasma_projectile_initial_vel or something like that. Oh and Logic also takes care of what position of everything is. Finally, Display will show the user the red dot that is a plasma ball and refresh the screen. As the name game loop implies, this gets repeated over and over, with user input changing what logic does.
So what’s so good about adhering to these three steps? I think it just makes things easier to keep track of. If you had refresh screen somewhere up in logic, things can be messy on screen and things just won’t be in one place when debugging the code.
One last lesson is do not use two SDL_PollEvent() functions in one game loop. Each call flushes the event queue and renders the second one useless. This function is used in while() loops so just remember to put an if() conditional behind the while() if you have to use two of them. Or more. Because the while() needs to run the stuff in the brackets before checking the status to be true or false. Not that I’d make a mistake like that.
¬_¬


















