2048-Shooter/Objects/Spawner.gd

51 lines
1.1 KiB
GDScript3
Raw Permalink Normal View History

2022-11-27 20:47:03 +01:00
extends Panel
var enemy_pre = preload("res://Objects/Entity.tscn")
var item_pre = preload("res://Objects/item.tscn")
var enemy = null
var item = null
var e_speed = 50
var e_life = 2
var spawn_rate = 3
var spawn_speed = 3.5
2022-11-27 20:47:03 +01:00
var rng = RandomNumberGenerator.new()
var Time = 0
# Called when the node enters the scene tree for the first time.
func _ready():
rng.randomize()
if rng.randi_range(0, spawn_rate) == 0:
enemy = enemy_pre.instance()
add_child(enemy)
var Progressbars = get_tree().get_nodes_in_group("XP")
for Progressbar in Progressbars:
Progressbar.connect("full_bar", self, "set_spawn_values")
pass
func _process(delta):
Time += delta
if Time > spawn_speed:
2022-11-27 20:47:03 +01:00
rng.randomize()
if rng.randi_range(0, spawn_rate) == 0:
if rng.randi_range(0, 10) != 0:
enemy = enemy_pre.instance()
enemy.speed = e_speed
enemy.life = e_life
add_child(enemy)
else:
item = item_pre.instance()
item.speed = e_speed
add_child(item)
Time = 0
func set_spawn_values(value):
e_speed += value
e_life *= 2
if (spawn_rate > 1):
2022-11-27 20:47:03 +01:00
spawn_rate -= 1
elif spawn_speed > 1.5:
spawn_speed -= 0.1
2022-11-27 20:47:03 +01:00
pass