I have the following space invaders code which is working pretty well.
On invader creation:
//initialise invader counters
step_counter=100;
move_counter=0;
left=true;
move_speed=1;
speed_counter=0;
And on invader step:
if step_counter > 0 {
step_counter -= move_speed;
// Move every fifty steps
if step_counter % 50 == 0 {
if left == true {
x += 15;
move_counter++;
// At right of screen, drop and change direction; speed up
if move_counter == 4 {
left = false;
y += 15;
speed_counter++
if speed_counter == 5 {
move_speed += 1;
speed_counter = 0;
}
}
}
else {
x -= 15;
move_counter--;
// At left of screen, drop and change direction; speed up
if move_counter == -4 {
left = true;
y += 15;
speed_counter++
if speed_counter == 5 {
move_speed += 1;
speed_counter = 0;
}
}
}
}
}
else {
// reset counter over 100 steps
step_counter = 100;
}
This is working really nicely, and gives a feeling very close to the original arcade game. However, for some reason the invaders get stuck two thirds of the way down the screen and refuse to go any further.
And ideas why?