Game Development Reference
In-Depth Information
Moving the player using key logic (iteration 2)
Now we are going to tackle moving the player about the maze and going through tunnels (they
warp to the other side if the tile on the opposite side is an open one. Since we have not yet
added this game to the framework, the first task we must tackle is setting up a simple
ENTER_FRAME event for our game loop. This will be replaced later in the chapter when we
integrate with the framework.
We will be changing the name of the file to GameDemoIteration2.as . You are not required to do
this unless you want to have a keepsake of each iteration in the chapter. If you do create a new
file, make sure the class name and constructor are changed to correspond to the new name. If
you are using the IDE, you will need to make sure the document class attribute references the
new class name.
This is the file path for the Flash IDE:
/source/projects/notanks/flashIDE/com/efg/games/notanks/GameDemoIteration2.as
And this one is for the Flex SDK (using Flash Develop):
/source/projects/notanks/flexSDK/src/com/efg/games/notanks/GameDemoIteration2.as
Changing the class name for iteration 2
We have a new file name for the game demonstration, so now, we will need to change the class
name to match. We will also need to change the name of the constructor function. First, we will
change the class name.
public class GameDemoIteration2 extends Sprite
{
Next, we will change the constructor.
public function GameDemoIteration2() {
Adding a simple placeholder game timer
For the simple placeholder game timer, we will use a standard ENTER_FRAME event. Our game is
being designed to eventually use the Main.as game timer, so all of this code will be replaced
upon integration with the Main class. For now though, it can be used to demonstrate all game
logic except starting new levels and new player tanks after they have been destroyed.
First, we must import the event package in import section of the code:
import flash.events.*;
We are going to accept key input into our game. The game will need the focus of the Flash Player
to ensure that key input is accepted properly. We don't want the focusRect to display when our
game Sprite has focus, so we make sure it is turned off.
In the init function, you should add this line:
this.focusRect = false;
Next, we have to find a place to add in the temporary event listener. We have chosen to do it
inside the restartPlayer function. Only a portion of the function is listed in this section. The bold
Search WWH ::




Custom Search