Hello all,
I just finished some code to get enemies in my game but im experiencing strange behaviour within the game.
My game currently is a 2000x2000 map which can be scrolled by moving the mouse to the edge of stage… i just tried adding some enemies.
Let me post a screenshot:
Whats happening here is that the red bordered enemies stick to a position on the screen. The green bordered enemy scrolls with the map.
In my code im trying to spawn 10 enemies, and have them update their positions according to map scrolling.
heres my code
enemy AS file:
package game{
import flash.display.MovieClip;
import core.*;
import lib.*;
import game.*;
public class game_enemy extends MovieClip {
private var this_enemy:enemy_gfx = new enemy_gfx;
private var this_x:int;
private var this_y:int;
public function game_enemy( ex:Number,ey:Number,speed:Number) {
//this_enemy = new enemy_gfx;
this_x=ex;
this_y=ey;
this_enemy.x=this_x-game_engine.vX;
this_enemy.y=this_y-game_engine.vY;
game_engine.scr.addChild(this_enemy);
}
public function move_enemy() {
// isnt moving yet, just updating position
this_enemy.x=this_x-game_engine.vX;
this_enemy.y=this_y-game_engine.vY;
}
}
}
and this code i use in main AS:
public function load_wave() {
for (var i:Number = 0; i < 10; i++) {
wave = new Array();
var rndX = Math.floor(Math.random() * mW);
var rndY = Math.floor(Math.random() * mH);
enemy = new game_enemy(rndX,rndY,5);
wave.push( enemy );
scr.addChild( enemy );
}
}
public function move_enemies() {
for each ( var enemy:game_enemy in wave )
{
enemy.move_enemy();
}
}
im puzzled as to what is going wrong here so im hoping someone can help me out here.
Regards,
TurboTuTone
p.s. it looks like with every build theres a random number of enemies with static positions, and only one enemy that has correct behaviour (that scrolls with the map) maybe this info helps.