Posted June 28, 2021 by Mejia Tavarez Software and More
#2d #tilemaps #tools #unity3d #map generator #devlog #coding
Disclaimer:
This is a humble approach for creating a random map generator for my game. Please notice that I did not try my best here and this could definitely be way better...I just wanted to have some fun while creating a random map generator. I will provide links to the code used here if you want to take a look. Also, feedback is really appreciated :).
My approach for this tool was the following:
Here's the code that does that:
For shuffling the grid:
https://gist.github.com/MerliMejia/26a9a61efc9cea80155ea129f83619d0#file-mapgenerator-cs-L54
For generating the random data on the grid:
https://gist.github.com/MerliMejia/26a9a61efc9cea80155ea129f83619d0#file-mapgenerator-cs-L71
You can use Unity's Gizmos system to get an early visualization:
https://gist.github.com/MerliMejia/26a9a61efc9cea80155ea129f83619d0#file-mapgenerator-cs-L175
You can use Scriptable Objects to know what to draw and how many it should draw:
https://gist.github.com/MerliMejia/26a9a61efc9cea80155ea129f83619d0#file-obstacles-cs-L7
After that, you just need to draw the tiles based on the random grid data and that's it!
https://gist.github.com/MerliMejia/26a9a61efc9cea80155ea129f83619d0#file-mapgenerator-cs-L148
Here's all the code used in this tool:
https://gist.github.com/MerliMejia/26a9a61efc9cea80155ea129f83619d0