MarchGame/scripts/gameController.gd

63 lines
1.4 KiB
GDScript3
Raw Permalink Normal View History

2026-03-10 01:04:23 +00:00
class_name GameController extends Node2D
var crateTotal=0
signal destroySignal(body)
signal teleportSignal(body)
signal levelChangeSignal(level)
var currentScene:String="res://scenes/game.tscn"
var timer := Timer.new()
var timeAvailable := 10
2026-03-03 02:07:00 +00:00
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
2026-03-10 01:04:23 +00:00
add_child(timer)
timer.wait_time =1
timer.one_shot=false
timer.connect("timeout", secondCounter)
timer.start()
2026-03-03 02:07:00 +00:00
2026-03-10 01:04:23 +00:00
func secondCounter()-> void:
timeAvailable -=1
if timeAvailable <=0:
print("YOU LOSE!!")
levelChangeSignal.emit(currentScene)
2026-03-03 02:07:00 +00:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
2026-03-10 01:04:23 +00:00
func _on_trigger(body: Variant,effect,trigger) -> void:
2026-03-03 02:07:00 +00:00
print("GC knows trigger..."+effect)
if body is Crate:
match effect:
"destroy":
crateTotal -=1
if crateTotal <=0:
print("you win")
2026-03-10 01:04:23 +00:00
levelChangeSignal.emit(currentScene)
destroySignal.emit(body)
"teleport":
print("GC teleport an object")
teleportSignal.emit(body)
"powerup":
print("GC knows powerup")
timeAvailable +=5
if body is Player:
match effect:
"powerup":
print("GC knows powerup")
timeAvailable +=5
destroySignal.emit(trigger)
func crateUpdate(cratesAmount) ->void:
crateTotal=cratesAmount
print("GC updated crates: " +str(crateTotal))
2026-03-03 02:07:00 +00:00