extends Node2D

var boxTotal = 4
var timer:=Timer.new()
var countdown = 10

# C alled 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()
	pass # Replace with function body.
func secondCounter():
	# print("one second")
	countdown -=1
	if countdown <=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(effect: Variant, body) -> void:
	print("Game Controller sees an alert.")
	if body is RigidBody2D:
		print("I see a rigid body.")
		body.queue_free()
		boxTotal -=1
		if boxTotal <=0:
			print("YOU WON!!")
			get_tree().reload_current_scene()

func bulletHit(body):
	print("Game controller knows bullet hit something")
	if body.is_in_group("destructable"):
		body.queue_free()