AprilGodotGame/gamecontroller.gd

44 lines
1.1 KiB
GDScript3
Raw Permalink Normal View History

class_name GameController extends Node2D
var totalCrates = 3
var timeLimit = 10
var timer = Timer.new()
# 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():
print("tick "+str(timeLimit))
timeLimit -= 1
if timeLimit <= 0:
print("YOU LOSE...")
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_trigger_fired(effect: Variant, body: Variant) -> void:
print("GameController know about trigger " + effect)
if effect == "destroy":
totalCrates -= 1
print("Crates remaining: " + str(totalCrates))
body.queue_free()
if totalCrates == 0:
print("YOU WIN!")
get_tree().reload_current_scene()
func numberOfCrates(value:int)->void:
totalCrates = value
func bulletDamage(body, bullet):
print("Game controller knows about bullet")
body.queue_free()
#bullet.queue_free()