▪️Building the thing

Firstly, I have to say that I won't be able to comment all my code and explain all of my code on here, there's too much files and things linked to one another that it would be impossible to do.

What I'll do is create for you multiple checklists, that corresponds to different part of the project and that you can follow in order to build a complete game in C using MiniLibX. All the code for my game is available on my Github, if you have any question on it, don't hesitate to contact me (Simon) and it would be a pleasure for me to answer all the questions you might have.

so_long being a video game, that is something pretty personal, and you surely don't want to do exactly the same thing as I did (and I don't want you to neither), that's why, checklists is the best way to go. You'll have some ideas on where to start and what to do, and you still have to search for information and learn new things.

Now that all that is said, let's get to work.

Map checklist

All these checks can be made directly when you parse the map file. Now, if all these checks are ok, there's two more things you have to check on the map : is the exit accessible from the start position, and are all the collectibles accessible from the start position.

Remember that you have to collect all collectibles to unlock the exit, so if not all collectibles are accessible, the map is invalid.

The way that I checked that in my code is by using a sort of flood fill algorithm, starting on the start position. I check every tiles and what type they are, I update a counter each time the type of the tile is a collectible, same for the exit.

At the end I can easily check if the collectibles counter is equal to the number of collectibles that I found when parsing the map, if they are different, not all collectibles are accessible, thus the map is invalid. I do the same thing for the exit, if the exit counter is 0, this means the exit is inaccessible, thus the map is invalid.

An other way to check if the map is valid is to use a backtracking algorithm from the exit to the start position, and from all the collectibles to the start position. If any one of them couldn't reach the start position, the map is invalid.

Game checklist

Render checklist

Key handler

The key handler (at least in my game), is mainly used to call the update_player_position function when W, A, S or D is pressed or to close the program correctly when we press the ESC key.

There's some things you have to think about before updating the player position.

Final word

You have to assemble all these checklist to get the game working, and adapt it to your style of coding. As said earlier, if you want to see some code, take a look at my Github and ask me questions.

That's basically all that you have to do to have a working game, but the big part is to find assets that fit the theme you want for your game.

You can find a lot of free assets on itch.io (as said in the subject). You can also draw them yourself.

You could use a program like Aseprite to draw some pixel art assets yourself, it's not free but it works great !

Last updated