MarchTTLGame/scripts/gameController.gd

51 lines
1.3 KiB
GDScript3
Raw Permalink Normal View History

class_name GameController extends Node2D
2026-03-09 21:11:08 +00:00
var crateTotal = 0
signal destroySignal(body)
signal teleportSignal(body)
signal levelChangeSignal(level)
var currentScene:String = "res://scenes/game.tscn"
2026-03-09 21:11:08 +00:00
var timer := Timer.new()
var timeAvailable := 10
2026-03-09 21:11:08 +00:00
# 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()->void:
timeAvailable -=1
if timeAvailable <=0:
print("YOU LOST YOU ARE A LOSER YOU SUCK")
levelChangeSignal.emit(currentScene)
2026-03-09 21:11:08 +00:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_trigger(body: Variant, effect, trigger) -> void:
2026-03-09 21:11:08 +00:00
print("GC knows trigger...."+effect)
if body is Crate:
match effect:
"destroy":
crateTotal -=1
if crateTotal <=0:
print("You WON!!!")
levelChangeSignal.emit(currentScene)
destroySignal.emit(body)
"teleport":
print("GC teleport")
teleportSignal.emit(body)
if body is Player:
match effect:
"powerup":
timeAvailable += 5
destroySignal.emit(trigger)
func crateUpdate(cratesAmount)->void:
crateTotal = cratesAmount
print("GC updated crates: "+str(crateTotal))