42 lines
782 B
GDScript
42 lines
782 B
GDScript
@tool
|
|
extends Composer
|
|
class_name Spawner
|
|
|
|
@export var unit_type: PackedScene
|
|
@export var spawn_duration = 1.0
|
|
|
|
@export var player: Node:
|
|
set(val):
|
|
if val is Player:
|
|
player = val
|
|
else:
|
|
player = null
|
|
|
|
@export var delivery = Vector2(100.0, 0.0):
|
|
set(val):
|
|
delivery = val
|
|
_check_compose()
|
|
|
|
var _spawning_since = 0.0
|
|
|
|
func _compose():
|
|
$delivery.position = delivery
|
|
|
|
func _physics_process(delta):
|
|
if Engine.is_editor_hint():
|
|
return
|
|
|
|
_spawning_since += delta
|
|
if _spawning_since > spawn_duration:
|
|
spawn()
|
|
|
|
func spawn():
|
|
if unit_type:
|
|
var unit := unit_type.instantiate()
|
|
if unit is Unit:
|
|
unit.position = delivery
|
|
unit.player = player
|
|
_spawning_since = min(0.0, _spawning_since - spawn_duration)
|
|
# FIXME add to battlefield
|
|
add_child(unit)
|