GodotCourse/week5/updated_project/scripts/gamecontroller.gd

34 lines
765 B
GDScript3
Raw Normal View History

2024-08-12 19:32:24 +00:00
extends Node
2024-08-12 14:22:12 +00:00
2024-08-12 19:19:54 +00:00
var coinsCollected = 0
2024-08-12 14:22:12 +00:00
var crate = preload("res://scenes/crate.tscn")
2024-08-12 19:32:24 +00:00
@onready var boxtrap = $"../crates/boxtrap"
2024-08-12 21:43:39 +00:00
@onready var timer = $Timer
2024-08-12 19:32:24 +00:00
@onready var player = $"../CharacterBody2D"
2024-08-12 14:22:12 +00:00
func _on_area_2d_areatrigger(effect, body):
print("Game Controller sees the trigger "+effect)
match effect:
"alert":
#do stuff
if body.is_in_group("player"):
for n in 3:
var box = crate.instantiate()
2024-08-12 19:32:24 +00:00
owner.add_child(box)
2024-08-12 14:22:12 +00:00
box.position = boxtrap.position
"powerup":
print("you got power")
2024-08-12 19:19:54 +00:00
"kill":
print("kill the player")
func coinCollected():
coinsCollected +=1
print("coins collected "+str(coinsCollected) )
func playerDeath():
2024-08-12 21:43:39 +00:00
player.die()
timer.start()
func _on_timer_timeout():
get_tree().reload_current_scene()