35 lines
880 B
GDScript
35 lines
880 B
GDScript
class_name GameController extends Node2D
|
|
|
|
var total_crates = 4
|
|
var time_limit = 10
|
|
var timer = Timer.new()
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
add_child(timer)
|
|
timer.wait_time = 1
|
|
timer.one_shot = false
|
|
timer.connect('timeout', second_counter)
|
|
timer.start()
|
|
func second_counter():
|
|
print('tick')
|
|
time_limit -= 1
|
|
if time_limit <= 0:
|
|
print('Loser!')
|
|
get_tree().reload_current_scene()
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|
|
|
|
|
|
func _on_trigger_trigger_fired(effect: Variant, body: Variant) -> void:
|
|
print('Game Controller knows :: ' + effect)
|
|
if effect =='Destroy':
|
|
total_crates -= 1
|
|
print('Crates Remaining ' + str(total_crates))
|
|
body.queue_free()
|
|
if total_crates == 0:
|
|
print('Winner!')
|
|
get_tree().reload_current_scene()
|