# Sprite Animation for Game Programming

• Print
This chapter is from the book

## Designing the Game

The overview of the Henway game has already given you a leg up on the game's design, even if you don't realize it. For example, you already know how many sprites are required for the game. Can you hazard a guess? There are five sprites in the game: one chicken sprite and four car sprites. There is certainly the opportunity to include additional car sprites if desired, but the basic game only uses four.

Beyond the sprites, can you guess how many bitmap images the game needs? If you guessed six, you're very close. Following are the seven bitmap images required of the game:

• Background highway image

• Chicken image

• Four car images

• Small chicken image

You probably factored in all these images except the last one. The small chicken image is used to convey to the player how many chickens are left. As an example, when the game starts, three small chickens are displayed in the lower right edge of the screen. As you sacrifice your chickens to the highway, the small chickens disappear until you have none left and the game is over.

Now that you have a feel for the graphical objects involved in the game, let's consider other data that must be maintained by the game. First, it's pretty obvious that you'll need to keep track of how many chicken lives are remaining. You'll also want to keep a running score that is added to each time a chicken makes it safely across the highway. A Boolean variable keeping track of whether the game is over is also required.

There is one last variable that would be hard for you to anticipate without actually developing the game and testing it out. I'm referring to an input delay variable, which helps to alter the keyboard and joystick input response to improve the playability of the game. If you directly responded to the keyboard and joystick in every game cycle, which is how you would logically support input in the game, the chicken would zip around the game screen too fast. There are just too many game cycles taking place to give input devices that much attention. In order to slow down the input a little, you can use a delay variable and only check for keyboard and joystick input every third game cycle. Determining the appropriate delay is somewhat of a trial and error process, so you're free to tinker with it and see what you like best. The point is that the game benefits dramatically from putting a leash on the speed of the user input handling.

To recap, the design of the Henway game has led us to the following pieces of information that must be managed by the game:

• The number of chicken lives

• The score

• A Boolean game over variable

• A delay variable

With this information in mind, you're now ready to move on and put the code together for the Henway game.