Enemy Movement Problems

Hi guys, i have been working on this basic arcade-style space ship shooter game. Im sure you all know what im talking about: you control a little ship at the bottom of the screen and move it with the arrows, fire with the space bar at other space ship enemies. Well i have had everything come along fine up until now (which should have been a signal :stuck_out_tongue: ) Anyway here is the problem. Everything is working fine. Controlling the player ship, firing lasers, displaying health and lives, attaching the boss at the end of the level, scrolling the screen clouds etc., and even attaching the enemy clips. However… I cannot seem to come up with a script that works 100% as far as moving the enemies goes. So here is the script i wrote for actually attaching the enemies. Anyone have any suggestions as to how to write the moveEnemies() function? I have tried everything i can think of. This is my first major flash game (if you can call it major :smiley: ) but once i get this engine working ill be really happy. Thanks!

Heres the addEnemy script:


function addEnemies () {
 if (distancetoEnemy<=0) {
  if (enemiesOn == false) {
   if (totalEnemies>0) {
    for (e=0; e<5; e++) {
     // add enemy to screen
     attachMovie("basicEnemy", "enemy"+nextEnemy, 9999+nextEnemy);
     _root["enemy"+nextEnemy]._y = 30;
     _root["enemy"+nextEnemy]._x = ((Math.random()*260)+20);
     if (int(Math.random()*100)<50) {
      dx = (Math.random()*3);
     } else {
      dx = -((Math.random()*3));
     }
     enemies.push({clip:nextEnemy, d:dx});
     nextEnemy++;
    }
    distancetoEnemy = 2000;
    enemiesOn = true;
    totalEnemies--;
   }
  }
 } else {
  distancetoEnemy -= (cloudspeed+scrollspeed);
 }
}

And here is an attempt at moving them, although it freezes the .swf:


function moveEnemies () {
 // movealll on stage enemies
 for (i=enemies.length-1; i>0; i--) {
  Menemy = _root["enemy"+(enemies*.clip)];
  Mdirect = enemies*.d;
  Menemy._x += Mdirect;
  if (Menemy._x>280) {
   enemies*.d = (enemies*.d)*-1;
  }
  if (Menemy._x<20) {
   enemies*.d = (enemies*.d)*-1;
  }
  // check for collision
  for (b=Plasers.length-1; b>0; b--) {
   Mlaser = _root["Plaser"+Plasers**];
   if (hitTest(Mlaser, Menemy)) {
    Menemy.gotoAndPlay(2);
    Menemy.removeMovieClip();
    enemies.splice(i, 1);
    Mlaser.removeMovieClip();
   }
  }
 }
}

Thanks alot guys, i really apreciate it.

PS - Im in Flash 5 :slight_smile: