Hi everyone, i was making a space shooting game, where you control
a horizontally moving ship and fire with the space bar. I want to get asteroids to come from the top of the screen and go down, and if they go past the bottom of the screen, you lose a life.
so far, I have one asteroid that does precisely what i want it to do, the code for the asteroid is as follows (entered in the main timeline) :
ActionScript Code:
for (var i = 0; i<bulletCount; i++) {
var b = bulletArray[i];
if (b._y>0) {
b._y -= bulletSpeed;
} else {
removeMovieClip(b);
bulletArray.splice(i, 1);
}
if (!hit) {
if (b.hitTest(ob)) {
hit = true;
ob.play();
b.play();
_root.score +=500;
b._y -= bulletSpeed;
bulletArray.splice(i, 1);
removeMovieClip(b);
}
}
}
}
var nrEnemies = 3;
for (i = 1; i < nrEnemies; i++)
{
_root.ob.duplicateMovieClip("asteroid" + i, _root.getNextHighestDepth());
}
var hit = false;
var obSpeed = 5;
var earthSpeed = 1;
function createObject(o) {
ob = this.attachMovie(o, o, 100);
ob._x = random(460) + 20;
}
function resetObject() {
ob._x = random(460)+20;
ob._y = -40;
ob.gotoAndStop(1);
ob.restart = false;
hit = false
}
function loseLife() {
earthMc._y = 360;
}
function lostlife() {
earthMc._y += earthSpeed;
}
function moveObject() {
if (ob._y<400) {
ob._y += obSpeed;
_root.score +=1
lostlife();
} else {
ob.play();
resetObject();
_root.lives -=1;
loseLife();
}
if (ob.restart) {
resetObject();
}
}
createObject("asteroid", "asteroid", (0));
my problem is that i only have one asteroid and the game is far too easy.
Is there a way to change the code or make a new one so that there will be more than one asteroid on the screen with the same properties?
any and all help is greatly appreciated.