40 lines
874 B
GDScript
40 lines
874 B
GDScript
extends Node
|
|
|
|
var myBox = preload("res://scenes/crate.tscn")
|
|
@onready var box_trap = $"../BoxTrap"
|
|
@onready var timer = $Timer
|
|
@onready var player = $"../CharacterBody2D"
|
|
|
|
var totalCoins = 0
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
pass
|
|
|
|
|
|
func _on_area_2d_areatrigger(effect, body):
|
|
print("Game Controller sees the trigger " + effect)
|
|
match effect:
|
|
"alert":
|
|
for n in 5:
|
|
var box = myBox.instantiate()
|
|
owner.add_child(box)
|
|
box.transform = box_trap.global_transform
|
|
|
|
|
|
func coinCollected():
|
|
totalCoins += 1
|
|
print("Coin added! Total coins is now " + str(totalCoins))
|
|
|
|
func playerDefeated():
|
|
player.defeated()
|
|
timer.start()
|
|
|
|
func resetWorld():
|
|
get_tree().reload_current_scene()
|