From ba3c1b6055611a0e08d217cd2555b4265720ef4f Mon Sep 17 00:00:00 2001 From: akshay Date: Sun, 21 Aug 2022 12:13:33 -0400 Subject: [PATCH] Fixed bug with starve and day end dialogs stomping on each other --- scripts/game_manager.gd | 7 ++++++- scripts/player/player.gd | 1 + scripts/player/state/sleeping.gd | 19 +++++++++++-------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/scripts/game_manager.gd b/scripts/game_manager.gd index 873fd06..360c8f2 100644 --- a/scripts/game_manager.gd +++ b/scripts/game_manager.gd @@ -27,7 +27,12 @@ func _unhandled_input(event): toggle_pause_menu() func _on_player_starved_to_death(): - play_simple_dialog("starve") + var node = Dialogic.start("starve") + node.pause_mode = PAUSE_MODE_PROCESS + add_child(node) + get_tree().paused = true + yield(node, "timeline_end") + get_tree().paused = false get_tree().change_scene(MainMenuScenePath) func play_simple_dialog(var dialog_name : String): diff --git a/scripts/player/player.gd b/scripts/player/player.gd index df8e6a3..35679b7 100644 --- a/scripts/player/player.gd +++ b/scripts/player/player.gd @@ -64,6 +64,7 @@ func set_health(new_value): child.visible = child.get_index() < health if health <= 0: emit_signal("starved_to_death") + hunger_timer.stop() func consume_food(item : Resource): set_health(MAX_HEALTH) diff --git a/scripts/player/state/sleeping.gd b/scripts/player/state/sleeping.gd index dfff053..4138afc 100644 --- a/scripts/player/state/sleeping.gd +++ b/scripts/player/state/sleeping.gd @@ -42,8 +42,6 @@ func enter_from(state): # Warp the player to the right position & orientation model_transform.global_transform = hop_position.global_transform else: - # Harm the player and show message - ctx.set_health(ctx.health - 1) var node = Dialogic.start("day_end") node.pause_mode = ctx.PAUSE_MODE_PROCESS ctx.add_child(node) @@ -90,12 +88,17 @@ func unhandled_input(event: InputEvent): var tween = model_transform.create_tween() tween.tween_property(model_transform, "global_transform:origin", old_model_origin, .1) yield(tween, "finished") - - # Show message - var node = Dialogic.start("wake_up") - node.pause_mode = ctx.PAUSE_MODE_PROCESS - ctx.add_child(node) - yield(node, "timeline_end") + + # Harm the player and show message after they hop out + if !made_it_to_bed: + ctx.set_health(ctx.health - 1) + + if ctx.health > 0: + # Show message + var node = Dialogic.start("wake_up") + node.pause_mode = ctx.PAUSE_MODE_PROCESS + ctx.add_child(node) + yield(node, "timeline_end") ctx.change_state(ctx.StateDefault.new())