extends Node2D

export (Array,PackedScene) var scenes

var random_scene = RandomNumberGenerator.new()
var scene_index = 0;
var last_object
var end_of_game = false

var spawner_enabled = false


func _ready():
	Signals.connect("die",self,"game_over")
	Signals.connect("win",self,"game_over")


func _on_Timer_timeout():
	if spawner_enabled:
		random_scene.randomize()
		scene_index = random_scene.randi_range(0,scenes.size()-1)
		var tmp = scenes[scene_index].instance()
		$items.add_child(tmp)
		last_object = tmp
		self.get_node("Timer").wait_time *= 0.99
		self.get_node("Timer").start()


func game_over():
	self.get_node("Timer").set_paused(true)
	last_object.queue_free()


func start():
	spawner_enabled = true
	self.get_node("Timer").set_paused(false)


func stop():
	spawner_enabled = false
	for obj in $items.get_children():
		remove_child(obj)
		obj.queue_free()
