Designing the Game
Now that you understand the basic idea behind the game, let's focus on a few details regarding the design of the game. The player's car can move horizontally across the game screen, which means that its position is confined to the x axis. The player can shoot up verticallywith his Twinkie missiles terminating at the top of the screen, similar to the missiles in the Meteor Defense game from Hour 19, "Example Game: Meteor Defense."
The aliens in Space Out can move around in any direction and at different velocities. The Blobbo and Jelly aliens bounce off of the edges of the screen, while Timmy is allowed to wrap around and appear on the other side. This is because Timmy has a tendency to fly horizontally across the screen, whereas the others move around a little more randomly. All the aliens fire missiles down toward the player's carwith the missiles terminating when they strike the car or the ground. The aliens are immune from their own missiles, so they can't hit each other. This is a good thing for the aliens because they aren't very careful in terms of how they aim.
Space Out has no discrete levels and no real goal other than surviving. However, the difficulty level of the game does gradually increase as the player progresses through the game. The difficulty of the game increases by adding new aliens at a faster pace. Eventually the player will have his hands full trying to contend with a never-ending army of aliens. That's the whole fun of shoot-em-ups!
To help you get a feel for how the Space Out game is laid out, take a look at Figure 21.1.
Figure 21.1 The Space Out game consists of a starry background, a ground desert image, a car, aliens, and missiles that are fired between the car and aliens.
The figure shows the background image of the desert, which serves as a backdrop for the car to drive around on. The starry background still appears in the majority of the screen, whereas the background image shows the desert where the car drives around. The background image actually includes a horizontal band of sky that helps blend the desert landscape into the starry background. The car sprite moves around on top of the desert background image. The aliens appear in the sky and move around trying to hit the car by firing various missiles. Of course, the car also fires missiles back at the aliens. The score for the game is displayed in the upper right corner of the game screen, along with the number of remaining lives (cars).
Now that you understand the basics of the game, it's important to examine the sprites that it requires. Following is a list of the sprites that go into the Space Out game:
Missile sprites (from the aliens and the car)
The only type of sprite in this list that I haven't mentioned is the explosion sprite, which is used to show an alien being destroyed by a missile, as well as the car being destroyed by an alien missile. Two different sizes of explosions are actually used in the Space Out game. The larger explosion is used to show an alien or the car being destroyed, whereas the smaller explosion is used to show a missile exploding. This distinction is important because it shows how missiles cause a smaller explosion when they simply crash into the desert, as opposed to hitting the car.
In addition to the sprites, the Space Out game requires several bitmaps. Following are the bitmap images required of the game:
Background desert image
Missile image (fired by car)
Alien images (Blobbo, Jelly, and Timmy; animated)
Missile images (fired by each of the three aliens)
Explosion images (animated; small and large)
Small car image
Game over image
These images flow directly from the design of the game that you've covered thus far, so there hopefully shouldn't be any big surprises here. Perhaps the main thing to point out is that the aliens all rely on animated images to provide them with a more interesting appearance as they move around on the game screen. The only other animated images in the game are the explosion images, which go with the explosion sprites.
The score needs to be maintained throughout the game, as well as the number of remaining lives (cars); the game ends when all three of your cars have been destroyed. The difficulty level of the game is stored away in a global variable, and gradually increases as the player racks up points and progresses through the game. Another important piece of information is the familiar Boolean variable that keeps track of whether the game is over.
The last global game variable required of Space Out is an input delay variable that helps add some restraint to the player's ability to fire missiles rapidly. Without this input delay variable, it would be too easy to wipe out the aliens by holding down the fire key (Spacebar) and raining missiles on the aliens with little effort. By slowing down the number of missiles that can be fired, the player is forced to be more accurate and evade aliens when they miss. Establishing the appropriate delay is somewhat of a trial-and-error process, and you might decide that the game is more fun with a slightly different value than I used.
To recap, the design of the Space Out game has led us to the following pieces of information that must be managed by the game:
The number of lives (cars) remaining
The difficulty level
A Boolean game over variable
A delay variable for firing input
Before diving into the code for the Space Out game, you need to add a new feature to the game engine. Although the game engine is a flexible piece of software, you will likely find yourself adding new features in the future to accommodate the special needs of new games. This is a good thing because you get to reuse those features in any game that you create from then on.