Updated architecture so WeaponComponent uses an exported array to store
weapon resources.
This commit is contained in:
parent
63ed0aae3a
commit
cf172bc546
7 changed files with 88 additions and 36 deletions
|
|
@ -1,13 +1,10 @@
|
|||
class_name ShootComponent extends Node
|
||||
|
||||
@export var stagger_offset: float = 0.5 # Time delay per projectile index (seconds)
|
||||
@export var horizontal_offset: float = 1.0 # Horizontal distance per projectile index
|
||||
|
||||
@onready var weapon_component: Node = %WeaponComponent
|
||||
@onready var player = $".."
|
||||
|
||||
func shoot():
|
||||
var weapon_data = weapon_component.data # WeaponShot resource configuration
|
||||
var weapon_data = weapon_component.weapon_data
|
||||
var current_time = Time.get_ticks_msec() / 1000.0
|
||||
var total_projectiles = weapon_data.projectiles
|
||||
|
||||
|
|
@ -18,15 +15,14 @@ func shoot():
|
|||
|
||||
if total_projectiles > 0:
|
||||
for b in range(total_projectiles):
|
||||
var bullet_scene = weapon_data.bullet_scene
|
||||
var bullet := bullet_scene.instantiate() as Area2D
|
||||
var bullet := weapon_data.bullet_scene.instantiate() as Area2D
|
||||
get_tree().root.add_child(bullet)
|
||||
|
||||
# Calculate index relative to center (0 = center, -1/+1 = first from center)
|
||||
var index_from_center: float = b - center_index
|
||||
|
||||
# Calculate timing offset for staggered firing
|
||||
var time_offset: float = index_from_center * stagger_offset
|
||||
var time_offset: float = index_from_center * weapon_data.stagger_offset
|
||||
|
||||
# Calculate horizontal offset for this bullet (symmetrical: left=-ve, right=+ve)
|
||||
var bullet_horizontal_offset: float = index_from_center * weapon_data.horizontal_offset
|
||||
|
|
@ -42,7 +38,7 @@ func shoot():
|
|||
bullet.time_offset = time_offset
|
||||
bullet.fire_time = current_time + time_offset
|
||||
|
||||
# Set the bullet data (this is what was missing)
|
||||
# Set the bullet data
|
||||
bullet.set_weapon_data(weapon_data.bullet_scene, weapon_data)
|
||||
|
||||
# Subtract projectile spacing from current Player travel for next shot
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue