PDA

View Full Version : help on my actionscript game


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;
}

MonkeyBiscuits
12-07-2007, 03:36 PM
instead of setting a boolean for dropdown and trying to run the for loop off that, you'd be much better off creating a function called 'dropdown' which performs the same function and is called where you currently set the boolean to true.

rrh
12-07-2007, 04:36 PM
You are creating the grinches in a loop that goes from 0 to 1 and 0 to 7, but moving in a loop from 0 to 2 and 0 to 9, so you are testing y values for non-existant grinches. You might want a couple variables that store the number of rows and columns of the grinches to simplify that.

And like I said to the other space invaders guy, the space invaders move as a unit. It might simplify things if you put them inside a container movieclip, and just move that container clip.