Question

I'm making a top down shooter for a college project. I'm getting extremely low on available time left to complete this.

I followed a tutorial as we was not taught any AS3 although expected to creating a game in this language so there is commented code due to this. The tutorial lead me up to creating a player on the stage that moves by keyboard presses and can fire bullets by pressing the left mouse button, but it didn't help with creating enemies at all.

So I created an enemy movie clip that just spawns on the stage at X=0 and Y=0 (random spawning will be added later), and it's supposed to move towards the players location but it doesn't. When the swf loads up it appears they have started to move but have frozen on the screen. It's not crashed because I can still move the player around and fire bullets? Any help is appreciated.

Main.as code

Enemy.as code

Was it helpful?

Solution

Well, you are not calling the moveTowards() in any loop -> the position is not updated. Or where exactly are you updating the enemy's position? I see only one setting of .x, .y of enemy and it is right after you create the object, no further updates.

Put this into your loop function in Main.as:

for(var i:int=0; i<enemies.length; i++) {
    Enemy(enemies[i]).moveTowards(player.x, player.y);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top