How do you reload the laser beams after they have been shot once in a Space Invaders type game? My students and I have been trying to figure this out.
Hi @thompam1,
Here is how I broke down the problem:
- When lasers get past upper border (laser.y < 0), they should reset to the position of the ship but a little higher.
if (laser.y <0) {
laser.x = Player.x;
laser.y = Player.y - 50;
} - But then, lasers keep traveling up because line 35 sets a velocityY for lasers. So, you need to add the following addition to the if statement to stop the velocityY when the lasers reset:
if (laser.y <0) {
laser.velocityY = 0;
laser.x = Player.x;
laser.y = Player.y - 50;
}
Good luck!
Michelle
1 Like