pir-serious-game-ethics/mini-game/scripts/spawner.gd
2021-04-28 01:39:35 +02:00

61 lines
1.3 KiB
GDScript

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
var timer_speed = 0.99
var random_threshold = 50
var scenes_offset = 0
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(1,100)
if(scene_index >= random_threshold):
scene_index = 1
else:
scene_index = 0
var tmp = scenes[scene_index+scenes_offset*2].instance()
$items.add_child(tmp)
last_object = tmp
if(self.get_node("Timer").wait_time <= 1):
self.get_node("Timer").wait_time = 1
else:
self.get_node("Timer").wait_time *= timer_speed
self.get_node("Timer").start()
func game_over():
self.get_node("Timer").set_paused(true)
last_object.queue_free()
func start(difficulty, version):
match difficulty:
"easy":
timer_speed = 0.99
random_threshold = 50
"hard":
timer_speed = 0.95
random_threshold = 33
_:
pass
scenes_offset = version
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()