Log 5




──────────────┤ View On GitHub ├──────────────

Short week this week. Had a friend visiting over the weekend so all game dev went on hold. Even though the week was shorter I managed to implement persistence into the engine. Was much easier than I was anticipating.

1. DONE Persistent Game States

On starting a new game the engine checks for a game file. If there is one then the engine loads it. If there isn’t one then the engine initialises a new world. We’re also building a proper roguelike engine now, on closing the game the engine checks if the player is dead, if they are it deletes the save file. If the player is alive then we save the game world including all entities, explored tiles, items, and stats.

Implementing this I realised how much I take for granted being able to easily serialize an object into JSON or XML in other languages. The tutorial also mentions using Boost to achieve this, but I was reluctant to add that dependency yet.

2. DONE Menus

Started on tutorials 10.2 to add menus for loading and saving the game.

To start, the game renders a main menu with three options, New Game, Continue, Quit.

New Game, starts a new game, deleting the old save. It doesn’t actually delete the save since it overwrites on exit, or deletes the old file on death.

Continue loads an existing save if there is one. Continue only shows if there’s a save. Not happy with how I did this in the end. Feels hacky.

Quit, quits the game. Saves the state on exit, as with any other quit command.

I had to modify a little how the engine initialises since I don’t want to world to display on the main menu when the game starts. Instead it shows just the main menu. But, if you open the menu with , then the world still renders, which is nice. On selecting an item it moves the games states around, creates a world if needed and either loads or resets the game. I had already implemented a reset game state so I reused that for the New Game Functionality.

Everything is managed through state. The game loads into the MainMenuState and then switches based on the selected input.

Files

libtcod-vcpkg-template-e00ca5d-windows.x64.zip 1 MB
Nov 04, 2023
libtcod-vcpkg-template-e00ca5d-macos.x64.tar.gz 1 MB
Nov 04, 2023
libtcod-vcpkg-template-e00ca5d-linux.x64.tar.gz 1 MB
Nov 04, 2023
cpprl-0.0.9.zip 61 kB
Nov 04, 2023

Get Yet Another Roguelike tutorial with C++ and Libtcod

Leave a comment

Log in with itch.io to leave a comment.