Compare commits

..

8 commits

28 changed files with 241 additions and 340 deletions

View file

@ -1,8 +1,8 @@
extends Area2D
@onready var bullet: PackedScene = load("res://scenes/weapon_stock.tscn")
@onready var bullet: PackedScene = load("res://scenes/player_weapons/weapon_stock.tscn")
@onready var shot_data: = load("res://resources/player_weapons/weapon_shot_stock.tres")
@onready var shot_data: = load("res://resources/player_weapon_resources/weapon_shot_stock.tres")
func _process(delta):

83
Scratch
View file

@ -1,83 +0,0 @@
@export_category("Stagger")
@export var horizontal_offset: float = 6.5 # Horizontal distance between projectiles
@export var stagger_offset: float = 5 # Time delay per projectile index
@export var firing_angle: float = 0.0 # Angle in degrees (0 = straight up, positive = angled right)
@export var num_groups: int = 1 # Number of symmetrical groups to fire (1 = single direction, 2 = left/right, 3 = left/center/right)
---
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:
# Calculate center index for symmetrical staggering
var center_index = (total_projectiles - 1) / 2.0
if total_projectiles > 0:
for group in range(num_groups):
# Calculate projectile indices for this group
# For 1 group: 0..N-1
# For 2 groups: 0..N/2-1 and N/2..N-1
# For 3 groups: 0..N/3-1 and N/3..2N/3-1 and 2N/3..N-1
var group_start: int
var group_end: int
if num_groups == 1:
group_start = 0
group_end = total_projectiles
elif num_groups == 2:
group_start = 0
group_end = total_projectiles / 2 if total_projectiles % 2 == 0 else (total_projectiles - 1) / 2
elif num_groups == 3:
var third = total_projectiles / 3
group_start = 0
group_end = third if third > 0 else 1
else:
continue # Skip if num_groups > 3
for b in range(group_start, group_end):
var bullet_scene = weapon_data.bullet_scene
var bullet := bullet_scene.instantiate() as Node
get_tree().root.add_child(bullet)
# Calculate index relative to group center for staggering
var group_center: float = (group_start + group_end - 1) / 2.0
var index_from_center: float = b - group_center
# Calculate timing offset for staggered firing
var time_offset: float = abs(index_from_center) * stagger_offset
# Calculate horizontal offset for this bullet (symmetrical within group)
var bullet_horizontal_offset: float = index_from_center * weapon_data.horizontal_offset
# Calculate vertical offset from center point (symmetrical vertical spread within group)
var distance_from_center: float = abs(index_from_center)
var vertical_offset: float = (distance_from_center * weapon_data.origin * -1) / 2
# Calculate final position based on firing angle using polar coordinates
var angle_rad: float = weapon_data.firing_angle * 0.0174533 # Convert degrees to radians
var spread_angle: float = -firing_angle * 0.0174533 # Spread opposite to firing angle
# Calculate position using polar coordinates from player origin
var origin_x: float = weapon_data.origin * 0.5 # Distribute origin horizontally
var origin_y: float = weapon_data.origin
var pos_x: float = player.position.x + origin_x + bullet_horizontal_offset
var pos_y: float = player.position.y + origin_y + vertical_offset
# Apply angular offset
var angle_offset_x: float = -weapon_data.origin * sin(spread_angle)
var angle_offset_y: float = -weapon_data.origin * cos(spread_angle)
bullet.position = Vector2(pos_x + angle_offset_x, pos_y + angle_offset_y)
# 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 shot
player.travel -= weapon_data.spacing

View file

