Game Development Reference
In-Depth Information
Once again, we are going to change to a new class name for this iteration.
This is the Flash IDE path:
/source/projects/notanks/flashIDE/com/efg/games/notanks/GameDemoIteration6.as
And this is for the Flex SDK (using Flash Develop):
/source/projects/notanks/flexSDK/src/com/efg/games/notanks/GameDemoIteration6.as
Changing the class name for iteration 6
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 again
modify the class name.
public class GameDemoIteration6 extends Sprite
{
Then, we modify the constructor.
public function GameDemoIteration6() {
Making additions to the restartPlayer function
First, we need to add a line to the restartPlayer function. You only need to add in the following
bold code; the other code should already be in the function and is listed for reference:
playerInvincibleCount = 0;
//** added iteration 6
setCurrentRegion(player);
//** end added iteration 6
//this is as good a place as any for now
addEventListener(Event.ENTER_FRAME, runGame, false,0,true);
Next, we will look at the changes to the render function for setting the currentRegion attribute of
the player. The line we need was already added to the render function. We have a comment mark
in front of it though. Now it is time to remove the comment from the line.
if (!player.inTunnel) {
switchMovement(MOVESTOP, player);
//*** uncommented in iteration #6
setCurrentRegion(player);
//*** end uncommented in iteration #6
//once player gets to center, check the enemy chase AI
}
Modifying the update and render functions for enemy tanks
Enemy tanks are updated in the same manner as the player. They can move about the maze in
the same manner as the player and even utilize the warp tunnel off the sides, top, and bottom of
the game screen. To render the enemy tanks, we first update the nextX and nextY values. Next, if
the tank is in a tunnel, we check to see if it is out of the tunnel. Finally, we update the currRow and
Search WWH ::




Custom Search