I’m trying to create a Space Invaders clone to learn more about game programming in Flash, and I’m kind of stuck on how to get them to move.
I have three different sprites, then 3 for loops duplicate them to make rows. Then, I want to make all the sprites move back and forth in unison, moving down a row every once in a while.
My prototype makes the sprites move left and right, checks for a collision with a wall, and if there is, reverse the direction and increment a variable. When that variable reaches say, 2, it shifts the Y position up a bit (moving the sprite(s) down).
But, the prototype is making each sprite move independantly, how can I make them ALL move in unison?
MovieClip.prototype.move = function() {
this.speed = 1;
this.left = 5 + this._width/2;
this.right = 200 - this._width/2;
this.onEnterFrame = function() {
this._x += this.speed;
if(this._x < this.left) {
this.speed *= -1;
bounces++;
}
if(this._x > this.right) {
this.speed *= -1;
bounces++;
}
if(bounces == 2) {
this._y += 5;
bounces = 0;
}
}
}
for(i=1; i<9; i++) {
_root["sprite3"+i].move();
}
Any help appreciated.