Updated cycle testing logic and various other behaviours for enhanced

system.
This commit is contained in:
Henry Faber 2026-06-29 22:12:28 +01:00
parent 1ac71cc104
commit 7ffb93963f
10 changed files with 237 additions and 31 deletions

View file

@ -5,13 +5,24 @@ class_name ShootComponent extends Node
@onready var ship: Sprite2D = get_node("../Ship")
@onready var fire_helper: WeaponFireHelper = %WeaponFireHelper
func shoot():
var weapon_data = weapon_component.weapon_data
var current_time = Time.get_ticks_msec() / 1000.0
func shoot() -> void:
var active_weapons: Array[WeaponShot] = weapon_component.get_active_weapons()
if active_weapons.is_empty():
return
if player.travel > weapon_data.projectile_vertical_spacing:
_shoot_standard(weapon_data, current_time)
_shoot_grouped(weapon_data, current_time)
var current_time: float = Time.get_ticks_msec() / 1000.0
# Burst gating: find the minimum projectile_vertical_spacing among all
# active weapons. This is the most restrictive timing threshold.
var min_spacing: float = INF
for w: WeaponShot in active_weapons:
if w.projectile_vertical_spacing < min_spacing:
min_spacing = w.projectile_vertical_spacing
if player.travel > min_spacing:
for w: WeaponShot in active_weapons:
_shoot_standard(w, current_time)
_shoot_grouped(w, current_time)
# Reset travel after firing to prevent multiple bursts per tap
player.travel = 0.0
@ -26,12 +37,12 @@ func _get_spawn_position(weapon_data: WeaponShot) -> Vector2:
sprite_height = ship.texture.get_height()
# Top edge of the sprite in world space, then offset by origin.
var top_edge = ship.global_position.y - (sprite_height / 2.0)
var top_edge: float = ship.global_position.y - (sprite_height / 2.0)
return Vector2(ship.global_position.x, top_edge + weapon_data.origin)
# Standard projectile logic (delegates to WeaponFireHelper)
func _shoot_standard(weapon_data: WeaponShot, current_time: float):
func _shoot_standard(weapon_data: WeaponShot, current_time: float) -> void:
var total_projectiles: int = weapon_data.projectiles
if total_projectiles > 0:
@ -40,8 +51,8 @@ func _shoot_standard(weapon_data: WeaponShot, current_time: float):
get_tree().root.add_child(bullet)
# Delegate math to the helper
var spawn_position = _get_spawn_position(weapon_data)
var props = fire_helper.compute_standard_props(weapon_data, b, spawn_position, current_time)
var spawn_position: Vector2 = _get_spawn_position(weapon_data)
var props: Dictionary = fire_helper.compute_standard_props(weapon_data, b, spawn_position, current_time)
bullet.position = props.position
bullet.angle = props.angle
bullet.time_offset = props.time_offset
@ -56,15 +67,15 @@ func _shoot_standard(weapon_data: WeaponShot, current_time: float):
# Grouped projectile logic (delegates to WeaponFireHelper)
func _shoot_grouped(weapon_data: WeaponShot, current_time: float):
func _shoot_grouped(weapon_data: WeaponShot, current_time: float) -> void:
for group: WeaponProjectileGroup in weapon_data.groups.filter(func(g): return g != null):
for b in range(group.bullet_count):
var bullet := weapon_data.bullet_scene.instantiate() as Area2D
get_tree().root.add_child(bullet)
# Apply computed properties for the original bullet
var spawn_position = _get_spawn_position(weapon_data)
var props = fire_helper.compute_grouped_props(group, weapon_data, b, spawn_position, current_time, false)
var spawn_position: Vector2 = _get_spawn_position(weapon_data)
var props: Dictionary = fire_helper.compute_grouped_props(group, weapon_data, b, spawn_position, current_time, false)
bullet.position = props.position
bullet.angle = props.angle
bullet.time_offset = props.time_offset
@ -79,8 +90,8 @@ func _shoot_grouped(weapon_data: WeaponShot, current_time: float):
get_tree().root.add_child(mirror_bullet)
# Apply computed properties for the mirrored bullet
var mirror_spawn = _get_spawn_position(weapon_data)
var mirror_props = fire_helper.compute_grouped_props(group, weapon_data, b, mirror_spawn, current_time, true)
var mirror_spawn: Vector2 = _get_spawn_position(weapon_data)
var mirror_props: Dictionary = fire_helper.compute_grouped_props(group, weapon_data, b, mirror_spawn, current_time, true)
mirror_bullet.position = mirror_props.position
mirror_bullet.angle = mirror_props.angle
mirror_bullet.time_offset = mirror_props.time_offset