34 lines
866 B
GDScript3
34 lines
866 B
GDScript3
|
class_name GameController extends Node2D
|
||
|
var totalCrates = 3
|
||
|
var timeLimit = 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", secondCounter)
|
||
|
timer.start()
|
||
|
func secondCounter():
|
||
|
print("tick")
|
||
|
timeLimit -=1
|
||
|
if timeLimit <= 0:
|
||
|
print("you lose baby")
|
||
|
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_fired(effect: Variant, body: Variant) -> void:
|
||
|
print("Game controller knows :: "+effect)
|
||
|
if effect=="destroy":
|
||
|
totalCrates -= 1
|
||
|
print("Crates Remaining " + str(totalCrates) )
|
||
|
body.queue_free()
|
||
|
if totalCrates == 0:
|
||
|
print("YOU WIN!")
|
||
|
get_tree().reload_current_scene()
|