22 lines
656 B
GDScript
22 lines
656 B
GDScript
class_name SpawnSystem
|
|
extends System
|
|
|
|
func query():
|
|
# Find all entities that have both transform and velocity
|
|
return q.with_all([C_SpawnPoint]).enabled()
|
|
|
|
func process(entities: Array[Entity], _components: Array, delta: float):
|
|
for entity in entities:
|
|
var spawn_point = entity.get_component(C_SpawnPoint) as C_SpawnPoint
|
|
|
|
if not spawn_point.should_spawn():
|
|
spawn_point.spawn_cooldown -= delta
|
|
continue
|
|
|
|
var spawned = spawn_point.spawn_prefab.instantiate() as Entity
|
|
get_tree().current_scene.add_child(spawned)
|
|
ECS.world.add_entity(spawned)
|
|
|
|
spawned.global_position = entity.global_position
|
|
spawn_point.start_spawn_cooldown()
|