I’m making a space invaders-esk game and i have 3 rows of 11 aliens. I’ve down this by creating a multi-dimensional array of aliens As this is supposed to be an invasion the aliens need to move down the screen every so often, currently i’m using this:
// update the game
public void update()
{
// schedule the aliens to move down
alienTimer.schedule(new TimerTask(){
public void run()
{
// move the aliens row by row
moveAliens();
}
}, 1000, 2000);
}
// move the aliens row by row
private void moveAliens()
{
for(int i = (aliens.length -1); i > -1; i--)
{
for(int j = 10; j > -1; j--)
{
if(aliens[i][j] == null)
{
// Do nothing alien doesn't exist
}
else
{
// move the alien down
aliens[i][j].moveDown();
}
}
}
}
// Alien Move Down method
// move the alien
public void moveDown()
{
getPosition().y += 5;
}
but when i run the game the after the second delay all the aliens just move down the screen without stopping for the 2 second period. I’ve also tried scheduleAtFixedRate, but it had the same result.
Anyone have any ideas, and whilst your here, how could i go about having different rows move in opposite directions left and right, eg row 1 would move left, hit the screen bounce then move right, row 2 would move right, it the screen bounce, then move left.
Thanks for any help