How do I add a limit to how many projectiles are on screen?

@Speed9855 good question! after looking at some old galaga footage, seems like there are two limits to how projectiles are fired:

  1. only two projectiles can be on screen
  2. there is a minimum time between projectiles firing

for the first constraint, you can check it by comparing the length of the array returned by the array of sprites of kind block with the limit you want.

for the second constraint, i’d use a variable to keep track of the next time a projectile can be fired at. then compare the current time with that variable to see if a shot can be fired.

together that would look like this:

in the above code, the maximum number of projectiles is 2 and the minimum time between shots is 200ms

2 Likes