I’m currently just venturing into AS3 in classes and am building a tower defense game from the ground up, what I need to know is there a way to call in a second array to replace the first, while displacing the first one from the scene?
Here’s the code that I’m pretty sure I need to add something into:
private var level1:Array = new Array(
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 1, 1, 5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 4, 1, 1, 1, 1, 1, 6, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
);
private var level2:Array = new Array(
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1,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,
0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 7, 3, 1, 1, 4, 0, 0, 7, 1, 1, 1, 1, 1, 1, 1, 1, 4, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
);
public var enemies:Array = new Array();
public var fastEnemies:Array = new Array();
public var strongEnemies:Array= new Array();
public var wayPoints:Array = new Array();
private var counter:Number = 0;
private var rows:Number = 12;
private var cols:Number = 20;
private var startX:Number = 24; //81+15-- 96 center on a 800x600
private var startY:Number = 24; //109+15-- 124
private var space:Number = 2;
public var money:Number = 100;
public var lives:Number = 3;
public var en:Enemy;
public var fen:FastEnemy;
public var sen:StrongEnemy;
public var gameOver:Boolean = false;
public var turret1:Turret;
private var startPoint:MovieClip = new MovieClip();
public var endPoint:MovieClip = new MovieClip();
private var enemyTimer:Timer = new Timer(1000, 10); //change back to 10 later
private var waveTimer:Timer = new Timer (5000);
public function Game():void
{
stop();
turret1 = new Turret ();
turret1.x = 684;
turret1.y = 28;
addChild(turret1);
//trace(turret1.cost);
cost1_txt.text = turret1.cost.toString();
for (var i:uint = 0; i < rows; i++)
{
for (var j:uint = 0; j < cols; j++)
{
var tile:Tile = new Tile(level1[counter]);
tile.x = startX + ((tile.width + space) * j);
tile.y = startY;
if (level1[counter] == 0)
{
tile.buttonMode = true; //makes the hand visible so you know where is clickable
tile.addEventListener(MouseEvent.MOUSE_UP, spawnTurret);
}
if (level1[counter] == 2)
{
startPoint = tile;
}
if (level1[counter] == 3)
{
endPoint = tile;
}
if (level1[counter] >=4)
{
wayPoints.push(tile);
}
addChild(tile);
counter++
}
startY += tile.height + space;
}
enemyTimer.addEventListener(TimerEvent.TIMER, spawnEnemy);
enemyTimer.start();
waveTimer.addEventListener(TimerEvent.TIMER, startWave);
update ();
}
Although… I might need to put the update in this area
private function spawnEnemy(e:TimerEvent):void
{
//trace(e.target.x + " " + e.target.y)
if (enemyTimer.currentCount == 10)
{
waveTimer.start();
}
if (waveTimer.currentCount<=2 || waveTimer.currentCount>=4 && waveTimer.currentCount!=10)
{
en = new Enemy();
en.x = startPoint.x;
en.y = startPoint.y;//284 will place closeto center
addChild(en);
enemies.push(en);
}
if (waveTimer.currentCount == 3)
{
fen = new FastEnemy();
fen.x = startPoint.x;
fen.y = startPoint.y;
addChild(fen);
fastEnemies.push(fen);
}
if (waveTimer.currentCount == 10)
{
sen = new StrongEnemy();
sen.x = startPoint.x;
sen.y = startPoint.y;
addChild(sen);
strongEnemies.push(sen);
}
}
(And I am using multiple ASC files to do my coding, this is all from my GAME class… my tiles are from a different class but my Arrays place them down)
What I’m looking to do is that after the third wave (just for level one! so the level1 array) I want to (if the player still has lives) switch to my level2 Array and clear the board of all turrets… Any ideas how I do this?