32 lines
881 B
GDScript3
32 lines
881 B
GDScript3
|
class_name GameController extends Node2D
|
||
|
var totalCrates = 10
|
||
|
var timeLimit = 4
|
||
|
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()# Replace with function body.
|
||
|
func secondCounter():
|
||
|
print("tick")
|
||
|
timeLimit -=1
|
||
|
if timeLimit <= 0:
|
||
|
print ("YOU LOSE")
|
||
|
|
||
|
# 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("GameController knows :: "+effect)
|
||
|
if effect=="destroy":
|
||
|
totalCrates -=1
|
||
|
print("Crates Remaining"+str(totalCrates))# Replace with function body.
|
||
|
body.queue_free()
|
||
|
if totalCrates==0:
|
||
|
print("YOU WIN")
|
||
|
get_tree().reload_current_scene()
|