45 lines
1.1 KiB
GDScript3
45 lines
1.1 KiB
GDScript3
|
extends Node
|
||
|
|
||
|
#This node is a scene manager. It is used to control all the visible
|
||
|
#assets in the viewport. However the scene manager does not encapsulate
|
||
|
#overall logic, and it does not persist data - that belongs to the GameManager,
|
||
|
#which is an autoload singleton.
|
||
|
|
||
|
var coinsCollected = 0
|
||
|
|
||
|
var crate = preload("res://scenes/crate.tscn")
|
||
|
@onready var boxtrap = $"../crates/boxtrap"
|
||
|
@onready var timer = $Timer
|
||
|
@onready var player = $"../CharacterBody2D"
|
||
|
|
||
|
func _ready():
|
||
|
GameManager.resetPlayer()
|
||
|
|
||
|
func _on_area_2d_areatrigger(effect, body):
|
||
|
match effect:
|
||
|
"alert":
|
||
|
#do stuff
|
||
|
if body.is_in_group("player"):
|
||
|
for n in 3:
|
||
|
var box = crate.instantiate()
|
||
|
owner.add_child(box)
|
||
|
box.position = boxtrap.position
|
||
|
|
||
|
func coinCollected():
|
||
|
print("scene manager saw coin collected")
|
||
|
GameManager.coinsCollected +=1
|
||
|
|
||
|
func resetGame():
|
||
|
timer.start(.5)
|
||
|
|
||
|
func _on_timer_timeout():
|
||
|
get_tree().reload_current_scene()
|
||
|
|
||
|
#Scene control loop
|
||
|
func _process(delta):
|
||
|
if GameManager.player.health < 0 && player.living:
|
||
|
player.die()
|
||
|
|
||
|
func _on_badguy_player_damage():
|
||
|
player.hurt()
|