kai361
12-07-2007, 02:52 PM
I am currently in my 2nd year at uni and I have to make a game in flash using action script, I hav decided to make a space invaders type game and I am using grinch’s in stead of space ships, I have nearly completed the game apart from one part. I need the game to take the user to the game over screen when the grinch’s y coordinates are at 560, the problem that I am facing is that as soon as I start the game the user is taken to the game over screen, is there anyone that can help me? The code that I have used for this is below in bold. Thankyou to anyone who can help me. I have also included the fla file as well, the code below is in scene 2, in the controller (the black circle to the left of the canvas.
// set the initial speed of the grinchs
onClipEvent (load) {
dropdown = false;
speed = 10;
}
// move the grinchs
onClipEvent (enterFrame) {
for (i=0; i<3; i++) {
for (j=0; j<10; j++) {
// move horizontal
_root["grinch"+i+"_"+j]._x += speed;
if (_root["grinch"+i+"_"+j]._x<0) {
// set direction to right
speed = 10;
// drop down
dropdown = true;
break;
}
if (_root["grinch"+i+"_"+j]._x>Stage.width) {
// set direction to left
speed = -10;
// drop down
dropdown = true;
break;
}
//sends to game over
if (_root["grinch"+i+"_"+j]._y>=560) {
trace("game over");
_root.gotoAndPlay("gameOver");
}
}
}
// end for loops
// drop down all the rows
if (dropdown) {
for (var i = 0; i<3; i++) {
for (var j = 0; j<10; j++) {
_root["grinch"+i+"_"+j]._y += 20;
}
}
}
dropdown = false;
}
// set the initial speed of the grinchs
onClipEvent (load) {
dropdown = false;
speed = 10;
}
// move the grinchs
onClipEvent (enterFrame) {
for (i=0; i<3; i++) {
for (j=0; j<10; j++) {
// move horizontal
_root["grinch"+i+"_"+j]._x += speed;
if (_root["grinch"+i+"_"+j]._x<0) {
// set direction to right
speed = 10;
// drop down
dropdown = true;
break;
}
if (_root["grinch"+i+"_"+j]._x>Stage.width) {
// set direction to left
speed = -10;
// drop down
dropdown = true;
break;
}
//sends to game over
if (_root["grinch"+i+"_"+j]._y>=560) {
trace("game over");
_root.gotoAndPlay("gameOver");
}
}
}
// end for loops
// drop down all the rows
if (dropdown) {
for (var i = 0; i<3; i++) {
for (var j = 0; j<10; j++) {
_root["grinch"+i+"_"+j]._y += 20;
}
}
}
dropdown = false;
}