I am trying to figure out what is the best way to handle persistent changes in game world. Metroidvania games keep track of the player actions within a level, for example "this boss has been defeated", "this power up has been taken", "this button has been pushed", etc. In "Cave Story", some completed actions will change the state of the main village, and some NPCs will have dialog specific to what the player has done, before.
I can think of two different ways to handle this functionality:
- Having a copy of the same map, for each state; this sounds resource heavy, and inefficient.
- Using some kind of "chapter" definition that allows me to load/initialise each object of the map in regards to the current chapter. For example, multiple versions of the same NPC would exist, on the map, at various locations, with a chapter attribute. The map can start to get messy, and it can be hard to test.
In regards to the second option, different behaviors and the object loading code would look like this:
if (object.currentChapter == currentChapter) {
object.load()
}
I am using Tiled, and as proposed, it can then be possible to load the object layer corresponding to the current game state or chapter:
loadMap(map, chapter) {
...
createObjects(map, objectLayerName)
}
As an example, in object_chapter_1
, the wizard is outside of a laboratory. In object_chapter_2
, the wizard is inside of the laboratory, preparing some magic potions.
I can't really figure out what is the best solution, and what techniques can be used to deal with this problem. What are the differant techniques to deal with different world and story states, in metroidvanias?