# Enemy Defeat

**URL:** <https://forum.makecode.com/t/enemy-defeat/3177>\
**Category:** Help\
**Created:** [August 20, 2020, 6:15pm UTC](https://forum.makecode.com/t/enemy-defeat/3177 "2020-08-20T18:15:20Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kat/32/2596_2.png) [@Kat](https://forum.makecode.com/u/Kat)\
**Post date:** [August 20, 2020, 6:15pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/1 "2020-08-20T18:15:20Z")

</div>

> **[W1ld : Cats](https://arcade.makecode.com/78809-32571-18043-47967)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

I have tried different methods for the enemy to be beaten, overlap+b, projectiles, and jumping on top of the enemy and none seemed to work very well. Any suggestions?

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [August 20, 2020, 7:44pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/2 "2020-08-20T19:44:42Z")

</div>

How bout this?

> **[W1ld : Cats Unsigned\_Arduino's edits](https://arcade.makecode.com/63705-80227-67723-68632)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

  
Cleaned up the code, accidentally added the sprite data extension, removed about 20 unneeded variables, (sorta) fixed the pictures, and holding down `B` while touching a cat will slowly deplete the other cats health, but you might get scratched too!

---

<div class="post-metadata">

**Author:** ![Kat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kat/32/2596_2.png) [@Kat](https://forum.makecode.com/u/Kat)\
**Post date:** [August 20, 2020, 7:49pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/3 "2020-08-20T19:49:29Z")

</div>

Wow! Thank you! The problem with the ¨b¨ button is that when you defeat one cat, it doesn’t really defeat it because once you go to the next bush to trigger another cat, it does not spawn another.

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [August 20, 2020, 7:58pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/4 "2020-08-20T19:58:41Z")

</div>

Fixed it:

> **[W1ld : Cats Unsigned\_Arduino's edits](https://arcade.makecode.com/93052-74717-58389-47788)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

  
When you kill an enemy cat, it sets `enemyexists` to false so it can spawn another one

---

<div class="post-metadata">

**Author:** ![Kat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kat/32/2596_2.png) [@Kat](https://forum.makecode.com/u/Kat)\
**Post date:** [August 21, 2020, 12:40pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/5 "2020-08-21T12:40:45Z")

</div>

Thanks!!

---

<div class="post-metadata">

**Author:** ![Kat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kat/32/2596_2.png) [@Kat](https://forum.makecode.com/u/Kat)\
**Post date:** [August 21, 2020, 12:59pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/6 "2020-08-21T12:59:01Z")

</div>

I was in edit code when I noticed that the system could not run the code. When I put debug mode on, it said that the ¨on button released¨ code did not work. Is there another way to have the cat ¨walk¨?

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [August 21, 2020, 4:29pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/7 "2020-08-21T16:29:55Z")

</div>

That’s, weird. Are you running the code I posted right above? It works for me

---

<div class="post-metadata">

**Author:** ![Kat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kat/32/2596_2.png) [@Kat](https://forum.makecode.com/u/Kat)\
**Post date:** [August 21, 2020, 5:48pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/8 "2020-08-21T17:48:15Z")

</div>

Yep. But I added som music to the start screen. As soon as I deleted the music it was working again. Weird

---

<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:** [August 21, 2020, 6:04pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/9 "2020-08-21T18:04:25Z")

</div>

Ahh, if you did so using the `play melody` block it was likely pausing in the on start; play melody pauses until the melody completes so you can play them one after the other - you can see that here where it won’t turn the screen red until after the music stops

> **[Untitled](https://arcade.makecode.com/51319-75535-05634-60556)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

One thing you can try is running the music in a forever loop, based off whether or not the user has ended start screen; sort of like this:

> **[Untitled](https://arcade.makecode.com/03003-18019-22658-72680)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![Kat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kat/32/2596_2.png) [@Kat](https://forum.makecode.com/u/Kat)\
**Post date:** [August 21, 2020, 6:11pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/10 "2020-08-21T18:11:56Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![Kat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kat/32/2596_2.png) [@Kat](https://forum.makecode.com/u/Kat)\
**Post date:** [August 21, 2020, 6:30pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/11 "2020-08-21T18:30:39Z")

</div>

Is there a way to say ¨on destroyed sprites of the same kind¨ or something?

---

<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:** [August 24, 2020, 5:24pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/12 "2020-08-24T17:24:03Z")

</div>

There is an “on destroyed sprite of kind” block in the sprite toolbox!

 ![Screen Shot 2020-08-24 at 10.23.33 AM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/4f013821f2ed41e878e2e3982820f480d758c0bd.png)

---

<div class="post-metadata">

**Author:** ![Kat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kat/32/2596_2.png) [@Kat](https://forum.makecode.com/u/Kat)\
**Post date:** [August 24, 2020, 5:30pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/13 "2020-08-24T17:30:52Z")

</div>

Thanks, but I was trying to find out if there is a way to say **ALL** sprites of the same kind, not just one. I think I have figured out another way to begin another level though.

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [August 24, 2020, 7:27pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/14 "2020-08-24T19:27:26Z")

</div>

This would destroy every enemy on screen

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

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [October 8, 2020, 9:26pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/15 "2020-10-08T21:26:30Z")

</div>

@richard

I hope I can add to this post, as I am having a similar issue with sprites and auto destroy. Within a tilemap, I have the set the cars to auto destroy themselves.

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

When any car hits a wall, in the code I create a sprite and want to set to the other side (for now I put it somewhere in the middle).

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

The issue I am having is, the blue cars to the left of screen stay there. When a move the player to the right, the camera scrolls right, and when I go back that cars are gone.

> **[Frogging Hard](https://arcade.makecode.com/82643-76982-64792-85479)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Can someone help me out?

---

<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:** [October 8, 2020, 9:40pm UTC](https://forum.makecode.com/t/enemy-defeat/3177/16 "2020-10-08T21:40:40Z")

</div>

The `AutoDestroy` flag means ‘destroy when the sprite is out of our viewport’; so destroying when they move offscreen is the correct behavior. It sounds like what you want is actually the `destroy on wall` flag:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/9c80e4c9f04ca11feefe614bb3ec57d08ee1a15f.png)

to make it so the sprite colliding with the wall gets destroyed / triggers the `on destroyed` logic