@ -12,14 +12,14 @@ config_version=5
config/name="Facsimile Wing"
run/main_scene="uid://bj4fytc3sy482"
config/features=PackedStringArray("4.6", "Forward Plus")
config/features=PackedStringArray("4.7", "Forward Plus")
config/icon="res://icon.svg"
[display]
window/size/viewport_width=216
window/size/viewport_width=208
window/size/viewport_height=384
window/size/window_width_override=1296
window/size/window_width_override=1248
window/size/window_height_override=2304
window/subwindows/embed_subwindows=false
window/stretch/mode="viewport"
@ -52,6 +52,11 @@ shoot={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
]
}
cycle={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
[physics]

View file

@ -0,0 +1,16 @@
[gd_resource type="Resource" script_class="WeaponShot" format=3 uid="uid://b75ae840k03dy"]
[ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/player_weapons/weapon_stock.tscn" id="1_lcw6o"]
[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://scripts/weapon_shot.gd" id="2_ym48c"]
[resource]
script = ExtResource("2_ym48c")
shot_name = "stock"
bullet_scene = ExtResource("1_lcw6o")
damage = 2
speed = 500
spacing = 25.0
origin = -12
horizontal_offset = 10.0
stagger_offset = 0.35
metadata/_custom_type_script = "uid://7n1itonn35fm"

View file

@ -0,0 +1,18 @@
[gd_resource type="Resource" script_class="WeaponShot" format=3 uid="uid://cck3gmnhu5agc"]
[ext_resource type="PackedScene" uid="uid://clpyd8qfwthk2" path="res://scenes/player_weapons/weapon_spreadshot.tscn" id="1_07hyh"]
[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://scripts/weapon_shot.gd" id="2_syw6j"]
[resource]
script = ExtResource("2_syw6j")
shot_name = "tri"
bullet_scene = ExtResource("1_07hyh")
damage = 3
speed = 450
projectiles = 3
spacing = 30.0
origin = -15
horizontal_offset = 8.5
stagger_offset = 0.2
stagger_animation = true
metadata/_custom_type_script = "uid://7n1itonn35fm"

View file

@ -0,0 +1,18 @@
[gd_resource type="Resource" script_class="WeaponShot" format=3 uid="uid://bhc6aja38vyr"]
[ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/player_weapons/weapon_stock.tscn" id="1_hm46f"]
[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://scripts/weapon_shot.gd" id="2_w7xlm"]
[resource]
script = ExtResource("2_w7xlm")
shot_name = "vanguard"
bullet_scene = ExtResource("1_hm46f")
damage = 5
speed = 500
projectiles = 5
spacing = 30.0
origin = -15
horizontal_offset = 8.25
stagger_offset = 0.5
stagger_animation = true
metadata/_custom_type_script = "uid://7n1itonn35fm"

View file

@ -1,17 +0,0 @@
[gd_resource type="Resource" script_class="WeaponShot" format=3 uid="uid://b75ae840k03dy"]
[ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/player_weapons/weapon_stock.tscn" id="1_by0nb"]
[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://resources/weapon_shot.gd" id="2_by0nb"]
[resource]
script = ExtResource("2_by0nb")
shot_name = "Stock Shot"
bullet_scene = ExtResource("1_by0nb")
speed = 500
projectiles = 5
spacing = 20.0
origin = -25
horizontal_offset = 6.0
stagger_offset = 5.5
rotate_to_velocity = false
metadata/_custom_type_script = "uid://7n1itonn35fm"

View file

@ -1,20 +0,0 @@
class_name WeaponShot extends Resource
@export_category("Info")
@export var shot_name: String
@export var bullet_scene: PackedScene = null
@export_category("Shot Data")
@export var damage: int = 1
@export var speed: int = 135
@export var projectiles: int = 2
@export var spacing: float = 35
@export var origin: int = -23
@export_category("Stagger")
@export var horizontal_offset: float = 6.5 # Horizontal distance between projectiles
@export var stagger_offset: float = 5 # Time delay per projectile index
# Angle in degrees, default is 0
@export var angle: float = 0.0 # Angle at which the bullet should be fired
@export var rotate_to_velocity: bool = true

View file

@ -20,7 +20,7 @@ var ship_displacement: float
var travel: float = 0
func _ready() -> void:
## Set initial start position
position = Vector2(screensize.x / 2, screensize.y - 45)
@ -37,12 +37,16 @@ func _process(delta) -> void:
if is_shooting == true:
shoot_component.shoot()
$%MuzzleFlash.show()
if is_shooting == false:
$%MuzzleFlash.hide()
# Read Movement Component
movement_component.input = input_component.move_dir
movement_component.tick(delta)
# Cycle weapon (testing key)
if input_component.cycle_weapon:
weapon_component.cycle_weapon()

View file

@ -6,8 +6,12 @@
[ext_resource type="Script" uid="uid://dss0dbwr71y6m" path="res://scripts/input_component.gd" id="4_smehm"]
[ext_resource type="Texture2D" uid="uid://b0iavxi8vaxtj" path="res://graphics/ship_thrusters.png" id="5_qlg0r"]
[ext_resource type="Script" uid="uid://c0rikbakpcags" path="res://scripts/movement_component.gd" id="5_ur7pv"]
[ext_resource type="Script" uid="uid://bgd1hwindc2ui" path="res://scripts/shoot_component.gd" id="6_y4r1p"]
[ext_resource type="Script" uid="uid://suynuijl68qp" path="res://scripts/shoot_component.gd" id="6_y4r1p"]
[ext_resource type="Script" uid="uid://ylmao2ndp22y" path="res://scripts/weapon_component.gd" id="7_d2wvv"]
[ext_resource type="Resource" uid="uid://b75ae840k03dy" path="res://resources/player_weapon_resources/stock.tres" id="8_stock"]
[ext_resource type="Resource" uid="uid://bhc6aja38vyr" path="res://resources/player_weapon_resources/vanguard.tres" id="9_ur7pv"]
[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://scripts/weapon_shot.gd" id="10_d2wvv"]
[ext_resource type="Resource" uid="uid://cck3gmnhu5agc" path="res://resources/player_weapon_resources/tri.tres" id="11_3v2ag"]
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
atlas = ExtResource("5_qlg0r")
@ -34,7 +38,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_fjrip")
}],
"loop": true,
"loop": 1,
"name": &"banked",
"speed": 15.0
}, {
@ -45,7 +49,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_ur7pv")
}],
"loop": true,
"loop": 1,
"name": &"fwd",
"speed": 15.0
}]
@ -74,7 +78,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_d2wvv")
}],
"loop": true,
"loop": 1,
"name": &"stock",
"speed": 15.0
}]
@ -90,9 +94,6 @@ size = Vector2(6, 5.75)
[node name="Player" type="Area2D" unique_id=652131079]
script = ExtResource("1_ur7pv")
can_shoot = null
is_shooting = null
muzzle_flash = null
[node name="Ship" type="Sprite2D" parent="." unique_id=1155866924]
unique_name_in_owner = true
@ -148,11 +149,12 @@ metadata/_custom_type_script = "uid://c0rikbakpcags"
[node name="ShootComponent" type="Node" parent="." unique_id=623642425]
unique_name_in_owner = true
script = ExtResource("6_y4r1p")
metadata/_custom_type_script = "uid://bgd1hwindc2ui"
[node name="WeaponComponent" type="Node" parent="." unique_id=1648685183]
unique_name_in_owner = true
script = ExtResource("7_d2wvv")
weapon_data = ExtResource("8_stock")
available_weapons = Array[ExtResource("10_d2wvv")]([ExtResource("8_stock"), ExtResource("11_3v2ag"), ExtResource("9_ur7pv")])
metadata/_custom_type_script = "uid://ylmao2ndp22y"
[connection signal="timeout" from="WeaponCooldown" to="." method="_on_weapon_cooldown_timeout"]

