# Need help with enemy spawning

**URL:** <https://forum.makecode.com/t/need-help-with-enemy-spawning/38915>\
**Category:** Help\
**Created:** [August 26, 2025, 9:18pm UTC](https://forum.makecode.com/t/need-help-with-enemy-spawning/38915 "2025-08-26T21:18:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eternance](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/eternance/32/24292_2.png) [@Eternance](https://forum.makecode.com/u/Eternance)\
**Post date:** [August 26, 2025, 9:18pm UTC](https://forum.makecode.com/t/need-help-with-enemy-spawning/38915/1 "2025-08-26T21:18:24Z")

</div>

I need help with the code involved with spawning the enemies near the player, but still on random tiles.

> **[Dart Royale](https://arcade.makecode.com/S08200-93987-15549-95483)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![C0d3r](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/c0d3r/32/27435_2.png) [@C0d3r](https://forum.makecode.com/u/C0d3r)\
**Post date:** [August 27, 2025, 5:20pm UTC](https://forum.makecode.com/t/need-help-with-enemy-spawning/38915/2 "2025-08-27T17:20:16Z")

</div>

i have a solution but i don’t know how to code it

make it so tiles near the player changes to the color of the background

---

<div class="post-metadata">

**Author:** ![a012](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/a012/32/24099_2.png) [@a012](https://forum.makecode.com/u/a012)\
**Post date:** [August 27, 2025, 5:36pm UTC](https://forum.makecode.com/t/need-help-with-enemy-spawning/38915/3 "2025-08-27T17:36:22Z")

</div>

### Problems in the current code:

1. **Random tile placement vs. near the player**

- `tiles.placeOnRandomTile(enemyBot, assets.tile\`myTile10`)` places the enemy anywhere that tile exists, which may not be near the player.

1. **`follow()` combined with random placement**

- Because the enemy may spawn far away, it has to travel before it can engage the player, creating inconsistent difficulty.

1. **`botCount` logic**

- You increment `botCount` in multiple places (on spawn and on destroy), but it can get out of sync if a projectile destroys an enemy before `botCount` is updated. Here is the right code here. ### step 1 create a function for the sprite enemy here  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/9/1/911e05518699ff57b414881ee147c4f7c4cbc748.png)  
. After you do this, then call It on the game update interval if not count is less than bot max count, this is the last step here.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/9/7/9731207a24f7f0a7b27e0b3cbb3a0ce119235b9c.png)  
That is it well done, the code is complete.

---

<div class="post-metadata">

**Author:** ![Eternance](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/eternance/32/24292_2.png) [@Eternance](https://forum.makecode.com/u/Eternance)\
**Post date:** [August 28, 2025, 4:51am UTC](https://forum.makecode.com/t/need-help-with-enemy-spawning/38915/4 "2025-08-28T04:51:56Z")

</div>

The first image is blurry man, if you could clear up the resolution please that would be great. thanks.

---

<div class="post-metadata">

**Author:** ![a012](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/a012/32/24099_2.png) [@a012](https://forum.makecode.com/u/a012)\
**Post date:** [August 28, 2025, 5:16pm UTC](https://forum.makecode.com/t/need-help-with-enemy-spawning/38915/5 "2025-08-28T17:16:59Z")

</div>

Here is the better version.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/5/2/5234f76ce6eb3b7e64245f451361ae3e77baaca0.png)  
If you still cannot see it, just use Ctrl + so you see it bigger.
