Save file, and layer


Hello :)

Today I will talk about 2 mains topic: The layer system, and the map save system!

.Layer system

A layer system is implemented to allow you to draw on multiple "levels", that allow you to combine tile like you want to, by having one tile being behind or in front of another tile. Right now you can have a limit of 256 differents layers BY map. Why a so precise number ? This will be explained later on :)

Currently the layer system is still pretty rought, this is still a WIP feature, but once the system will be more worked on you will be able to define multiple type of layer, move them upfront or behind other layer as you want to, and even export them if you want to (this allow you to have 2 maps with the same "terrain" without having to recreate the same full terrain multiple time and/or edit each map if you want to edit the terrain).

Map save system

Now I will talk about a more technical thing: How the map are saved on your computer.

As mentionned in the last post, each map will have a binary file. I finally finished this! Right now each map have a save file with the ".cmap" extension, but what is interesting is how the map is saved, so let's talk about it :)

If we take this map that I draw very quickly

We can see important thing:
- First there is a lots of "void", or empty tile
- Second we have 3 layers (the letter we can see on the left "a", "b" and "c")
- And finally we have a lots of repetition for the layer "a" (the water), a little repetition with layer "b" (the grass) and finaly no repetition at all with the layer "c" (the flower).

Now we have the "base" information that we need to save: Each layers, each tile, and each repetition!

At first the engine will get the map layers, and start by the first one ("a"), get each of is tiles, and for each tile it will check multiple thing:

First it will check if their is any tile on the right, then if we have a tile, we check if the tile is the same type (here "water"), if this is the case, it will increment the number of "repeat" to 1, and we do this process until we hit the limit of the map of the right, or we hit a different type of tile.
Once this is done, we have those data availabe about the tile: His position (X/Horizontal, Y/Vertical), it's type (Water), from what tileset it come from, and it's number of repeat (11), with this we can start adding this to our save file like that:
- Position
- Type
- Tileset
- Repeat
and we do this in a loop, until all the layer are done :)

With this, we have a file that look like that: (Don't worry if you don't understand ;) )

I added some color to let you see with more ease what is what:
At the start we have the pink color, this is just used by the engine to know what type of file this is (aka Magic Number).
Then we have 3 colors:
- The first green define the size of the first layer
- The first blue/grey the size of the second layer
- The first orange/brown the size of the thrid layer

And after those 3 colors we see again 3 big part in colors, and those are our data:
Green => Each tiles for the first layer
Blue => Each tiles for the second layer
Orange => Each tiles for the third layer

All this allow us to have this map:



Stored in only a file of 332 octets/bytes


And finally, this is the end of this post :)

I'm very open to question, idea and/or talk, so do not hesitate to join the Discord server:
https://discord.gg/4yfq4NNzs4

Have fun, and have a great day,
Ward.

Get RPG Creator

Comments

Log in with itch.io to leave a comment.

wonderful work i can't wait to see how this evolves   rpmaker mz is so confusing to use at time and the spark really fades at times when i wanna do simple things like make quest all the steps you ned to do place a simple chest