View file

@ -0,0 +1,53 @@
[gd_scene format=3 uid="uid://clpyd8qfwthk2"]
[ext_resource type="Script" uid="uid://c5blhfopjpfny" path="res://scenes/player_weapons/weapon_stock.gd" id="1_nx6aw"]
[ext_resource type="Texture2D" uid="uid://bnpm8b62n1pr5" path="res://graphics/shot_stock_og.png" id="2_s6ult"]
[sub_resource type="AtlasTexture" id="AtlasTexture_5bykt"]
atlas = ExtResource("2_s6ult")
region = Rect2(0, 0, 7, 11)
[sub_resource type="AtlasTexture" id="AtlasTexture_vsqoq"]
atlas = ExtResource("2_s6ult")
region = Rect2(7, 0, 7, 11)
[sub_resource type="AtlasTexture" id="AtlasTexture_yqx5m"]
atlas = ExtResource("2_s6ult")
region = Rect2(14, 0, 7, 11)
[sub_resource type="SpriteFrames" id="SpriteFrames_fdubj"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_5bykt")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_vsqoq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_yqx5m")
}],
"loop": 1,
"name": &"default",
"speed": 24.0
}]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mvdrj"]
size = Vector2(6.666667, 14)
[node name="StockWeapon" type="Area2D" unique_id=1832200900]
script = ExtResource("1_nx6aw")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1831184252]
scale = Vector2(1.5, 1.5)
sprite_frames = SubResource("SpriteFrames_fdubj")
autoplay = "default"
frame_progress = 0.35886022
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1890946059]
shape = SubResource("RectangleShape2D_mvdrj")
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="." unique_id=985862716]
rect = Rect2(-3, -7, 6, 14)
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]

View file

