extends Node #preloading crate and marker for box trap var myBox = preload("res://scenes/crate.tscn") @onready var box_trap = $"../BoxTrap" @onready var timer = $Timer @onready var player = $"../CharacterBody2D" @onready var coins = $"../Coins" @onready var enemies = $"../Enemies" @onready var ui = $"../CanvasLayer/UI" # Called when the node enters the scene tree for the first time. func _ready(): GameManager.resetPlayer() ui.coinsUpdate(GameManager.coinCollectedTotal) ui.healthUpdate(GameManager.player.health) #the above might not always work, and might return an error due to loading orders; #if that happens, uncomment the initialization versions in the ui script itself for n in coins.get_children(): if n is Coin: #wire up our listener n.coinCollected.connect(_on_coin_coin_collected) for n in enemies.get_children(): if n is BadGuy: n.playerDamage.connect(playerDamage) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): if GameManager.player.health <= 0 and player.living: player.die() func _on_area_2d_areatrigger(effect, body): print("Game Controller sees the trigger " + effect) match effect: "alert": #do stuff print("hi") if body.is_in_group("player"): for n in 3: var box = myBox.instantiate() owner.add_child(box) box.transform = box_trap.transform func resetWorld(): get_tree().reload_current_scene() func _on_coin_coin_collected(): GameManager.coinCollected() ui.coinsUpdate(GameManager.coinCollectedTotal) func playerDamage(): if player.living: GameManager.playerDamage() ui.healthUpdate(GameManager.player.health) func _on_death_complete(): #this is where we start the timer that will, in turn, reset the world timer.start(0.5)