# Dungeon

**URL:** <https://forum.makecode.com/t/dungeon/1906>\
**Category:** Show & Tell\
**Tags:** featured-game, game\
**Created:** [April 30, 2020, 9:16pm UTC](https://forum.makecode.com/t/dungeon/1906 "2020-04-30T21:16:11Z")\
**Posts on this page:** 12\
**Page:** 2

<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:** [December 5, 2024, 11:03pm UTC](https://forum.makecode.com/t/dungeon/1906/22 "2024-12-05T23:03:00Z")

</div>

@toxic_lj i tried reimplementing this using the tile util extension, but it’s still pretty complicated. here’s that code:

> **[generated-tilemap-sample](https://arcade.makecode.com/30709-24450-94674-15485)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

the issue is that the connection blocks in the tile-util extension are bi-directional which doesn’t work for dungeons that are made up of grids of connected rooms… you end up having to create “Even” and “Odd” connections to prevent rooms from accidentally overriding each other’s connections.

I think I should probably just make an extension that is explicitly for connecting tilemaps in a grid. that would certainly make zelda-like games like this one easier to author.

---

<div class="post-metadata">

**Author:** ![toxic\_lj](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@toxic\_lj](https://forum.makecode.com/u/toxic_lj)\
**Post date:** [January 21, 2025, 5:18pm UTC](https://forum.makecode.com/t/dungeon/1906/23 "2025-01-21T17:18:06Z")

</div>

Ok I finally got this to work with my game. But now How would I go about making the individual rooms random off a list?

---

<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 21, 2025, 5:47pm UTC](https://forum.makecode.com/t/dungeon/1906/24 "2025-01-21T17:47:13Z")

</div>

@toxic_lj in that sample code i gave, it’s actually already doing that. the array of room types is actually a double array, and each index represents all of the possible rooms for that type. all you have to do is add more rooms to each of those arrays

![room-versions](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/0/c/0c0da63f9d462c9418fb502739721afcae0c795f.gif)

---

<div class="post-metadata">

**Author:** ![toxic\_lj](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@toxic\_lj](https://forum.makecode.com/u/toxic_lj)\
**Post date:** [January 22, 2025, 5:25pm UTC](https://forum.makecode.com/t/dungeon/1906/25 "2025-01-22T17:25:19Z")

</div>

Sorry I totally forgot to mention Im using the original one without using the tilemap extention 😬

---

<div class="post-metadata">

**Author:** ![toxic\_lj](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@toxic\_lj](https://forum.makecode.com/u/toxic_lj)\
**Post date:** [February 3, 2025, 5:57pm UTC](https://forum.makecode.com/t/dungeon/1906/26 "2025-02-03T17:57:02Z")

</div>

How did you make it so that it doesnt reload the game objects like coins and pressed buttoms every time to go back into the room?

---

<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:** [February 3, 2025, 6:10pm UTC](https://forum.makecode.com/t/dungeon/1906/27 "2025-02-03T18:10:25Z")

</div>

@toxic_lj what you want to do is change the tilemap when the player picks up a coin or interacts with a button. typically, i do it like this:

1. when the tilemap loads, create a coin sprite on top of each of the coin tiles in my map
2. use the “cover tile” block from the arcade-tile-util extension to cover those tiles with floor tiles
3. inside of the “on player overlap coin” event, set the tile underneath the coin to be the floor tile. this way, the coin won’t get respawned by step 1 when the map is reloaded

here’s some demo code:

> **[coin-collectin](https://arcade.makecode.com/81614-07182-19552-69396)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![toxic\_lj](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@toxic\_lj](https://forum.makecode.com/u/toxic_lj)\
**Post date:** [February 4, 2025, 6:27pm UTC](https://forum.makecode.com/t/dungeon/1906/28 "2025-02-04T18:27:59Z")

</div>

well the thing is… I was using your “map of tilemaps” and it seems that no matter what it resets the maps when you re-enter them. how would you do it then?

---

<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:** [February 4, 2025, 11:59pm UTC](https://forum.makecode.com/t/dungeon/1906/29 "2025-02-04T23:59:49Z")

</div>

@toxic_lj can you share a link to your code?

---

<div class="post-metadata">

**Author:** ![toxic\_lj](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@toxic\_lj](https://forum.makecode.com/u/toxic_lj)\
**Post date:** [February 5, 2025, 9:45pm UTC](https://forum.makecode.com/t/dungeon/1906/30 "2025-02-05T21:45:39Z")

</div>

[https://arcade.makecode.com/S95030-47954-16948-55809](https://arcade.makecode.com/S95030-47954-16948-55809) here you go, I just cleaned up my code a bit so its easier to figure out XD

---

<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:** [February 6, 2025, 12:05am UTC](https://forum.makecode.com/t/dungeon/1906/31 "2025-02-06T00:05:31Z")

</div>

thanks! okay, this should be pretty easy to fix. be sure to make a backup of your project before making the changes i’m about to suggest just in case!

so the reason this isn’t working right now is because the `SetRoomTo` function returns a fresh map every time a room is loaded. we want to keep the same maps around in an array so that they don’t keep getting reset. our strategy is going to be to convert the `TheMap` array in your project into a double array of TileMaps instead of a double array of room kinds.

first, let’s convert your `SetRoomMap` function into a new function called `GetRoomMap` that returns the tilemap for each roomkind instead of setting the current tilemap. it should be basically the same function, but replace all of the `set tilemap to` blocks with `return` blocks, like I did for the first roomkind in this screenshot:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/4/1/41deb17a5ab5a01c5f47d8878fe1edbe8e6b1853.png)

then, inside of your `GenerateMap` function, instead of filling the `TheMap` array with room kinds, let’s fill it with tilemaps instead. in the line where you are adding the result of `FigureOutRoomType` to the array, instead pass the output of that function into your new `GetRoomMap` function

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

finally, in your `LoadRoomDirection` function, you’ll want to call the `set tilemap to` block directly instead of calling `SetRoom`. you also will want to move the `InRoom = false` block from `SetRoom` into this function as well:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/4/5/4567401f342841df961664ea97528d6b2e0c22d4.png)

---

<div class="post-metadata">

**Author:** ![Astronomicality22](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/astronomicality22/32/18365_2.png) [@Astronomicality22](https://forum.makecode.com/u/Astronomicality22)\
**Post date:** [February 6, 2025, 5:59pm UTC](https://forum.makecode.com/t/dungeon/1906/32 "2025-02-06T17:59:13Z")

</div>

So, it’s a rogue-like dungeon crawler?

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://forum.makecode.com/u/Mik)\
**Post date:** [July 1, 2026, 11:41pm UTC](https://forum.makecode.com/t/dungeon/1906/33 "2026-07-01T23:41:05Z")

</div>

HOW DID YOU DO THAT :boom: 🤯

[Previous page](https://forum.makecode.com/t/dungeon/1906.md?page=1)