@ -1,6 +1,8 @@
extends Area2D
@onready var shot_data = load("res://resources/player_weapon_resources/weapon_shot_stock.tres")
# Data to be set externally when this bullet is instantiated
var bullet_scene: PackedScene = null
var shot_data: WeaponShot = null
# Time offset when this bullet was fired (relative to other bullets in the same shot)
var time_offset: float = 0.5
@ -11,12 +13,6 @@ var fire_time: float = 0.0
# Track if this bullet is currently active in the shot
var is_active: bool = false
# Angle at which this bullet should fire (in degrees)
var angle: float = 0.0
# Whether to rotate bullet to face its movement direction
var rotate_to_velocity: bool = true
func _process(delta):
var current_time = Time.get_ticks_msec() / 1000.0
@ -24,31 +20,42 @@ func _process(delta):
if !is_active and current_time >= fire_time:
activate()
# Calculate the movement vector based on speed, angle, and delta
var angle_rad = deg_to_rad(angle)
var move_x = cos(angle_rad) * shot_data.speed * delta
var move_y = sin(angle_rad) * shot_data.speed * delta
# Move the bullet
position.x += move_x
position.y += move_y
# Rotate to face movement direction - ensure proper rotation calculation
if rotate_to_velocity:
var velocity = Vector2(cos(angle_rad) * shot_data.speed, sin(angle_rad) * shot_data.speed)
rotation = velocity.angle()
# Debug output - this will show you what's really happening
print("Bullet angle: ", angle, "Velocity angle:", velocity.angle(), "Rotation set to:", rotation)
position.y -= shot_data.speed * delta
func activate():
is_active = true
visible = true
# # Emit signal for hit detection
# emit_signal("activate")
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()
# Set fire_time for the next shot (staggered firing)
var current_time = Time.get_ticks_msec() / 1000.0
fire_time = current_time + shot_data.stagger_offset
# Function to set the bullet data (called from parent scene)
func set_weapon_data(bullet_scene_param: PackedScene, shot_data_param: WeaponShot):
bullet_scene = bullet_scene_param
shot_data = shot_data_param
# Function to offset animation playback for staggered visual effect
func set_animation_offset(offset: float) -> void:
var sprite = $AnimatedSprite2D
if sprite:
var frames = sprite.sprite_frames
if frames:
var animation = sprite.animation
var frame_count = frames.get_frame_count(animation)
if frame_count > 0:
# Calculate average frame duration from actual frame timings
var total_duration = 0.0
for i in range(frame_count):
total_duration += frames.get_frame_duration(animation, i)
var avg_frame_duration = total_duration / frame_count
# Convert time offset to frame offset, wrap within animation length
var frame_offset = fposmod(offset / avg_frame_duration, float(frame_count))
sprite.frame = int(frame_offset)

View file

@ -27,7 +27,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_yqx5m")
}],
"loop": true,
"loop": 1,
"name": &"default",
"speed": 24.0
}]

View file

@ -1,54 +0,0 @@
extends Area2D
@onready var shot_data = load("res://resources/player_weapon_resources/weapon_shot_stock.tres")
# Time offset when this bullet was fired (relative to other bullets in the same shot)
var time_offset: float = 0.5
# When this bullet should fire (absolute time)
var fire_time: float = 0.0
# Track if this bullet is currently active in the shot
var is_active: bool = false
# Angle at which this bullet should fire (in degrees)
var angle: float = 0.0
# Whether to rotate bullet to face its movement direction
var rotate_to_velocity: bool = true
func _process(delta):
var current_time = Time.get_ticks_msec() / 1000.0
# Fire if it's time and bullet isn't already active
if !is_active and current_time >= fire_time:
activate()
# Calculate the movement vector based on speed, angle, and delta
var angle_rad = deg_to_rad(angle)
var move_x = cos(angle_rad) * shot_data.speed * delta
var move_y = sin(angle_rad) * shot_data.speed * delta
# Move the bullet
position.x += move_x
position.y += move_y
# Rotate to face movement direction - ensure proper rotation calculation
if rotate_to_velocity:
var velocity = Vector2(cos(angle_rad) * shot_data.speed, sin(angle_rad) * shot_data.speed)
rotation = velocity.angle()
# Debug output - this will show you what's really happening
print("Bullet angle: ", angle, "Velocity angle:", velocity.angle(), "Rotation set to:", rotation)
func activate():
is_active = true
visible = true
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()
# Set fire_time for the next shot (staggered firing)
var current_time = Time.get_ticks_msec() / 1000.0
fire_time = current_time + shot_data.stagger_offset

View file

@ -1 +0,0 @@
uid://7wuopfptd3qe

View file

