Generally you just copy the existing save file every time you save the game. Some games will delete the copy as soon as the save operation is complete, but I've always kept it around just in case. What you're primarily trying to avoid by doing all this is the player losing everything if the game crashes, the OS crashes, the power goes out, et cetera in the middle of a hard drive operation leaving you with only half a save file.
Ah I see, that makes sense! I'm saving my main save files via the Steam API which I just pass a buffer of data to - so don't think I could do any kind of backing up there. But for the options files, and non-Steam build of the game, it would be a good feature.
World Map Month Started!I've finally started work on the world map! The core feature set of the map will be:
- Moving along paths between levels
- Branching paths
- Secret paths reached by secret exits
And then I have ideas for various extra bits on top of this. But this is the basic starting point.
My favourite way to start this kind of task is to open up Tiled and just place some stuff down. It's easier to get an idea of what kind of data I'll be feeding into the game that way.
So, rectangle objects for levels, lines for paths. The next step is to get this data loaded into the game. I made a simple representation of the map that uses three types of data:
- Path sections: A single straight-line section of path. Links to a junction at each end.
- Junction: Automatically created at the ends of path sections. Links to one or more paths. Can also link to a level marker. Represented by a yellow rectangle in the image below.
- Level marker: Represents a level. Links to a single junction.
The junctions tie everything together in a nice simple way, because:
- Path sections don't need to know about Level Markers at all
- If I add more map features (e.g. things that can be interacted with that aren't levels) then they will also link to junctions
- Actors that move around the map (e.g. Leilani) can navigate the whole thing using only Path Sections and Junctions, they also don't need to care about Level markers.
Next I started getting the flow in for unlocking paths and levels.
When the level is completed, it tells its junction to propagate the "unlocked" state. So the junction will unlock any relevant paths that lead from that junction. When the path has done it's unlocking animation, it tells the next junction to propagate the "unlocked" state. If the junction links to a level then it'll unlock the level, otherwise it'll unlock more paths. So the unlock state naturally flows through the map with very little effort.
Path sections are aware of whether they are a secret path or not (secret paths are orange in the gif above). So finding a secret exit simply unlocks secret paths instead of normal paths.
Paths are also directional, which is just based on the direction that I drew the path in Tiled. Leilani can walk along a path section in either direction, but it can only be unlocked from one end. The gif below demonstrates this: after using the secret exit to skip a level, you then continue to progress "forwards" through the map. This ensures that even if you skip to an unfamiliar part of the world map, you won't be confused about which direction to progress in.
Finally, I hooked all this stuff into the save data, and the loading and completion of real levels. I also added Leilani, currently represented by a blue triangle.
Traversing the paths and junctions is pretty simple to implement, and uses the junctions to decide most of the logic. For example when the player presses Right, the Leilani actor asks the junction for a path section that leads to the right, and if one exists, starts moving along it. Then when Leilani reaches the end of a path section, she asks the junction "are you a stopping point?" - which could mean that the junction has a level linked to it, or multiple paths to choose from. If the junction isn't a stopping point, it'll instead tell Leilani which path to automatically start moving along next.