I've just really read what you coded - this won't work anywhere near how you expect:
for K = 1 to 48 and move=1
It won't actually execute the code in the loop at all:
for K = 1 to 48 and move=1
- evaluate move=1, which is true and results in a 1, becoming:
for K = 1 to 48 and 1
- evaluate 48 and 1, which is 0 (it's a binary AND), becoming:
for K = 1 to 0
You can't combine checks in a for loop like that - I suspect you've come from a C or C++ background where you can combine multiple checks within a for statement.
This is how the loop should go:
if move = 1
for K = 1 to 48
if enemies(K).xpos > 600 `if any enemies xpos > 600
move = 0 `move left
for P = 1 to 48
enemies(P).ypos = enemies(P).ypos +12 `move everything down
next P
` now all enemies have been moved down, do not check for any more
` enemies past the cutoff point, as the above 'move down' loop
` will be executed again.
exit
endif
next K
endif
If your 'alive' field simply mirrors whether the sprite exists, then get rid of it.
FOR Z = 3 TO 50
if sprite exist(Z)
`Z is offset by -2, because enemy ships start from sprite number 3
`but the enemies array starts from 1.
` reposition the sprite
SPRITE Z, enemies(Z-2).xpos, enemies(Z-2).ypos, 3
` if it collides with the bullet, get rid of it
if sprite collision(2, Z) `2 is bullet, 3-50(Z) are the 48 ships
delete sprite Z
endif
endif
next Z
By moving the collision detection inside the SPRITE EXIST check, it gets rid of that pesky 'sprite does not exist' error.