51 lines
1.3 KiB
GDScript
51 lines
1.3 KiB
GDScript
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
|
|
# 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)
|
|
|
|
# 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:
|
|
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))
|