# Dungeon

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

<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: [April 30, 2020, 9:16pm UTC](https://forum.makecode.com/t/dungeon/1906/1 "2020-04-30T21:16:11Z")

</div>

Hey folks,

This is a game I started a long time ago but haven’t posted until now. It’s finally gotten to the point where it’s too big to work on so I’m just going to release it as is. I present: DUNGEON

> **[Dungeon](https://arcade.makecode.com/71680-30649-43580-11759)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Some features:

1. 100% written in blocks
2. Procedurally generated dungeons (different every time)
3. Over 90 tilemaps!

Hope you enjoy it! There isn’t really a “game over” screen, but there is an end. If you get to a really big room then you’ve beaten it.

p.s. This project is so big that most computers have a hard time opening it in blocks. Be warned that you might hang your browser if you try to import it. Also, I apologize for the code. I got pretty lazy towards the end 😄

---

<div class="post-metadata">

### Author: ![joshmarinacci](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/joshmarinacci/32/768_2.png) [@joshmarinacci](https://forum.makecode.com/u/joshmarinacci)
#### Post date: [May 2, 2020, 2:27pm UTC](https://forum.makecode.com/t/dungeon/1906/2 "2020-05-02T14:27:40Z")

</div>

Wow. That was shockingly fun to play. Great job!

---

<div class="post-metadata">

### Author: ![Icicles](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/icicles/32/734_2.png) [@Icicles](https://forum.makecode.com/u/Icicles)
#### Post date: [May 3, 2020, 7:48pm UTC](https://forum.makecode.com/t/dungeon/1906/3 "2020-05-03T19:48:47Z")

</div>

@richard  
It was a really fun game! Just I couldn’t load it onto my Brainpad Arcade, when I did I waited at least an hour but it just didn’t load. But really fun game!

---

<div class="post-metadata">

### Author: ![mouseart](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mouseart/32/925_2.png) [@mouseart](https://forum.makecode.com/u/mouseart)
#### Post date: [May 4, 2020, 10:11am UTC](https://forum.makecode.com/t/dungeon/1906/4 "2020-05-04T10:11:40Z")

</div>

太棒了，可以用作教科书！

---

<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: [May 4, 2020, 4:51pm UTC](https://forum.makecode.com/t/dungeon/1906/5 "2020-05-04T16:51:04Z")

</div>

@Icicles I haven’t tested it on the brainpad, it might not work. It does work on the pybadge/pygamer (or at least did work)

---

<div class="post-metadata">

### Author: ![AIWintermuteAI](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@AIWintermuteAI](https://forum.makecode.com/u/AIWintermuteAI)
#### Post date: [May 15, 2020, 1:56am UTC](https://forum.makecode.com/t/dungeon/1906/6 "2020-05-15T01:56:03Z")

</div>

Hello! This is Dmitry, from TinkerGen STEM Education. Our company made a retro gaming console for use with [Makecode Arcade, called GameGo](https://blog.tinkergen.com/2020/04/14/gamego-a-retro-gaming-platform/). We have also developed a series of free online courses to help our users to get started with GameGo and learn how to make their own video games. Despite the courses are written for GameGo, there is no restriction on use with other hardware or purely in Makecode simulator.  
In the course, there is a recommendation section, where we recommend some good games for students to help them learn. We want to include Dungeon, a game, that you made, in recommendation section. We think it is very suitable as Demo Game for GameGo, because it fully demonstrates the characteristics of Arcade.

We hope to obtain your permission to allow us to recommend your game in the course, and use Dungeon as Demo Game in GameGo. In addition, we will send you a free GameGo for you to use and create even more wonderful games. Please reach me at [maslovdmitry@chaihuo.org](mailto:maslovdmitry@chaihuo.org) for further communication!  
@richard

---

<div class="post-metadata">

### Author: ![isaacreisbr23](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isaacreisbr23/32/1708_2.png) [@isaacreisbr23](https://forum.makecode.com/u/isaacreisbr23)
#### Post date: [August 4, 2020, 8:56pm UTC](https://forum.makecode.com/t/dungeon/1906/7 "2020-08-04T20:56:00Z")

</div>

dude see the new update of the amazing maze if you can thanks send me an email if you like

---

<div class="post-metadata">

### Author: ![adcoding](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/adcoding/32/27305_2.png) [@adcoding](https://forum.makecode.com/u/adcoding)
#### Post date: [August 5, 2020, 3:01pm UTC](https://forum.makecode.com/t/dungeon/1906/8 "2020-08-05T15:01:28Z")

</div>

OMG!! this is amazing.  
I love this, congrats!

---

<div class="post-metadata">

### Author: ![LcAtonal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/lcatonal/32/16800_2.png) [@LcAtonal](https://forum.makecode.com/u/LcAtonal)
#### Post date: [August 6, 2020, 8:55am UTC](https://forum.makecode.com/t/dungeon/1906/9 "2020-08-06T08:55:56Z")

</div>

Niceeeeeee

---

<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 10, 2020, 11:42am UTC](https://forum.makecode.com/t/dungeon/1906/10 "2020-08-10T11:42:31Z")

</div>

man ive been playing a lot and i think i keep going in circles

---

<div class="post-metadata">

### Author: ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)
#### Post date: [October 25, 2022, 7:50pm UTC](https://forum.makecode.com/t/dungeon/1906/11 "2022-10-25T19:50:52Z")

</div>

welp i am really lucky  
394th try: 20 seconds

---

<div class="post-metadata">

### Author: ![BlastBoxGames](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blastboxgames/32/11727_2.png) [@BlastBoxGames](https://forum.makecode.com/u/BlastBoxGames)
#### Post date: [June 27, 2023, 6:39pm UTC](https://forum.makecode.com/t/dungeon/1906/12 "2023-06-27T18:39:03Z")

</div>

Ummmm @richard

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/edba7f3c0b106ab784324567e80470ca423f5c99.png)  
Is this suposed to happen?

---

<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: [June 27, 2023, 7:45pm UTC](https://forum.makecode.com/t/dungeon/1906/13 "2023-06-27T19:45:05Z")

</div>

nope!

---

<div class="post-metadata">

### Author: ![\_jupiter](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/_jupiter/32/28012_2.png) [@\_jupiter](https://forum.makecode.com/u/_jupiter)
#### Post date: [August 4, 2023, 4:51pm UTC](https://forum.makecode.com/t/dungeon/1906/14 "2023-08-04T16:51:24Z")

</div>

_avoiding spikes_ wow this is a fun ga- _noclips into backrooms_

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

---

<div class="post-metadata">

### Author: ![\_jupiter](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/_jupiter/32/28012_2.png) [@\_jupiter](https://forum.makecode.com/u/_jupiter)
#### Post date: [August 4, 2023, 4:51pm UTC](https://forum.makecode.com/t/dungeon/1906/16 "2023-08-04T16:51:33Z")

</div>

not again

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

---

<div class="post-metadata">

### Author: ![Luke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/luke/32/32519_2.png) [@Luke](https://forum.makecode.com/u/Luke)
#### Post date: [August 26, 2024, 12:30am UTC](https://forum.makecode.com/t/dungeon/1906/17 "2024-08-26T00:30:40Z")

</div>

Hey sorry for reviving this I’m just super curious how you stored and read the data for each of the individual rooms in a dungeon and their connections. I’ve dabbled in procedural generation but I still have no idea how your system is so simple!  
Other questions  
How is the overall dungeon layout generated randomly?  
and how do you generate consistent dungeons but with the right amount of variation?  
How do you find the right dungeon tilemaps to connect to each one?  
Would something like this be possible without using multiple tilemaps?  
How did you store and read player changes to a dungeon room after they have left?

---

<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 26, 2024, 10:39pm UTC](https://forum.makecode.com/t/dungeon/1906/18 "2024-08-26T22:39:45Z")

</div>

@Luke

> How is the overall dungeon layout generated randomly?

the overall dungeon layout isn’t actually randomly generated, i made four by hand and just randomly choose from this list (spoilers):

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

the layout might not be random, but the rooms that make up the dungeon are randomly connected to make each dungeon unique.

now if i _wanted_ to make a random layout for a dungeon, i’d use an algorithm to create a maze that i’d use as a template.

> how do you generate consistent dungeons but with the right amount of variation?

by cheating (see above)

> How do you find the right dungeon tilemaps to connect to each one?

the dungeon layout is authored as an image, like this:

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

the green pixel marks the entrance and the red pixel marks the exit, and every pink pixel is a room in the dungeon. each pink room in the dungeon can have between one and four doors, depending on how many other rooms are bordering it. since there are four directions a door can be in (north, east, south, and west), that means there are 15 different combinations of doors that a room can have! here is a table that lists them all (an X means there is a door in that direction):

| id | north | east | south | west |
| --- | --- | --- | --- | --- |
| 1 | X | | | |
| 2 | | X | | |
| 3 | | | X | |
| 4 | | | | X |
| 5 | X | X | | |
| 6 | X | | X | |
| 7 | X | | | X |
| 8 | | X | X | |
| 9 | | X | | X |
| 10 | | | X | X |
| 11 | X | X | X | |
| 12 | X | X | | X |
| 13 | X | | X | X |
| 14 | | X | X | X |
| 15 | X | X | X | X |

so, for each pixel in the image I figure out the correct room type based on how many pixels border it. you can see the code for this in the `getRoomType` function.

for each of these room types, I hand wrote six possible tilemaps that can be loaded for that combination of doors. you can see all of these tilemaps inside of the `setTilemap` function, which takes two arguments: the room type (a number between 1-15 from the above table) and the room index (a number between 0-5 which represents the version of the room to load).

when this game generates a dungeon it loops over the layout image and for each pixel figures out the correct room type and a random room index and stores them in a double array of numbers. all of this logic is inside the `loadDungeon` function.

you might also see a variable called `roomIndices` in that function, that’s an array that keeps track of the last index used for each possible room type. whenever a new room is generated, we increment that number for the room type so that we aren’t just loading the same room over and over again.

> Would something like this be possible without using multiple tilemaps?

sure! i would keep the logic pretty much the same and just “draw” each tilemap onto one giant tilemap as the world is generated. that’s pretty easy to do (see the tile util extension for blocks that let you set/get the tiles from a tilemap in a variable).

however, that strategy would only work because each of the tilemaps in this game are the same size and always place doors in the same place. if you wanted to do more varied rooms, you’d have to figure out how to draw “hallways” between the rooms which would probably be really annoying. I know we did this on stream at some point…

> How did you store and read player changes to a dungeon room after they have left?

I keep a double array that marks each of the rooms that they player has visited. then you can just check it by doing `visited[col][row]`. there isn’t much state to this game, either a room has been cleared or it hasn’t. it’s impossible to leave a room that isn’t cleared (the doors are locked), so keeping track of visits was all i had to do.

for more complicated state, you can simply modify the tilemap when you enter and leave a room. as long as you keep a reference to that tilemap (e.g. in a variable, an array, or using the connections blocks in the tile-util extension), when you reload that tilemap using the same reference then the changes will persist.

---

<div class="post-metadata">

### Author: ![Luke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/luke/32/32519_2.png) [@Luke](https://forum.makecode.com/u/Luke)
#### Post date: [August 27, 2024, 4:13pm UTC](https://forum.makecode.com/t/dungeon/1906/19 "2024-08-27T16:13:08Z")

</div>

Wow this is super helpful thank you!!

---

<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 27, 2024, 4:15pm UTC](https://forum.makecode.com/t/dungeon/1906/20 "2024-08-27T16:15:34Z")

</div>

@Luke I just remembered that we did a stream like four years ago where I recreated all of this code:

[![](https://img.youtube.com/vi/aiw1X870CwQ/hqdefault.jpg "MakeCode Arcade Advanced - Drawing a dungeon") ](https://www.youtube.com/watch?v=aiw1X870CwQ)

---

<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: [December 5, 2024, 6:01pm UTC](https://forum.makecode.com/t/dungeon/1906/21 "2024-12-05T18:01:04Z")

</div>

I know its alot to ask but is there a easier way to do this “map of tilemaps” by using the tile-util or tilemaps extensions?

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