63 lines
1.4 KiB
GDScript
63 lines
1.4 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 LOSE!!")
|
|
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 win")
|
|
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))
|
|
|