@ -1,54 +0,0 @@
extends Area2D
@onready var shot_data = load("res://resources/player_weapon_resources/weapon_shot_stock.tres")
# Time offset when this bullet was fired (relative to other bullets in the same shot)
var time_offset: float = 0.5
# When this bullet should fire (absolute time)
var fire_time: float = 0.0
# Track if this bullet is currently active in the shot
var is_active: bool = false
# Angle at which this bullet should fire (in degrees)
var angle: float = 0.0
# Whether to rotate bullet to face its movement direction
var rotate_to_velocity: bool = true
func _process(delta):
var current_time = Time.get_ticks_msec() / 1000.0
# Fire if it's time and bullet isn't already active
if !is_active and current_time >= fire_time:
activate()
# Calculate the movement vector based on speed, angle, and delta
var angle_rad = deg_to_rad(angle)
var move_x = cos(angle_rad) * shot_data.speed * delta
var move_y = sin(angle_rad) * shot_data.speed * delta
# Move the bullet
position.x += move_x
position.y += move_y
# Rotate to face movement direction - ensure proper rotation calculation
if rotate_to_velocity:
var velocity = Vector2(cos(angle_rad) * shot_data.speed, sin(angle_rad) * shot_data.speed)
rotation = velocity.angle()
# Debug output - this will show you what's really happening
print("Bullet angle: ", angle, "Velocity angle:", velocity.angle(), "Rotation set to:", rotation)
func activate():
is_active = true
visible = true
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()
# Set fire_time for the next shot (staggered firing)
var current_time = Time.get_ticks_msec() / 1000.0
fire_time = current_time + shot_data.stagger_offset

View file

@ -1 +0,0 @@
uid://c1u6yrjkp26i5

View file

@ -14,7 +14,7 @@
z_index = -1
[node name="BaseBackground" type="ColorRect" parent="Level/Background" unique_id=1360709800]
offset_right = 217.0
offset_right = 208.0
offset_bottom = 410.0
color = Color(0.2899925, 0.5692833, 0.9110645, 1)
@ -32,7 +32,7 @@ hframes = 4
frame = 1
[node name="CloudRight" type="Sprite2D" parent="Level/Background/Back" unique_id=1729409543]
position = Vector2(177, 32)
position = Vector2(168, 32)
texture = ExtResource("3_4wyf3")
flip_h = true
hframes = 4
@ -52,7 +52,7 @@ hframes = 4
frame = 2
[node name="CloudRight" type="Sprite2D" parent="Level/Background/Mid" unique_id=702118355]
position = Vector2(177, 32)
position = Vector2(168, 32)
texture = ExtResource("3_4wyf3")
flip_h = true
hframes = 4
@ -71,7 +71,7 @@ hframes = 4
frame = 3
[node name="CloudRight" type="Sprite2D" parent="Level/Background/Fore" unique_id=1798342457]
position = Vector2(185, 32)
position = Vector2(176, 32)
texture = ExtResource("3_4wyf3")
flip_h = true
hframes = 4

View file

@ -3,9 +3,12 @@ class_name InputComponent extends Node
var move_dir: Vector2 = Vector2.ZERO
var shoot_pressed: bool = false
var shooting: bool = false
var cycle_weapon: bool = false
func update() -> void:
move_dir = Input.get_vector("left", "right", "up", "down")
shoot_pressed = Input.is_action_just_pressed("shoot")
shooting = Input.is_action_pressed("shoot")
# Development Keys
cycle_weapon = Input.is_action_just_pressed("cycle")

View file

@ -17,7 +17,7 @@ func tick(delta: float):
if player == null: return
# Shorten variable for accessing weapon_component for clarity
var weapon_system = weapon_component.data
var weapon_system = weapon_component.weapon_data
# Calculate ship to bullet displacement
player.ship_displacement = player.position.y - player.previous_position.y

View file

