-
Space Invaders help!
Hi
I am trying to enhance a version of space invaders for an assignment and i have managed to align the 'aliens' in a row, but i cant work out how to get multiple rows underneath the first row (x).
I have tried x+1 and various others but i am stuck, can anyone help please?
Thanks in advance :D
x
-
it might help to see some of the relevant bits of code, inside code tags,
i'm pretty new but can i ask are you using two nested for loops to set them out
sonny
-
Hi thanks for the help :D
ill post the code i have that aligns the first horizontal row of 6 of the aliens.
public void initWorld() {
actors = new ArrayList();
for (int i = 0; i < 6; i++){ // amount of vertical space invaders
Monster m = new Monster(this);
m.setX( (int)(Stage.HEIGHT) );
m.setX( i*70 ); //width gap between space invaders
m.setVx( (int)(15-10) );
actors.add(m);
i need to do another 5 rows of aliens underneath this but im not sure how to shift the rows down by 1 each time, if that makes sense?
xx
-
like I said im still new to this but i think you nedd to do something like this
Code:
public void initWorld() {
actors = new ArrayList();
for (int k =0: k <5; k++) { // sets out 5 rows
for (int i = 0; i < 6; i++){ // amount of vertical space invaders
Monster m = new Monster(this);
m.setX( (int)(Stage.HEIGHT) );
m.setX( i*70 ); //width gap between space invaders
m.setVx( (int)(15-10) );
actors.add(m);
}
}
you may need to use the K index somewhere to set out the height in the vertical.
hope this helps
-
i tried to put the 'k' in like you said but it hasnt made the extra rows i need. would i have to put the k index in one of the other classes too? or define it somewhere else?
-
not sure really, has it set out the rows on top of each other? so it loooks like one row.
you have used the index i
Code:
m.setX( i*70 ); //width gap between space invaders
presumably this sets a distance across from left to right
you will have to use the k index to set out the vertical distances
does this bit have something to do with the vertical spacing
Code:
m.setVx( (int)(15-10)