June2026Game/Scripts/game.gd

49 lines
1.2 KiB
GDScript

class_name GameController extends Node2D
signal destroySignal(body)
var numberOfCrates = 2
var timer = Timer.new()
var timeAvailable = 50
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
get_window().grab_focus()
add_child(timer)
# time based on seconds
timer.wait_time = 1
# count to 1 and stuff, false means keep clock running
timer.one_shot = false
timer.connect("timeout", countdown)
timer.start()
func countdown() -> void:
# Reduce time left
timeAvailable -= 1
if timeAvailable <= 0 and numberOfCrates > 0:
print("LOSER")
get_tree().reload_current_scene()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_trigger(body: Variant, trigger: Variant, intent:String) -> void:
print("Game controller knows trigger fired")
match intent:
"destroy":
destroySignal.emit(body)
func crateTotal(howMany):
numberOfCrates = howMany
print("GC knows crates: "+str(numberOfCrates))
if numberOfCrates == 0:
print("YOU WON!!!")
get_tree().reload_current_scene()
func bulletDamage(body, _bullet)->void:
if body.is_in_group("shootable"):
destroySignal.emit(body)
destroySignal.emit(_bullet)