32 lines
1.3 KiB
GDScript
32 lines
1.3 KiB
GDScript
class_name ShootComponent extends Node
|
|
|
|
@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
|
|
|
|
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
|
|
|
|
# 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!")
|
|
|
|
# Subtract projectile spacing from current Player travel for next
|
|
player.travel -= weapon_data.spacing
|
|
|
|
else: return
|