GodotProject/scripts/gamecontroller.gd

37 lines
742 B
GDScript

extends Node
var crate = preload("res://scenes/crate.tscn")
@onready var boxtrap = $"../crates/boxtrap"
@onready var timer = $Timer
@onready var player = $"../CharacterBody2D"
var totalCoins = 0
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 = crate.instantiate()
owner.add_child(box)
box.position = boxtrap.position
"powerup":
print("you got power")
func coinCollected():
totalCoins += 1
print("Game controller will add coin " + str(totalCoins))
func playerDeath():
player.die()
timer.start()
func resetWorld():
get_tree().reload_current_scene()