Game Development Reference
In-Depth Information
Updating the move states for player movement
(iteration 3)
Now, we are going to start adding in quite a few new functions to handle the actual movement
logic. First, let's take a look at the constant variables that we will use to control the current move
state of the player. We are going to change to a new class name for this iteration.
As usual, we'll provide you with the file path for the Flash IDE:
/source/projects/notanks/flashIDE/com/efg/games/notanks/GameDemoIteration3.as
and for the Flex SDK (using Flash Develop):
/source/projects/notanks/flexSDK/src/com/efg/games/notanks/GameDemoIteration3.as
Changing the class name for iteration 3
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. As before, we
first change the class name.
public class GameDemoIteration3 extends Sprite
{
Next, we modify the constructor name.
public function GameDemoIteration3() {
Adding the move state constants
The following states were already added to the variable definition section in iteration 1, but we
have not discussed them much:
//movement specific variables
public static const MOVE_UP:int = 0;
public static const MOVE_DOWN:int = 1;
public static const MOVE_LEFT:int = 2;
public static const MOVE_RIGHT:int = 3;
public static const MOVE_STOP:int = 4;
We will use these states when evaluating the current and next directions for the game characters.
We assign them as constants to make them easier to remember than strings or straight integers.
Plus, if you are using an advanced editor (such as Flash Develop, Flex Builder, Flash Builder, or
the CS5 IDE), constant variables show up in the code hinting to make them very easy to use.
Changing the runGame function for iteration 3
Now, we will add in some code to the runGame function to check the keyPressList array for the
various movement directions on each frame tick:
public function runGame(e:Event):void {
if (playerStarted) {
checkInput();
}
}
Search WWH ::




Custom Search