paratate/systems/bullets/spawn_patterns/line_pattern.gd

28 lines
1,013 B
GDScript

class_name LinePattern
extends BulletSpawnPattern
## Spawns bullets evenly spaced out along a line segment.
## Number of bullets to spawn along the line.
@export var bullet_count: int
## The speed that bullets will start with.
@export var bullet_speed: float
## Distance between the first and last bullet in the line.
@export var line_width: float
## The direction that spawned bullets will travel, orthogonal to the line of bullets.
@export_custom(0, "direction") var line_normal: Vector2 = Vector2.RIGHT
func _spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void:
for i in bullet_count:
var bullet = Bullet.create(preset, line_normal.rotated(bullet_set.spawn_rotation))
bullet.speed = bullet_speed
var line = line_normal.orthogonal().rotated(bullet_set.spawn_rotation)
var weight = float(i) / float(bullet_count - 1)
weight -= 0.5
if bullet_count == 1:
weight = 0.0
bullet.position = bullet_set.spawn_offset + line * weight * line_width
bullet_set.add_bullet(bullet)