Building tools for 2D top down adventure games
After the long development time of Danatia, I had more experience with the top down 2d formula and there was one thing I wanted above all else : fast terrain generation. Making a level in Danatia required drawing the level, adding the collisions, encoding the plant grid and placing the loading zones and spawn points. I wanted to automatize all of that. Making this process fast and easy would allow me to make more levels, to iterate on them at will and to free some time for more interesting parts of development. That's why I started Yet Another Zelda Fangame by building some basic blocks described below.
Building the terrain
My first goal was to build a level out of an elevation map. My plan was to have a basic understanding of elevation in code. That means your character can jump off ledges, climb slopes etc. This is seldom done in pure 2D games and this is because it is a pain to make. My rendition of it is still full of bugs and oddities. My main inspiration was Chicory : A colourful tale. After a lot of trials and error I settled on a height map system. Each map in the game is represented as an image file with shades of grey representing various heights.
The height map on the left and the actual terrain built from the height map
In game the level elevation is represented as seen on the right. This is actually a TileMap. Each cell of the tilemap is 10x10 pixels and can be a floor, a wall or a black outline. I won't go in details into how I made the code for the outline generation (to be honest there are still some mistakes here and there). What's important is that this process can take a second of computation. This could be an issue if the computation occurs every time the player enters a new level. One more second of loading time every level can add up very quickly. That's why I wanted to perform this terrain generation before even compiling the game. That's how I found out about Godot's @tool function.
Executing code in Godot's editor
By adding @tool at the beginning of any script, it can be run inside the editor. The documentation says it can be used to have processes running in the editor like an image rotating. That's not what I'm using it for though. What I wanted was a little button added to my editor to run the terrain generation whenever I want. So I did this little hack. It's ugly but it works fairly well.
@export var runIt = false: set(newV): if newV: make_a_terrain_go_go_go()
It creates a boolean variable on the side panel that can never be changed. When you click on it, it instead runs a function that generates the terrain.
As you can see I made several functions to do all sorts of things, each tied to its own checkbox.
The realm of shadows
This has a lot of potential. For examples, I use it to auto generate a color palette for the level or to fill lakes with water.
Another example is shadow generation. To add some depth to the levels I leverage the height information and create an image that represents the shadows cast by the terrain. I can modify the position of the sun in editor and see the results real time without having to run the game.
It also allowed some interesting effects in the Ash Woods levels where I leveraged the elevation information to map the shadow of the tree canopy adequately.
It's a simple effect but thanks to script in-editor execution, you can generate the tilemap as well as the textures used for the shadows ahead of time. It also allows for very fast iterations. In a few clicks I can see immediately what my level is going to look like and modify it at my leisure.
I believe that all these little processes will allow me to give more life and personality to each levels. We'll see how it goes. In any case this is a super useful Godot tool and I am glad I found it when I needed.
Get Yet Another Zelda Fangame
Yet Another Zelda Fangame
A short fangame about Zelda and its fans
Status | Released |
Author | La Saison du Croissant |
Genre | Adventure |
Tags | 2D, Action-Adventure, Cute, Fangame, Top Down Adventure, wholesome, zelda |
Languages | English, French |
Leave a comment
Log in with itch.io to leave a comment.