2026-03-09 20:48:04 +00:00
|
|
|
class_name GameController extends Node2D
|
2026-03-03 02:00:36 +00:00
|
|
|
|
2026-03-09 20:48:04 +00:00
|
|
|
var crateTotal:int = 0
|
|
|
|
|
signal destroySignal(body)
|
|
|
|
|
signal teleportSignal(body)
|
|
|
|
|
signal levelChangeSignal(level)
|
|
|
|
|
|
|
|
|
|
var timer := Timer.new()
|
|
|
|
|
var timeAvailable := 10
|
|
|
|
|
var currentScene:String = "res://scenes/game.tscn"
|
2026-03-03 02:00:36 +00:00
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready() -> void:
|
2026-03-09 20:48:04 +00:00
|
|
|
add_child(timer)
|
|
|
|
|
timer.wait_time = 1
|
|
|
|
|
timer.one_shot = false
|
|
|
|
|
timer.connect("timeout", secondCounter)
|
|
|
|
|
timer.start()
|
2026-03-03 02:00:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
pass
|
|
|
|
|
|
2026-03-09 20:48:04 +00:00
|
|
|
func secondCounter()->void:
|
|
|
|
|
timeAvailable -=1
|
|
|
|
|
if timeAvailable<=0:
|
|
|
|
|
print("You Lose Baby!!")
|
|
|
|
|
levelChangeSignal.emit(currentScene)
|
|
|
|
|
|
|
|
|
|
func _on_trigger(body: Variant, effect:String, trigger:Trigger) -> void:
|
2026-03-03 02:00:36 +00:00
|
|
|
print("GC knows trigger...."+effect)
|
|
|
|
|
if body is Crate:
|
|
|
|
|
match effect:
|
|
|
|
|
"destroy":
|
2026-03-09 20:48:04 +00:00
|
|
|
destroySignal.emit(body)
|
|
|
|
|
"teleport":
|
|
|
|
|
teleportSignal.emit(body)
|
|
|
|
|
if body is Player:
|
|
|
|
|
match effect:
|
|
|
|
|
"timeExtend":
|
|
|
|
|
timeAvailable +=5
|
|
|
|
|
destroySignal.emit(trigger)
|
|
|
|
|
|
|
|
|
|
func updateCrates(total:int)->void:
|
|
|
|
|
crateTotal = total
|
|
|
|
|
print("Crate total: "+str(crateTotal))
|
|
|
|
|
if crateTotal <=0:
|
|
|
|
|
print("You WON!!!")
|
|
|
|
|
levelChangeSignal.emit(currentScene)
|