# Enemy Sprite firing back... How to do it?

**URL:** <https://forum.makecode.com/t/enemy-sprite-firing-back-how-to-do-it/184>\
**Category:** Help\
**Created:** [May 17, 2019, 8:24pm UTC](https://forum.makecode.com/t/enemy-sprite-firing-back-how-to-do-it/184 "2019-05-17T20:24:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@Jeremy](https://forum.makecode.com/u/Jeremy)\
**Post date:** [May 17, 2019, 8:24pm UTC](https://forum.makecode.com/t/enemy-sprite-firing-back-how-to-do-it/184/1 "2019-05-17T20:24:34Z")

</div>

I’m trying to create an enemy sprite that fires projectiles. Someone want to help me out? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [May 17, 2019, 9:40pm UTC](https://forum.makecode.com/t/enemy-sprite-firing-back-how-to-do-it/184/2 "2019-05-17T21:40:07Z")

</div>

How would you want them to fire projectiles - in the direction of the player, or just in a given direction (e.g. space aliens can fire lasers downwards at random).

Either way, it will be something that you likely want to apply to all sprites of a given type (like enemy) - to do that, you can use `array of sprites of kind` from the `arrays` category of the toolbox (under `Advanced`) to create an array of all the currently existing sprites of that kind.

This sample has enemies that move across the screen while firing projectiles downwards.

> **[Chicken legs firing chicken legs](https://arcade.makecode.com/06784-54563-90729-97015)**
>
> Made with ❤️ in MakeCode Arcade.

(if you want them to actually be fired in the direction of the player, you will need to do some math based off the `x` and `y` positions of the two sprites)

---

<div class="post-metadata">

**Author:** ![Jeremy](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@Jeremy](https://forum.makecode.com/u/Jeremy)\
**Post date:** [May 17, 2019, 9:43pm UTC](https://forum.makecode.com/t/enemy-sprite-firing-back-how-to-do-it/184/3 "2019-05-17T21:43:57Z")

</div>

Thanks. I just figured out another way to do it, but I might give this a try as well to see which one works best. Sometimes doing it a different way makes the game flow better. Thanks again for the answer. I like it. It makes sense. I’m making a tank game in a platformer format. I need the enemy tanks to fire in a straight line… no targeting necessary. But I might use the targeting idea to create a boss at the end of a level. Thanks. I hadn’t even considered it.

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [May 17, 2019, 9:46pm UTC](https://forum.makecode.com/t/enemy-sprite-firing-back-how-to-do-it/184/4 "2019-05-17T21:46:06Z")

</div>

No problem! If you have any more questions, we’re happy to answer! (and we’d love to see the game when it is completed!)

---

<div class="post-metadata">

**Author:** ![Jeremy](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@Jeremy](https://forum.makecode.com/u/Jeremy)\
**Post date:** [May 17, 2019, 10:03pm UTC](https://forum.makecode.com/t/enemy-sprite-firing-back-how-to-do-it/184/5 "2019-05-17T22:03:56Z")

</div>

Absolutely. You’ll see it for sure… if I can get it like I want it.

---

<div class="post-metadata">

**Author:** ![Gemerson](https://avatars.discourse-cdn.com/v4/letter/g/ee59a6/32.png) [@Gemerson](https://forum.makecode.com/u/Gemerson)\
**Post date:** [June 25, 2021, 5:42pm UTC](https://forum.makecode.com/t/enemy-sprite-firing-back-how-to-do-it/184/6 "2021-06-25T17:42:06Z")

</div>

precisely that last thing you mention is what is difficult for me to understand, the mathematical part, which moves at random and launches projectiles towards the enemy, if you could explain me I would be very grateful

[image]
