Home > Articles > Programming > Games

  • Print
  • + Share This
This chapter is from the book


  1. Why does the HandleKeys() function change the velocity of the car sprite in response to the arrow keys, instead of directly changing its position?

  2. The HandleKeys() function could certainly change the position of the car sprite to get a similar result, but by changing the velocity you get a smoother sense of control in the game. More specifically, the movement of the car isn't choppy because when it changes direction, it actually decelerates and then accelerates again. This is a minor detail, but one that helps to add a touch of realism to the game.

  3. Why doesn't the Space Out game include a unique derived Sprite class for each kind of alien?

  4. The game could have been designed to utilize three derived Sprite classes such as BlobboSprite, JellySprite, and TimmySprite, but in reality it just wasn't necessary to break out the code that much. If the different aliens had required radically different functionality within them, this approach might have made more sense. And if you're a stickler for adhering to object-oriented design, you could still go back and redesign the game around three alien classes instead of one. However, I usually err on the side of simplicity, and in this case one class does the trick just fine.

  • + Share This
  • 🔖 Save To Your Account