Artifact : Level with Layers

What?

The artifact of this week is the Level, or more specifically the Load function of the level. It is based on the platformer code with some small modifications around layers and colliders, creating possiblilities to choose if these should be active or not.

The Level is used for easily drawing out the game level from a txt file, and therefore allows you to work with the level inside an Excel document. This makes it much easier to create the level, rather than hard coding it directly in the code. It’s flexible and easy to change where you spawn as a player or where all the enemies spawn. And by using multiple Layers it becomes possible to create objects that you can walk behind, or swim behind in our game.

How?

The Levels is loaded in from a text file using and ifstream for reading the lines from the file. The first thing that the level will load in from the text file is what the name of the sprite sheet that it should load followed by how many sprite boxes and their sizes.

By loading in the number of sprite boxes that it will need to read in both positions and how much to draw out from that x y position. After having the number of done, moving on to the next part where it loads them in with their values from the text file with x y width and height and saving them in a map with a char and a struct containing x y width and height.

level

 

The level also contains a layer enum and a bool for collider.  The Enum is to keep track on in what order each of the layers should be drawn out, to make sure what can be drawn out infront of what, combined with the collider bool that will filter out if the layer should have colliders on its objects or not. these two in combination made it possible to make it so that a layer infront of another without collider, that the player could then move in behind.

Why?

The main reason for making the level load to be like this is to easily to craft the map. in Excel, where you can colour code each letter. This makes it much easier to get a clear overview of how the level looks compared to have look at a white text document and try to figure out where everything is located.

levellayout