I'm making a side scrolling game in as3, where the player spawns units which automatically walks towards the exit on the other side of the screen, but there are towers stopping them. I would like the towers to shoot separately, is there any way? Here's my code, once the if statements are satisfied all towers fire at the same time.
private function tower1Fire():void
{
for (var j:int = creep1Array.length - 1; j >= 0; j--)
{
for each (var towerOne:mcTower1 in tower1Array)
{
if (creep1Array[j].x - towerOne.x <= 100 && creep1Array[j].y > towerOne.y)
{
var newTower1Bullet:mcLaser1 = new mcLaser1;
newTower1Bullet.x = towerOne.x;
newTower1Bullet.y = towerOne.y;
tower1BulletArray.push(newTower1Bullet);
stage.addChild(newTower1Bullet);
}
}
}
}
I have 3 towers on the screen, added using this code:
var tower1New1:MovieClip = new mcTower1;
tower1New1.x = 313;
tower1New1.y = 340;
tower1Array.push(tower1New1);
MovieClip(root).addChild(tower1New1);
I don't get any error. Any reply will be appreciated, thanks!