Map generator

While trying to decide what kind of game to work on next, post-jam, I Just remembered that a bunch of months ago I was working on a random map generator.

My nephew decided to do a random map generator in monogame, and challeneged me to do the same in tandem (I’m still trying to convince him to move to Defold, he’s 100% a better coder than me).

I just opened it up to take a look, and it’s pretty ok.

Basically just creates a random series of connected rooms, making sure each is actually accessible. The current iteration also builds a visual “mini map” mainly just to verify that it was working correctly. The main idea is that it creates a table with an ID for each room, a bool for each (n.e.s.w.) direction as to whether it’s connected to another room in that direction, and the ID of the room it’s connected to. Basic idea was for roguelike/rogelite type of games.

It is not amazing code, but it’s working code. I guess my question is: would this be interesting to anyone as an asset? Currently there are no exposed script properties or messages to manipulate it. It would likely benefit me to add those anyway of i want to make a game out of it. It’s currently not bogged down by other scripts and assets/graphics.

Should i put the time in to try to make it an accessible asset?

Brief visual example:

4 Likes

Posting your code is always welcome!

Here’s a random level generator from a while ago

https://www.pkeod.com/defrs/random_level/

1 Like

Ooooh, I didn’t realize there already was one. I guarantee mine is way dirtier haha.

There are an infinite ways to make a random level generator. An asset one would be useful to have a variety of ways of generating maps. Lots of devs have shared their ways of doing them and you could study them and compile some good ideas together into a compilation asset.

I just added you to the as yet private github project. Marvel at how i can get an OK result without knowing what I’m doing, lol.

The question, i guess, is: is it worth me adding comments and “hooks” and script properties and all that to make it legible and useable by other people, or do better solutions already exist in a defold context? I hadn’t seen anything.

Also, if you look into the project, use the “working backup” version of the script. I don’t remember what i was trying to add to it 7 months ago, but if you run it as is you’ll just get 900+ loops that print “0” and a freeze/crash lol

2 Likes

Without even looking my answer will always be yes. Even if there already were other solutions, another option is never a bad thing.

I looked at your generation code and what I would do is put it into a Lua module. Check other code assets to see how this can be done. Then it can be use in any script easily to generate your kind of map data.

3 Likes

:ok_hand: i love modules. I use them as often as makes sense to me.

There IS a 1 line module included as a sort of “constructor” that is totally not necessary, but i definitely get your point. This project was created start to finish to ONLY do this, with no game or extensibility in mind. Seeing it from the perspective of a piece within a larger game, translating it into a module makes good sense :facepunch:

I’ll probably work on it in the coming days and see what happens.

I also notice that my code has almost exactly 2x as many lines as yours :grin: granted, i haven’t removed the default gameloop functions that aren’t being used, and also I’m on my phone and haven’t run your code to see what it does. But good job! Haha. I’ll definitely take a detailed read through it to learn what it does. I have 0 professional or educational experience in this stuff, but i tend to make out ok. Hopefully can inspire some other “old dudes” to get in to Defold who are otherwise unqualified.

4 Likes

Here is my attempt to build procgen map(dungeon actually):

It contains doors, corridors, keys/treasures, in and out points.
It is unfinished, buggy and not suitable for production but I think it can give you an insight.

2 Likes

Just want to mention this algorithm - https://github.com/mxgmn/WaveFunctionCollapse

Wave Function Collapse algorithm has been implemented in C++, Python, Kotlin, Rust, Julia, Go, Haxe, Java, Clojure, JavaScript and adapted to Unity and Houdini. You can download official executables from itch.io or run it in the browser. WFC generates levels in Bad North, Caves of Qud, Dead Static Drive, Townscaper, several smaller games and many prototypes. It led to new research. For more related work, explanations, interactive demos, guides, tutorials and examples see the ports, forks and spinoffs section.

It’s ported to many languages, can be wrapped for Defold as native extension.

5 Likes

There is a C version if anyone interested in:

3 Likes