From 793564a44706b302921fae599f5cbe2fb8590e67 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 22 Apr 2023 18:45:03 -0400 Subject: Added traps --- Archipelago/client.gd | 8 ++++- Archipelago/effects.gd | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ Archipelago/load.gd | 6 ++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 Archipelago/effects.gd diff --git a/Archipelago/client.gd b/Archipelago/client.gd index dba8227..97e2ca4 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd @@ -523,7 +523,7 @@ func processItem(item, index, from): _has_colors.append(lcol) emit_signal("evaluate_solvability") - # Show a message about the item if it's new. + # Show a message about the item if it's new. Also apply effects here. if index != null and index > _last_new_item: _last_new_item = index saveLocaldata() @@ -545,6 +545,12 @@ func processItem(item, index, from): else: messages_node.showMessage("Received %s from %s" % [item_name, player_name]) + var effects_node = get_tree().get_root().get_node("Spatial/AP_Effects") + if item_name == "Slowness Trap": + effects_node.trigger_slowness_trap() + if item_name == "Iceland Trap": + effects_node.trigger_iceland_trap() + func doorIsVanilla(door): return !_mentioned_doors.has(door) diff --git a/Archipelago/effects.gd b/Archipelago/effects.gd new file mode 100644 index 0000000..7d7e0fe --- /dev/null +++ b/Archipelago/effects.gd @@ -0,0 +1,89 @@ +extends Node + +var effect_running = false +var slowness_remaining = 0 +var iceland_remaining = 0 + +var orig_env +var orig_walk +var orig_run + + +func _ready(): + orig_env = get_tree().get_root().get_node("Spatial/player/pivot/camera").environment + orig_walk = get_tree().get_root().get_node("Spatial/player").walk_speed + orig_run = get_tree().get_root().get_node("Spatial/player").run_speed + + var label = Label.new() + label.set_name("label") + label.margin_right = 1920.0 - 20.0 + label.margin_top = 20.0 + label.align = Label.ALIGN_RIGHT + label.valign = Label.VALIGN_TOP + + var dynamic_font = DynamicFont.new() + dynamic_font.font_data = load("res://fonts/Lingo.ttf") + dynamic_font.size = 36 + dynamic_font.outline_color = Color(0, 0, 0, 1) + dynamic_font.outline_size = 2 + label.add_font_override("font", dynamic_font) + + add_child(label) + + +func trigger_slowness_trap(): + if slowness_remaining == 0: + var player = get_tree().get_root().get_node("Spatial/player") + player.walk_speed = orig_walk / 2.0 + player.run_speed = orig_run / 2.0 + + slowness_remaining += 30 + + if not effect_running: + _process_effects() + + +func trigger_iceland_trap(): + if iceland_remaining == 0: + get_tree().get_root().get_node("Spatial/player/pivot/camera").set_environment( + load("res://environments/level_iceland.tres") + ) + + iceland_remaining += 30 + + if not effect_running: + _process_effects() + + +func _process_effects(): + effect_running = true + + while slowness_remaining > 0 or iceland_remaining > 0: + var text = "" + if slowness_remaining > 0: + text += "Slowness: %d seconds" % slowness_remaining + if iceland_remaining > 0: + if not text.empty(): + text += "\n" + text += "Iceland: %d seconds" % iceland_remaining + self.get_node("label").text = text + + yield(get_tree().create_timer(1.0), "timeout") + + if slowness_remaining > 0: + slowness_remaining -= 1 + + if slowness_remaining == 0: + var player = get_tree().get_root().get_node("Spatial/player") + player.walk_speed = orig_walk + player.run_speed = orig_run + + if iceland_remaining > 0: + iceland_remaining -= 1 + + if iceland_remaining == 0: + get_tree().get_root().get_node("Spatial/player/pivot/camera").set_environment( + orig_env + ) + + effect_running = false diff --git a/Archipelago/load.gd b/Archipelago/load.gd index f526411..80f7d06 100644 --- a/Archipelago/load.gd +++ b/Archipelago/load.gd @@ -200,6 +200,12 @@ func _load(): messages.set_name("AP_Messages") self.add_child(messages) + # Create the effects node. + var effects_script = ResourceLoader.load("user://maps/Archipelago/effects.gd") + var effects = effects_script.new() + effects.set_name("AP_Effects") + self.add_child(effects) + # Hook up the scene to be able to handle connection failures. apclient.connect("could_not_connect", self, "archipelago_disconnected") -- cgit 1.4.1