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

**URL:** https://forum.makecode.com/t/how-do-i-add-a-limit-to-how-many-projectiles-are-on-screen/33374
**Category:** Arcade
**Created:** [January 23, 2025, 10:45pm UTC](https://forum.makecode.com/t/how-do-i-add-a-limit-to-how-many-projectiles-are-on-screen/33374 "2025-01-23T22:45:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Speed9855](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/speed9855/32/19381_2.png) [@Speed9855](https://forum.makecode.com/u/Speed9855)
#### Post date: [January 23, 2025, 10:45pm UTC](https://forum.makecode.com/t/how-do-i-add-a-limit-to-how-many-projectiles-are-on-screen/33374/1 "2025-01-23T22:45:52Z")

</div>

I’m trying to make a galaga remake and I’m not sure how to limit the projectiles on screen to only two.

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [January 23, 2025, 11:08pm UTC](https://forum.makecode.com/t/how-do-i-add-a-limit-to-how-many-projectiles-are-on-screen/33374/2 "2025-01-23T23:08:14Z")

</div>

@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:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/d/e/de83f4300332ebe2b0c9550684dc3f8b66e98b51.png)

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

---

<div class="post-metadata">

### Author: ![Speed9855](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/speed9855/32/19381_2.png) [@Speed9855](https://forum.makecode.com/u/Speed9855)
#### Post date: [January 24, 2025, 6:23pm UTC](https://forum.makecode.com/t/how-do-i-add-a-limit-to-how-many-projectiles-are-on-screen/33374/3 "2025-01-24T18:23:13Z")

</div>

Thanks man. I really appreciate it.

---

<div class="post-metadata">

### Author: ![ShaneyBoi09](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/shaneyboi09/32/18893_2.png) [@ShaneyBoi09](https://forum.makecode.com/u/ShaneyBoi09)
#### Post date: [January 25, 2025, 8:34pm UTC](https://forum.makecode.com/t/how-do-i-add-a-limit-to-how-many-projectiles-are-on-screen/33374/4 "2025-01-25T20:34:39Z")

</div>

Hi @Speed9855! Welcome to the forum! 🙂

---

<div class="post-metadata">

### Author: ![Speed9855](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/speed9855/32/19381_2.png) [@Speed9855](https://forum.makecode.com/u/Speed9855)
#### Post date: [January 27, 2025, 7:44pm UTC](https://forum.makecode.com/t/how-do-i-add-a-limit-to-how-many-projectiles-are-on-screen/33374/5 "2025-01-27T19:44:28Z")

</div>

I do have one more question. How do I make an enemy shoot at me wherever I’m at on the tilemap?
