Hi!
I am working on a simple adventure game engine. I made template nodes for the objects in the rooms. There are objects you can pick up, other trigger a dialogue or change the room. This works really great, and the resulting code is very compact.
There is one variable gamestate containing the position in the game where the player is. If they picked something up, the gamestate changes to the next value. This way, a very linear story can be walked through step by step.
There is another variable event. It is set by the interacting object. Every item in the room, every room change or dialogue box click sends a different event string. The game always know what just happened.
The many return calls have a reason. The game manager always simulates the whole game until the step where the player is at. There is no persistent setting of the objects. Everything is built from scratch in every interaction. It should be very easy to load savegames, I only have to set the gamestate variable and the player is exactly in the position of the story where they left.
The issue is: This code is completely unreadable even if it is clean code. Extremely hard to edit. And this is just a 100% linear story. It will become a mess if there are branching stories. I need a different approach and don't know what to do.
Regards
Thomas
$room_lager/textvorlage.set_state("active")
if gamestate == "textvorlage_raumsuche":
if event == "enterroom_lager":
gamestate = "textvorlage_aufgabe"
signals.emit_signal("show_dialogue", "Du hast das Lager gefunden. Siehst du irgendwo die Textvorlage?")
return
if gamestate == "textvorlage_aufgabe":
if event == "dialogue_next_button":
gamestate = "textvorlage"
signals.emit_signal("show_dialogue", "Guckst du im Regal.")
return
if gamestate == "textvorlage":
if event == "objectinteraction_textvorlage":
gamestate = "textvorlage_ablegen"
signals.emit_signal("show_dialogue", "Der Text muss zum Setzkasten.")
else:
return
$room_lager/textvorlage.set_state("invisible")
new_inventory_image = $room_lager/textvorlage.get_inventory_texture()
$room_setzkasten/textvorlage.set_state("empty")
if gamestate == "textvorlage_ablegen":
if event == "objectinteraction_textvorlage_ziel":
signals.emit_signal("show_dialogue", "Super, so hast du den Text immer im Blick.")
gamestate = "textvorlage_abgelegt"
else:
return