Reloading lasers for Space Invaders type game

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:

  1. 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;
    }
  2. 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

Hello @thompam1,
I just wanted to check in. Were you able to get this project to work using @melynn’s suggestion?