Game Development Reference
In-Depth Information
Game controls : The spacebar moves the player's space ship up. There are no other
controls. Gravity will be constantly pulling the ship down to the bottom on the screen.
Game level advancement : There are no distinct game levels, but after each 10
seconds the obstacles become more plentiful (and longer), change color, and the speed
of the game will increase.
Game end : When the player hits an obstacle, the game is over.
Game scoring : The player will receive points for each second in flight.
Let's talk now about the basic technical design information.
We now know the type of game that we want to create, and we have 48 hours to do it. With this
limited time frame, we will need to make some vital decisions on how to proceed with the
technical design. First, let's discuss the scrolling. We could employ a tile-based scrolling engine
(see Chapter 10), or we could go with the screen-based engine presented in Chapter 11. Even
though both of these engines have been created and the necessary classes are already part of
the package structure, we might not even need to use them.
The only vital items that move in the game are the obstacles, and the world really is just a series
of obstacles that scroll toward and passed the player from right to left. If done properly, we only
need to make it appear that the player is moving from left to right, when in actuality, the player
stays in the middle of the screen. We will add some extra hints at the player movement by adding
some exhaust particles that move and fade out behind the player.
Note: We will be showing a lot of code in the next sections as a demonstration of how functions
will work. The entire set of code for Tunnel Panic is in the section called “Coding the
TunnelPanic.as Class.”
Creating the PlayerSprite object
For our player, we'll create a 32
32-pixel sprite using a standard Flash Sprite instance. The
sprite will be drawn using a vector drawing canvas. The player ship will remain in the middle of
the screen and will be pulled down by gravity each frame tick. The space bar will be used to move
the object up. The variables needed for the player are as follows:
private var playerSprite:Sprite = new Sprite();
private var playerShape:Shape = new Shape();
private var playerSpeed:Number = 4;
private var playerStarted:Boolean = false;
private var gravity:Number = 1;
The playerShape variable will be the vector canvas that holds the shape we will draw for the
player. playerSpeed represents how many pixels the ship will move up when the space bar is
pressed by the game player. And the playerStarted variable will be used to stop player input
when before a new the game play has begun.
The gravity value will be added to the y attribute of playerSprite on each frame tick, and
playerSpeed will counteract this gravity when the player presses the space bar.
Search WWH ::




Custom Search