Sunday, October 7, 2018

How do I implement a retro-style password-based "savegame" system?


How would I make a password system for a single-player game like the ones used in older console games?


For example, Mega Man X saves work by giving you a series of numbers that you can enter later to load your save.



Answer



First, break down your game state (or rather, the aspects of the state you want to save). In the case of a Mega Man style game, you might track which of the end-level bosses you've killed, the number of energy-tank-like powerups you have, and so on.


Pack all of that data into a bit field, that is, assign an appropriate number of bits to each value:



  • Killed boss 1 (one bit)

  • Killed boss 2 (one bit)


  • Killed boss 3 (one bit)

  • Killed boss 4 (one bit)

  • Energy tanks (x of 5 total) (3 bits)

  • Unlocked some achievement (one bit)


Our example has 8 bits total, which means a single character can represent a password. In practice, your game is likely to have more state and thus require more total bits and thus more characters. As noted in the comments here and elsewhere in this question, this approach works for "retro" games or other games where the size of the captured game state is reasonable. Beyond a certain point, you may discover that the complexity of the passwords necessary to encode your state is too large.


To decrease the likelyhood of casual observation cracking the password, you can transform the bit layout so that you introduce dummy bits (which have no effect on the game state but which make the password look different when you interpret all the bits as characters) or run it through some reversible hash-like operation to scramble the bits around so that all the "killed box X" bits are not right next to eachother, making corresponding sequential-state passwords look very different, or introduce checksum values.


If you dig around, there's a fair bit of information on the systems employed for some of the more-popular passworded games out there:



You could read up on those for additional inspiration.



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...