47 lines
1.2 KiB
GDScript
47 lines
1.2 KiB
GDScript
class_name BulletSet
|
|
extends Node2D
|
|
|
|
|
|
## Preset that determines how bullets are spawned, look, and behave.
|
|
@export var preset: BulletPreset
|
|
|
|
|
|
## Offset in pixels from the set's [member position] where
|
|
## a [BulletSpawnPattern] should spawn bullets.
|
|
var spawn_offset: Vector2 = Vector2.ZERO
|
|
## Offset from the set's [member rotation] that a [BulletSpawnPattern] should rotate itself by.
|
|
var spawn_rotation: float = 0.0
|
|
|
|
|
|
func _ready() -> void:
|
|
_spawn_rounds()
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if get_child_count() == 0:
|
|
queue_free()
|
|
|
|
if preset.set_behavior:
|
|
preset.set_behavior.process_set(self, delta)
|
|
|
|
for bullet in get_children():
|
|
if bullet is Bullet:
|
|
bullet.time_elapsed += delta
|
|
preset.behavior.process_bullet(bullet, delta)
|
|
|
|
|
|
func add_bullet(bullet: Bullet) -> void:
|
|
preset.behavior.init_bullet(bullet)
|
|
add_child(bullet)
|
|
|
|
|
|
func add_bullets(new_bullets: Array[Bullet]) -> void:
|
|
for bullet in new_bullets:
|
|
preset.behavior.init_bullet(bullet)
|
|
add_child(bullet)
|
|
|
|
|
|
func _spawn_rounds() -> void:
|
|
for _n in preset.rounds:
|
|
preset.pattern.spawn_bullets(self, preset)
|
|
await get_tree().create_timer(preset.round_delay, false, true).timeout
|