# Stationary cannon example

**URL:** https://forum.makecode.com/t/stationary-cannon-example/10959
**Category:** Show & Tell
**Created:** [November 19, 2021, 5:43am UTC](https://forum.makecode.com/t/stationary-cannon-example/10959 "2021-11-19T05:43:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![drtongue96](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@drtongue96](https://forum.makecode.com/u/drtongue96)
#### Post date: [November 19, 2021, 5:43am UTC](https://forum.makecode.com/t/stationary-cannon-example/10959/1 "2021-11-19T05:43:56Z")

</div>

> **[Stationary Cannon Example](https://arcade.makecode.com/30006-28481-96058-62286)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

I did this one quickly as a proof of concept for a boss battle in my bigger projects. Some ideas I had were: you get just 5 bombs and when you run out you have to get more and bring them back to the cannon. Obviously only shoot one at a time. Maybe make it a bit easier. The timer extension made this a cinch as I made the delay to shoot the same as the animation for the cannon. (Go close to cannon and press A to shoot)

---

<div class="post-metadata">

### Author: ![personalnote](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/personalnote/32/31359_2.png) [@personalnote](https://forum.makecode.com/u/personalnote)
#### Post date: [November 19, 2021, 5:11pm UTC](https://forum.makecode.com/t/stationary-cannon-example/10959/2 "2021-11-19T17:11:28Z")

</div>

Is it possible to allow the cannon to be activated when you reach a certain distance? Cause I wanted to make a mechanic in my game where if you are a certain distance between an enemy and you press a button combo, you will damage the enemy and push them back. I know there is a block in the Sprite Util extension called the ‘distance between [mysprite] and [mysprite2]’, but I don’t exactly get how to use it.

---

<div class="post-metadata">

### Author: ![Kiwiphoenix364](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kiwiphoenix364/32/14368_2.png) [@Kiwiphoenix364](https://forum.makecode.com/u/Kiwiphoenix364)
#### Post date: [November 22, 2021, 4:19pm UTC](https://forum.makecode.com/t/stationary-cannon-example/10959/3 "2021-11-22T16:19:26Z")

</div>

Use “if (distance between [mysprite] and [mysprite2]) (\</=/\>…) (number of pixels) then (blocks that you want to be activated)” Image so you aren’t too confused:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/f/fabb75fddf1097453d1d78e15f70132ce386cafb.png)

---

<div class="post-metadata">

### Author: ![drtongue96](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@drtongue96](https://forum.makecode.com/u/drtongue96)
#### Post date: [November 22, 2021, 4:21pm UTC](https://forum.makecode.com/t/stationary-cannon-example/10959/4 "2021-11-22T16:21:16Z")

</div>

Yes, I tried it. Works pretty good. I used 16 pixels as 8 seemed too little. I moved the overlap code to the b button and put the distance between on the a button…

> **[Stationary Cannon Example (with distance between)](https://arcade.makecode.com/71901-68761-90146-66912)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

### Author: ![personalnote](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/personalnote/32/31359_2.png) [@personalnote](https://forum.makecode.com/u/personalnote)
#### Post date: [November 23, 2021, 12:29am UTC](https://forum.makecode.com/t/stationary-cannon-example/10959/5 "2021-11-23T00:29:10Z")

</div>

thank you