@ -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,8 +15,7 @@ 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 Node2D
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)
@ -35,33 +31,19 @@ func shoot():
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 fixed vertical offset from weapon origin
bullet.position = player.position + Vector2(bullet_horizontal_offset, weapon_data.origin)
# Final position combines symmetrical horizontal spread with symmetrical vertical spacing
bullet.position = player.position + Vector2(bullet_horizontal_offset, weapon_data.origin + (vertical_offset + weapon_data.origin - total_projectiles))
# Set timing properties on the bullet
bullet.time_offset = time_offset
bullet.fire_time = current_time + time_offset
# Set bullet rotation properties
bullet.rotate_to_velocity = weapon_data.rotate_to_velocity # This should be true if you want rotation
# Set the angle for bullets - symmetrical spread around vertical (straight up = -90°)
if weapon_data.angle == 0:
# If angle is 0, all projectiles fire straight up
bullet.angle = -90.0
else:
# Set angle for bullets - symmetrical spread around vertical (straight up = -90°)
if index_from_center == 0:
# Center projectile fires straight up
bullet.angle = -90.0
else:
# Left projectiles: positive angle (up and to the left), Right projectiles: negative angle (up and to the right)
bullet.angle = -90.0 + weapon_data.angle * sign(index_from_center)
# Set the bullet data
bullet.set_weapon_data(weapon_data.bullet_scene, weapon_data)
# Offset animation playback per projectile if enabled
if weapon_data.stagger_animation:
bullet.set_animation_offset(index_from_center * weapon_data.stagger_offset)
# Subtract projectile spacing from current Player travel for next shot
player.travel -= weapon_data.spacing

View file

@ -1 +1 @@
uid://bgd1hwindc2ui
uid://suynuijl68qp

View file

@ -1,9 +1,41 @@
class_name WeaponComponent extends Node
@export var loaded_weapon: PackedScene = load("res://scenes/player_weapons/weapon_stock.tscn")
var data : WeaponShot = load("res://resources/player_weapon_resources/weapon_shot_stock.tres")
@export var weapon_data: WeaponShot = null
@export var available_weapons: Array[WeaponShot] = []
var _current_weapon_index: int = 0
func _ready() -> void:
# Set the default weapon to be stock, i.e. index 1
if weapon_data and not available_weapons.is_empty():
for i in range(available_weapons.size()):
if available_weapons[i] == weapon_data:
_current_weapon_index = i
return
func get_bullet_scene() -> PackedScene:
return data.weapon_shot # Reference to the Shot scene from the resource
return weapon_data.bullet_scene if weapon_data else null
func get_weapon_resource() -> Resource:
return weapon_data
func select_weapon_by_name(name: String) -> bool:
for i in range(available_weapons.size()):
if available_weapons[i].shot_name == name:
_current_weapon_index = i
weapon_data = available_weapons[i]
print("Switched to: ", name)
return true
return false
func cycle_weapon() -> void: # Used for testing weapon cycling
if available_weapons.is_empty():
return
_current_weapon_index = (_current_weapon_index + 1) % available_weapons.size()
weapon_data = available_weapons[_current_weapon_index]
print("Switched to: ", weapon_data.shot_name)

23
scripts/weapon_shot.gd Normal file
View file

@ -0,0 +1,23 @@
class_name WeaponShot
extends Resource
@export_category("Parameters")
@export var shot_name: String
@export var bullet_scene: PackedScene = null
@export var damage: int = 1
@export var speed: int = 135
@export var projectiles: int = 2
# Vertical spacing between projectiles
@export var spacing: float = 35
# Origin offset from center of player
@export var origin: int = -23
@export_category("Spread")
# Horizontal distance between projectiles
@export var horizontal_offset: float = 6.5
# Time delay per projectile index
@export var stagger_offset: float = 0.25
@export_category("Effects")
# Offset animation playback per projectile index
@export var stagger_animation: bool = false

View file

@ -1,25 +0,0 @@
extends Area2D
# Simple test to verify rotation behavior
var test_angle: float = 0.0
var rotate_to_velocity: bool = true
func _process(delta):
# Move in a straight line at 100 pixels per second
var move_x = cos(deg_to_rad(test_angle)) * 100 * delta
var move_y = sin(deg_to_rad(test_angle)) * 100 * delta
position.x += move_x
position.y += move_y
# Rotate to face movement direction (this is the key fix)
if rotate_to_velocity:
var velocity = Vector2(cos(deg_to_rad(test_angle)) * 100, sin(deg_to_rad(test_angle)) * 100)
rotation = velocity.angle()
# Debug output
print("Test angle: ", test_angle, "Velocity angle:", velocity.angle(), "Rotation set to:", rotation)
func _ready():
# Set initial rotation for testing
test_angle = 0.0

View file

@ -1 +0,0 @@
uid://b1bhb673ef5po

View file

@ -1,6 +0,0 @@
[gd_scene format=3 uid="uid://d4ls4srw6qyap"]
[ext_resource type="Script" uid="uid://d1rwqotmrag1r" path="res://test_rotation.gd" id="1_kx6bj"]
[node name="TestRotation" type="Area2D" unique_id=1832200900]
script = ExtResource("1_kx6bj")