Added bullet indexing to create shot patterns
This commit is contained in:
parent
bdbc3b015f
commit
1725b8b754
13 changed files with 91 additions and 27 deletions
|
|
@ -12,7 +12,7 @@ class_name MovementComponent extends Node
|
|||
var input = Input.get_vector("left", "right", "up","down")
|
||||
|
||||
func tick(delta: float):
|
||||
|
||||
|
||||
# Check to see if there's a player to move
|
||||
if player == null: return
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +1,49 @@
|
|||
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 = $".."
|
||||
|
||||
|
||||
# Change from instantiating WeaponComponent to instantiating Shot nodes
|
||||
func shoot():
|
||||
var weapon_data = weapon_component.data # WeaponShot resource configuration
|
||||
var current_time = Time.get_ticks_msec() / 1000.0
|
||||
var total_projectiles = weapon_data.projectiles
|
||||
|
||||
if player.travel > weapon_data.spacing:
|
||||
for b in range(weapon_data.projectiles):
|
||||
|
||||
# Get the Shot scene from the WeaponShot resource
|
||||
var bullet_scene = weapon_data.bullet_scene # Or however you store it
|
||||
|
||||
# Instantiate the bullet based data
|
||||
var bullet := bullet_scene.instantiate() as Node
|
||||
get_tree().root.add_child(bullet)
|
||||
|
||||
# Set up the bullet from resource data
|
||||
#bullet.shot_data = weapon_data # Pass the configuration
|
||||
# Calculate center index for symmetrical staggering
|
||||
var center_index = (total_projectiles - 1) / 2.0
|
||||
|
||||
# Adjust bullet spacing before firing
|
||||
bullet.position = player.position + Vector2((b - (weapon_data.projectiles - 1) / 2.0) * round(round((weapon_data.projectiles + weapon_data.spacing / 2)) / 2 - 2), weapon_data.origin)
|
||||
print(b, bullet.position.x)
|
||||
print(weapon_data.shot_name + " "+"fired!")
|
||||
if total_projectiles > 0:
|
||||
for b in range(total_projectiles):
|
||||
var bullet_scene = weapon_data.bullet_scene
|
||||
var bullet := bullet_scene.instantiate() as Node
|
||||
get_tree().root.add_child(bullet)
|
||||
|
||||
# Subtract projectile spacing from current Player travel for next
|
||||
player.travel -= weapon_data.spacing
|
||||
# Calculate index relative to center (0 = center, -1/+1 = first from center)
|
||||
var index_from_center: int = b - center_index
|
||||
|
||||
else: return
|
||||
# Calculate timing offset for staggered firing
|
||||
# Negative = fire before center (left), positive = fire after center (right)
|
||||
var time_offset: float = index_from_center * stagger_offset
|
||||
|
||||
# Calculate horizontal offset for symmetrical spread (left = negative, right = positive)
|
||||
horizontal_offset = index_from_center * weapon_data.spacing_horizontal
|
||||
|
||||
# Calculate vertical offset from center point (creates symmetrical vertical spread)
|
||||
# Bullets on either side of center get offset by distance_from_center * spacing / 2
|
||||
# This keeps the center bullet at origin and creates symmetrical vertical spread
|
||||
var distance_from_center: float = abs(index_from_center)
|
||||
var vertical_offset: float = (distance_from_center * weapon_data.origin * -1) / 2
|
||||
|
||||
# Final position combines symmetrical horizontal spread with symmetrical vertical spacing
|
||||
bullet.position = player.position + Vector2(horizontal_offset, weapon_data.origin + vertical_offset)
|
||||
|
||||
## Set timing properties on the bullet
|
||||
#bullet.time_offset = time_offset
|
||||
#bullet.fire_time = current_time + time_offset
|
||||
|
||||
# Subtract projectile spacing from current Player travel for next
|
||||
player.travel -= weapon_data.spacing
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue