Game Development Reference
In-Depth Information
Pixel Shooter is a simple arcade game where waves of faster and faster aliens fly down toward
the player's ship. The player's ship is controlled with the mouse, and missiles are fired with the
left button. When a missile hits an enemy ship, instead of having the ship just disappear as
enemies did in Balloon Saw, we will display an explosion on the screen.
For a game of this type, we will need to track a few more things than Balloon Saw. Besides
enemies, we must also keep track of and move missiles and explosions. In addition to testing
collisions between the player's ship and the enemies, we will need to test collision between the
missiles and the enemies. This time, a collision between an enemy and the player's ship results
in the player losing a chance, not gaining points. Points are scored when missiles hit enemies.
We will also be counting down the player's ships as they are destroyed, not counting up misses.
Pixel Shooter code highlights
We are not going to cover every line of Pixel Shooter, but we will discuss the major changes we
have made to the code to iterate a catch style game like Balloon Saw into a shoot 'em up.
New variables
We do not need many new variables to turn Balloon Saw into Pixel Shooter, and the ones we do
need are variations on variables that already existed.
The first two new variables are game states. We need both of these to help us start and restart
the player's ship on the screen. In Balloon Saw, the player's ship was never destroyed, so we
never had to restart it. However, in Pixel Shooter the player's ship can be destroyed, so we need
to handle that situation. With do that with STATE_START_PLAYER and STATE_REMOVE_PLAYER .
const STATE_START_PLAYER:int = 20;
const STATE_REMOVE_PLAYER:int = 40;
The next two variables are arrays that will hold the new objects types that we need to account for in
this game: missiles (fired by the player) and explosions (when an alien ship is hit with a missile).
public var missiles:Array;
public var explosions:Array;
Starting and restarting the player
Since we need to start and restart the player's ship, we also need to handle these states in our
game loop. For STATE_START_PLAYER , we call a newly created function named startPlayer() . For
STATE_REMOVE_PLAYER , we call removePlayer() .
public function gameLoop(e:Event) {
switch(gameState) {
case STATE_INIT :
initGame();
break
case STATE_START_PLAYER:
startPlayer();
break;
case STATE_PLAY_GAME:
playGame();
break;
case STATE_REMOVE_PLAYER:
Search WWH ::




Custom Search