Game Development Reference
In-Depth Information
Adding and moving enemy tanks (iteration 5)
The enemy tanks have one job—destroy the player tank. We will create our game logic for the
tanks in a manner similar to the player tank. One difference will be that the enemy tanks will have
some moderately smart AI code that will at least make them a moderate challenge against a
human opponent.
In this iteration, we will be reorganizing the game a little to get closer to the final version. This
means reordering and moving some of the current code and adding in code to place the enemy
tanks on the screen.
Once again, we are going to change to a new class name for this iteration.
In the Flash IDE, this is the file path:
/source/projects/notanks/flashIDE/com/efg/games/notanks/GameDemoIteration5.as
And in the Flex SDK (using Flash Develop), it's this one:
/source/projects/notanks/flexSDK/src/com/efg/games/notanks/GameDemoIteration5.as
Changing the class name for iteration 5
We once again 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. We first change the class name
public class GameDemoIteration5 extends Sprite
{
and then change the constructor name:
public function GameDemoIteration5() {
Let's look at the changes to the variable definition section for this iteration.
Updating the variable definitions for iteration 5
There are a few variables we need to add to this iteration for the enemy tanks to be successfully
added to the game screen. Also, we are going to add some variables that will contain region
information for the game screen.
Regions will be discussed in detail when we get to the enemy AI portion of the code, but for now,
just note that we have broken the game screen up into four regions. The regions are roughly
made up the tiles that make up the TOP_LEFT , TOP RIGHT , BOTTOM LEFT , and BOTTOM RIGHT portions
of the level map. These will be used to trigger enemy movement. If the player is in the same
screen region as an enemy tank (or tanks), then the enemy tank (or tanks) will start to chase the
player (more on this later in the section called “Chasing the player”).
Add these variables to the variable definition section of the game code:
//** added in iteration #5
private var regions:Array;
private var tempRegion:Object;
private var enemyList:Array;
private var tempEnemy:TileByTileBlitSprite;
//end iteration #5
Search WWH ::




Custom Search