From dd9eaf6ec699de6b224db8cdddd60743c89f872a Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 15 Jun 2026 12:52:27 +0100 Subject: [PATCH 01/37] Reduced standard shot colour intensity. --- scenes/weapon_stock.gd | 4 ++-- scenes/weapon_stock.tscn | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scenes/weapon_stock.gd b/scenes/weapon_stock.gd index d0e1cd6..7ebe31a 100644 --- a/scenes/weapon_stock.gd +++ b/scenes/weapon_stock.gd @@ -29,8 +29,8 @@ func activate(): is_active = true visible = true - # Emit signal for hit detection - emit_signal("activate") + # # Emit signal for hit detection + # emit_signal("activate") func _on_visible_on_screen_notifier_2d_screen_exited(): queue_free() diff --git a/scenes/weapon_stock.tscn b/scenes/weapon_stock.tscn index e4e7dd6..de22a81 100644 --- a/scenes/weapon_stock.tscn +++ b/scenes/weapon_stock.tscn @@ -1,7 +1,7 @@ [gd_scene format=3 uid="uid://ddpclu2vdy2ve"] [ext_resource type="Script" uid="uid://c5blhfopjpfny" path="res://scenes/weapon_stock.gd" id="1_u1d5o"] -[ext_resource type="Texture2D" uid="uid://dolmy8bnc8kkt" path="res://graphics/shot_stock.png" id="2_u1d5o"] +[ext_resource type="Texture2D" uid="uid://bnpm8b62n1pr5" path="res://graphics/shot_stock_og.png" id="2_u1d5o"] [sub_resource type="AtlasTexture" id="AtlasTexture_5bykt"] atlas = ExtResource("2_u1d5o") From 0bcb386a0f25a2e86b4837d2c6f6667c31d612a8 Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 15 Jun 2026 12:53:16 +0100 Subject: [PATCH 02/37] Reduced standard shot colour intensity. --- graphics/shot_stock_og.png | Bin 0 -> 296 bytes graphics/shot_stock_og.png.import | 40 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 graphics/shot_stock_og.png create mode 100644 graphics/shot_stock_og.png.import diff --git a/graphics/shot_stock_og.png b/graphics/shot_stock_og.png new file mode 100644 index 0000000000000000000000000000000000000000..b0c0fe0af87d8e550d68e7a821f257ea002ab951 GIT binary patch literal 296 zcmeAS@N?(olHy`uVBq!ia0vp^qCm{e!3-pqi< Date: Tue, 16 Jun 2026 17:38:48 +0100 Subject: [PATCH 03/37] Updated directory structure for clarity. Updated game resolution 208x384 --- project.godot | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project.godot b/project.godot index 43ed708..da358b6 100644 --- a/project.godot +++ b/project.godot @@ -17,9 +17,9 @@ 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" From d04153171690df9f0a28cbb30a637108b3b1e7bf Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 16 Jun 2026 17:39:18 +0100 Subject: [PATCH 04/37] Updated resource paths to match directory structure. --- Deprecated/stock_weapon.gd | 4 ++-- .../weapon_shot.gd | 2 +- .../weapon_shot.gd.uid | 0 .../weapon_shot_stock.tres | 4 ++-- scenes/{ => player_weapons}/weapon_stock.gd | 4 ++-- scenes/{ => player_weapons}/weapon_stock.gd.uid | 0 scenes/{ => player_weapons}/weapon_stock.tscn | 2 +- scenes/world.tscn | 8 ++++---- scripts/weapon_component.gd | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) rename resources/{player_weapons => player_weapon_resources}/weapon_shot.gd (94%) rename resources/{player_weapons => player_weapon_resources}/weapon_shot.gd.uid (100%) rename resources/{player_weapons => player_weapon_resources}/weapon_shot_stock.tres (79%) rename scenes/{ => player_weapons}/weapon_stock.gd (83%) rename scenes/{ => player_weapons}/weapon_stock.gd.uid (100%) rename scenes/{ => player_weapons}/weapon_stock.tscn (96%) diff --git a/Deprecated/stock_weapon.gd b/Deprecated/stock_weapon.gd index 71537c4..6f3c4dd 100644 --- a/Deprecated/stock_weapon.gd +++ b/Deprecated/stock_weapon.gd @@ -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): diff --git a/resources/player_weapons/weapon_shot.gd b/resources/player_weapon_resources/weapon_shot.gd similarity index 94% rename from resources/player_weapons/weapon_shot.gd rename to resources/player_weapon_resources/weapon_shot.gd index 63adff0..e8e4317 100644 --- a/resources/player_weapons/weapon_shot.gd +++ b/resources/player_weapon_resources/weapon_shot.gd @@ -12,6 +12,6 @@ extends Resource @export var spacing: float = 35 @export var origin: int = -23 -@export_category("Stagger") +@export_category("Spread") @export var horizontal_offset: float = 6.5 # Horizontal distance between projectiles @export var stagger_offset: float = 5 # Time delay per projectile index diff --git a/resources/player_weapons/weapon_shot.gd.uid b/resources/player_weapon_resources/weapon_shot.gd.uid similarity index 100% rename from resources/player_weapons/weapon_shot.gd.uid rename to resources/player_weapon_resources/weapon_shot.gd.uid diff --git a/resources/player_weapons/weapon_shot_stock.tres b/resources/player_weapon_resources/weapon_shot_stock.tres similarity index 79% rename from resources/player_weapons/weapon_shot_stock.tres rename to resources/player_weapon_resources/weapon_shot_stock.tres index e4cf1ca..6139dca 100644 --- a/resources/player_weapons/weapon_shot_stock.tres +++ b/resources/player_weapon_resources/weapon_shot_stock.tres @@ -1,7 +1,7 @@ [gd_resource type="Resource" script_class="WeaponShot" format=3 uid="uid://b75ae840k03dy"] -[ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/weapon_stock.tscn" id="1_by0nb"] -[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://resources/player_weapons/weapon_shot.gd" id="2_by0nb"] +[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/player_weapon_resources/weapon_shot.gd" id="2_by0nb"] [resource] script = ExtResource("2_by0nb") diff --git a/scenes/weapon_stock.gd b/scenes/player_weapons/weapon_stock.gd similarity index 83% rename from scenes/weapon_stock.gd rename to scenes/player_weapons/weapon_stock.gd index 7ebe31a..3de04e9 100644 --- a/scenes/weapon_stock.gd +++ b/scenes/player_weapons/weapon_stock.gd @@ -1,8 +1,8 @@ extends Area2D -@onready var bullet: PackedScene = load("res://scenes/weapon_stock.tscn") -@onready var shot_data: = load("res://resources/player_weapons/weapon_shot_stock.tres") +@onready var bullet: PackedScene = load("res://scenes/player_weapons/weapon_stock.tscn") +@onready var shot_data: = load("res://resources/player_weapon_resources/weapon_shot_stock.tres") diff --git a/scenes/weapon_stock.gd.uid b/scenes/player_weapons/weapon_stock.gd.uid similarity index 100% rename from scenes/weapon_stock.gd.uid rename to scenes/player_weapons/weapon_stock.gd.uid diff --git a/scenes/weapon_stock.tscn b/scenes/player_weapons/weapon_stock.tscn similarity index 96% rename from scenes/weapon_stock.tscn rename to scenes/player_weapons/weapon_stock.tscn index de22a81..364ec6a 100644 --- a/scenes/weapon_stock.tscn +++ b/scenes/player_weapons/weapon_stock.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://ddpclu2vdy2ve"] -[ext_resource type="Script" uid="uid://c5blhfopjpfny" path="res://scenes/weapon_stock.gd" id="1_u1d5o"] +[ext_resource type="Script" uid="uid://c5blhfopjpfny" path="res://scenes/player_weapons/weapon_stock.gd" id="1_u1d5o"] [ext_resource type="Texture2D" uid="uid://bnpm8b62n1pr5" path="res://graphics/shot_stock_og.png" id="2_u1d5o"] [sub_resource type="AtlasTexture" id="AtlasTexture_5bykt"] diff --git a/scenes/world.tscn b/scenes/world.tscn index 50bf2a4..9148110 100644 --- a/scenes/world.tscn +++ b/scenes/world.tscn @@ -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 diff --git a/scripts/weapon_component.gd b/scripts/weapon_component.gd index a4bb65b..0a9a9cd 100644 --- a/scripts/weapon_component.gd +++ b/scripts/weapon_component.gd @@ -1,7 +1,7 @@ class_name WeaponComponent extends Node -@export var loaded_weapon: PackedScene = load("res://scenes/weapon_stock.tscn") -var data : WeaponShot = load("res://resources/player_weapons/weapon_shot_stock.tres") +@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") From e2cf516c90c55c69a079f212c86c7a19cb02a51c Mon Sep 17 00:00:00 2001 From: henry Date: Wed, 17 Jun 2026 02:55:40 +0100 Subject: [PATCH 05/37] Refactored weapon component to handle weapon swaping. --- scenes/player.tscn | 2 +- scenes/player_weapons/weapon_stock.gd | 13 ++++++----- scripts/input_component.gd | 4 ++++ scripts/shoot_component.gd | 5 ++++- scripts/shoot_component.gd.uid | 2 +- scripts/weapon_component.gd | 31 ++++++++++++++++++++++++--- 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/scenes/player.tscn b/scenes/player.tscn index 4b33f53..e60f549 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -6,7 +6,7 @@ [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"] [sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"] diff --git a/scenes/player_weapons/weapon_stock.gd b/scenes/player_weapons/weapon_stock.gd index 3de04e9..55fd8e7 100644 --- a/scenes/player_weapons/weapon_stock.gd +++ b/scenes/player_weapons/weapon_stock.gd @@ -1,10 +1,8 @@ extends Area2D - -@onready var bullet: PackedScene = load("res://scenes/player_weapons/weapon_stock.tscn") -@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 @@ -38,3 +36,8 @@ func _on_visible_on_screen_notifier_2d_screen_exited(): # 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 diff --git a/scripts/input_component.gd b/scripts/input_component.gd index ce71e8d..83131e6 100644 --- a/scripts/input_component.gd +++ b/scripts/input_component.gd @@ -9,3 +9,7 @@ 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 Available Weapons diff --git a/scripts/shoot_component.gd b/scripts/shoot_component.gd index 3f1ee7d..b3bd5b3 100644 --- a/scripts/shoot_component.gd +++ b/scripts/shoot_component.gd @@ -19,7 +19,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 Node + var bullet := bullet_scene.instantiate() as Area2D get_tree().root.add_child(bullet) # Calculate index relative to center (0 = center, -1/+1 = first from center) @@ -42,5 +42,8 @@ func shoot(): bullet.time_offset = time_offset bullet.fire_time = current_time + time_offset + # Set the bullet data (this is what was missing) + bullet.set_weapon_data(weapon_data.bullet_scene, weapon_data) + # Subtract projectile spacing from current Player travel for next shot player.travel -= weapon_data.spacing diff --git a/scripts/shoot_component.gd.uid b/scripts/shoot_component.gd.uid index 4e59bd1..fdd16b5 100644 --- a/scripts/shoot_component.gd.uid +++ b/scripts/shoot_component.gd.uid @@ -1 +1 @@ -uid://bgd1hwindc2ui +uid://suynuijl68qp diff --git a/scripts/weapon_component.gd b/scripts/weapon_component.gd index 0a9a9cd..e88e83b 100644 --- a/scripts/weapon_component.gd +++ b/scripts/weapon_component.gd @@ -1,9 +1,34 @@ 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") +enum WeaponType { + STOCK, + NONE, +} +@export_enum("STOCK", "NONE") var loaded_weapon: int = WeaponType.STOCK +var data: WeaponShot = load("res://resources/player_weapon_resources/weapon_shot_stock.tres") func get_bullet_scene() -> PackedScene: - return data.weapon_shot # Reference to the Shot scene from the resource + if loaded_weapon == WeaponType.STOCK: + return preload("res://scenes/player_weapons/weapon_stock.tscn") + else: + return null + +func get_weapon_resource() -> Resource: + var weapon_resource_path: String + + if loaded_weapon == WeaponType.STOCK: + weapon_resource_path = "res://resources/player_weapon_resources/weapon_shot_stock.tres" + data = load(weapon_resource_path) + return data + else: + return null + + +#var data : WeaponShot = load("res://resources/player_weapon_resources/weapon_shot_stock.tres") + + + +#func get_bullet_scene() -> PackedScene: + #return data.weapon_shot # Reference to the Shot scene from the resource From 63ed0aae3adac61c4a5ad5be6c5276fc3ae964d3 Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 20 Jun 2026 13:03:48 +0100 Subject: [PATCH 06/37] Updated input component and player component handling to use tab to cycle weapons. --- project.godot | 7 ++++++- scenes/player.gd | 12 ++++++++---- scenes/player.tscn | 15 ++++++++------- scripts/input_component.gd | 5 ++--- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/project.godot b/project.godot index da358b6..8a275f5 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ 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] @@ -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] diff --git a/scenes/player.gd b/scenes/player.gd index 6439eb4..f61a309 100644 --- a/scenes/player.gd +++ b/scenes/player.gd @@ -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() diff --git a/scenes/player.tscn b/scenes/player.tscn index e60f549..c8b82bf 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -8,6 +8,9 @@ [ext_resource type="Script" uid="uid://c0rikbakpcags" path="res://scripts/movement_component.gd" id="5_ur7pv"] [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/weapon_shot_stock.tres" id="8_stock"] +[ext_resource type="Resource" uid="uid://bhc6aja38vyr" path="res://resources/player_weapon_resources/weapon_shot_spread.tres" id="9_ur7pv"] +[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://resources/player_weapon_resources/weapon_shot.gd" id="10_d2wvv"] [sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"] atlas = ExtResource("5_qlg0r") @@ -34,7 +37,7 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_fjrip") }], -"loop": true, +"loop": 1, "name": &"banked", "speed": 15.0 }, { @@ -45,7 +48,7 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_ur7pv") }], -"loop": true, +"loop": 1, "name": &"fwd", "speed": 15.0 }] @@ -74,7 +77,7 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_d2wvv") }], -"loop": true, +"loop": 1, "name": &"stock", "speed": 15.0 }] @@ -90,9 +93,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 +148,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("9_ur7pv") +available_weapons = Array[ExtResource("10_d2wvv")]([ExtResource("8_stock"), ExtResource("9_ur7pv")]) metadata/_custom_type_script = "uid://ylmao2ndp22y" [connection signal="timeout" from="WeaponCooldown" to="." method="_on_weapon_cooldown_timeout"] diff --git a/scripts/input_component.gd b/scripts/input_component.gd index 83131e6..f182984 100644 --- a/scripts/input_component.gd +++ b/scripts/input_component.gd @@ -3,13 +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 Available Weapons + cycle_weapon = Input.is_action_just_pressed("cycle") From cf172bc546e20f42a237decd3f60a8667b4f7fa1 Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 20 Jun 2026 13:05:18 +0100 Subject: [PATCH 07/37] Updated architecture so WeaponComponent uses an exported array to store weapon resources. --- .../player_weapon_resources/weapon_shot.gd | 2 +- .../weapon_shot_spread.tres | 17 ++++++ scenes/player_weapons/weapon_spreadshot.tscn | 53 +++++++++++++++++++ scenes/player_weapons/weapon_stock.tscn | 2 +- scripts/movement_component.gd | 2 +- scripts/shoot_component.gd | 12 ++--- scripts/weapon_component.gd | 36 ++++--------- 7 files changed, 88 insertions(+), 36 deletions(-) create mode 100644 resources/player_weapon_resources/weapon_shot_spread.tres create mode 100644 scenes/player_weapons/weapon_spreadshot.tscn diff --git a/resources/player_weapon_resources/weapon_shot.gd b/resources/player_weapon_resources/weapon_shot.gd index e8e4317..70c167a 100644 --- a/resources/player_weapon_resources/weapon_shot.gd +++ b/resources/player_weapon_resources/weapon_shot.gd @@ -14,4 +14,4 @@ extends Resource @export_category("Spread") @export var horizontal_offset: float = 6.5 # Horizontal distance between projectiles -@export var stagger_offset: float = 5 # Time delay per projectile index +@export var stagger_offset: float = 0.1 # Time delay per projectile index diff --git a/resources/player_weapon_resources/weapon_shot_spread.tres b/resources/player_weapon_resources/weapon_shot_spread.tres new file mode 100644 index 0000000..2bcbdce --- /dev/null +++ b/resources/player_weapon_resources/weapon_shot_spread.tres @@ -0,0 +1,17 @@ +[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_bullet"] +[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://resources/player_weapon_resources/weapon_shot.gd" id="2_script"] + +[resource] +script = ExtResource("2_script") +shot_name = "Spread Shot" +bullet_scene = ExtResource("1_bullet") +damage = 1 +speed = 450 +projectiles = 5 +spacing = 30.0 +origin = -15 +horizontal_offset = 10.0 +stagger_offset = 0.2 +metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/scenes/player_weapons/weapon_spreadshot.tscn b/scenes/player_weapons/weapon_spreadshot.tscn new file mode 100644 index 0000000..2158693 --- /dev/null +++ b/scenes/player_weapons/weapon_spreadshot.tscn @@ -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"] diff --git a/scenes/player_weapons/weapon_stock.tscn b/scenes/player_weapons/weapon_stock.tscn index 364ec6a..5eddb30 100644 --- a/scenes/player_weapons/weapon_stock.tscn +++ b/scenes/player_weapons/weapon_stock.tscn @@ -27,7 +27,7 @@ animations = [{ "duration": 1.0, "texture": SubResource("AtlasTexture_yqx5m") }], -"loop": true, +"loop": 1, "name": &"default", "speed": 24.0 }] diff --git a/scripts/movement_component.gd b/scripts/movement_component.gd index 18ebdb2..0539438 100644 --- a/scripts/movement_component.gd +++ b/scripts/movement_component.gd @@ -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 diff --git a/scripts/shoot_component.gd b/scripts/shoot_component.gd index b3bd5b3..9fa5479 100644 --- a/scripts/shoot_component.gd +++ b/scripts/shoot_component.gd @@ -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 diff --git a/scripts/weapon_component.gd b/scripts/weapon_component.gd index e88e83b..f443855 100644 --- a/scripts/weapon_component.gd +++ b/scripts/weapon_component.gd @@ -1,34 +1,20 @@ class_name WeaponComponent extends Node -enum WeaponType { - STOCK, - NONE, -} +@export var weapon_data: WeaponShot = null +@export var available_weapons: Array[WeaponShot] = [] -@export_enum("STOCK", "NONE") var loaded_weapon: int = WeaponType.STOCK - -var data: WeaponShot = load("res://resources/player_weapon_resources/weapon_shot_stock.tres") +var _current_weapon_index: int = 0 func get_bullet_scene() -> PackedScene: - if loaded_weapon == WeaponType.STOCK: - return preload("res://scenes/player_weapons/weapon_stock.tscn") - else: - return null + return weapon_data.bullet_scene if weapon_data else null func get_weapon_resource() -> Resource: - var weapon_resource_path: String + return weapon_data - if loaded_weapon == WeaponType.STOCK: - weapon_resource_path = "res://resources/player_weapon_resources/weapon_shot_stock.tres" - data = load(weapon_resource_path) - return data - else: - return null +func cycle_weapon() -> void: + if available_weapons.is_empty(): + return - -#var data : WeaponShot = load("res://resources/player_weapon_resources/weapon_shot_stock.tres") - - - -#func get_bullet_scene() -> PackedScene: - #return data.weapon_shot # Reference to the Shot scene from the resource + _current_weapon_index = (_current_weapon_index + 1) % available_weapons.size() + weapon_data = available_weapons[_current_weapon_index] + print("Switched to: ", weapon_data.shot_name) From d0664a87fab48b692ff9a01561344298db8e63b0 Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 20 Jun 2026 14:47:46 +0100 Subject: [PATCH 08/37] Update weapon resources, default weapon loaded; implemented call weapon by name. --- .../{weapon_shot_stock.tres => stock.tres} | 14 +++++------ resources/player_weapon_resources/tri.tres | 17 ++++++++++++++ .../player_weapon_resources/vanguard.tres | 17 ++++++++++++++ .../weapon_shot_spread.tres | 17 -------------- scenes/player.tscn | 11 +++++---- scripts/weapon_component.gd | 23 ++++++++++++++++++- .../weapon_shot.gd | 0 .../weapon_shot.gd.uid | 0 8 files changed, 69 insertions(+), 30 deletions(-) rename resources/player_weapon_resources/{weapon_shot_stock.tres => stock.tres} (56%) create mode 100644 resources/player_weapon_resources/tri.tres create mode 100644 resources/player_weapon_resources/vanguard.tres delete mode 100644 resources/player_weapon_resources/weapon_shot_spread.tres rename {resources/player_weapon_resources => scripts}/weapon_shot.gd (100%) rename {resources/player_weapon_resources => scripts}/weapon_shot.gd.uid (100%) diff --git a/resources/player_weapon_resources/weapon_shot_stock.tres b/resources/player_weapon_resources/stock.tres similarity index 56% rename from resources/player_weapon_resources/weapon_shot_stock.tres rename to resources/player_weapon_resources/stock.tres index 6139dca..4cd7aae 100644 --- a/resources/player_weapon_resources/weapon_shot_stock.tres +++ b/resources/player_weapon_resources/stock.tres @@ -1,16 +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_by0nb"] -[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://resources/player_weapon_resources/weapon_shot.gd" id="2_by0nb"] +[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_by0nb") -shot_name = "Stock Shot" -bullet_scene = ExtResource("1_by0nb") +script = ExtResource("2_ym48c") +shot_name = "stock" +bullet_scene = ExtResource("1_lcw6o") +damage = 2 speed = 500 -projectiles = 3 spacing = 25.0 origin = -12 -horizontal_offset = 8.0 +horizontal_offset = 7.5 stagger_offset = 0.35 metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/resources/player_weapon_resources/tri.tres b/resources/player_weapon_resources/tri.tres new file mode 100644 index 0000000..eed118e --- /dev/null +++ b/resources/player_weapon_resources/tri.tres @@ -0,0 +1,17 @@ +[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 = "vanguard" +bullet_scene = ExtResource("1_07hyh") +damage = 3 +speed = 450 +projectiles = 3 +spacing = 30.0 +origin = -15 +horizontal_offset = 8.5 +stagger_offset = 0.2 +metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/resources/player_weapon_resources/vanguard.tres b/resources/player_weapon_resources/vanguard.tres new file mode 100644 index 0000000..72941e4 --- /dev/null +++ b/resources/player_weapon_resources/vanguard.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" script_class="WeaponShot" format=3 uid="uid://bhc6aja38vyr"] + +[ext_resource type="PackedScene" uid="uid://clpyd8qfwthk2" path="res://scenes/player_weapons/weapon_spreadshot.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.5 +stagger_offset = 0.2 +metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/resources/player_weapon_resources/weapon_shot_spread.tres b/resources/player_weapon_resources/weapon_shot_spread.tres deleted file mode 100644 index 2bcbdce..0000000 --- a/resources/player_weapon_resources/weapon_shot_spread.tres +++ /dev/null @@ -1,17 +0,0 @@ -[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_bullet"] -[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://resources/player_weapon_resources/weapon_shot.gd" id="2_script"] - -[resource] -script = ExtResource("2_script") -shot_name = "Spread Shot" -bullet_scene = ExtResource("1_bullet") -damage = 1 -speed = 450 -projectiles = 5 -spacing = 30.0 -origin = -15 -horizontal_offset = 10.0 -stagger_offset = 0.2 -metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/scenes/player.tscn b/scenes/player.tscn index c8b82bf..b78146a 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -8,9 +8,10 @@ [ext_resource type="Script" uid="uid://c0rikbakpcags" path="res://scripts/movement_component.gd" id="5_ur7pv"] [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/weapon_shot_stock.tres" id="8_stock"] -[ext_resource type="Resource" uid="uid://bhc6aja38vyr" path="res://resources/player_weapon_resources/weapon_shot_spread.tres" id="9_ur7pv"] -[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://resources/player_weapon_resources/weapon_shot.gd" id="10_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") @@ -152,8 +153,8 @@ script = ExtResource("6_y4r1p") [node name="WeaponComponent" type="Node" parent="." unique_id=1648685183] unique_name_in_owner = true script = ExtResource("7_d2wvv") -weapon_data = ExtResource("9_ur7pv") -available_weapons = Array[ExtResource("10_d2wvv")]([ExtResource("8_stock"), ExtResource("9_ur7pv")]) +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"] diff --git a/scripts/weapon_component.gd b/scripts/weapon_component.gd index f443855..41ecc74 100644 --- a/scripts/weapon_component.gd +++ b/scripts/weapon_component.gd @@ -5,13 +5,34 @@ class_name WeaponComponent extends Node 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 weapon_data.bullet_scene if weapon_data else null func get_weapon_resource() -> Resource: return weapon_data -func cycle_weapon() -> void: +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 diff --git a/resources/player_weapon_resources/weapon_shot.gd b/scripts/weapon_shot.gd similarity index 100% rename from resources/player_weapon_resources/weapon_shot.gd rename to scripts/weapon_shot.gd diff --git a/resources/player_weapon_resources/weapon_shot.gd.uid b/scripts/weapon_shot.gd.uid similarity index 100% rename from resources/player_weapon_resources/weapon_shot.gd.uid rename to scripts/weapon_shot.gd.uid From 2c2b23f0bb9fb84235029aa40137b3c675b4b8e8 Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 20 Jun 2026 15:13:28 +0100 Subject: [PATCH 09/37] Cleaned up resource defaults and names; path references. --- resources/player_weapon_resources/stock.tres | 2 +- resources/player_weapon_resources/tri.tres | 2 +- resources/player_weapon_resources/vanguard.tres | 4 ++-- scripts/shoot_component.gd | 1 + scripts/weapon_shot.gd | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/resources/player_weapon_resources/stock.tres b/resources/player_weapon_resources/stock.tres index 4cd7aae..0d2906f 100644 --- a/resources/player_weapon_resources/stock.tres +++ b/resources/player_weapon_resources/stock.tres @@ -11,6 +11,6 @@ damage = 2 speed = 500 spacing = 25.0 origin = -12 -horizontal_offset = 7.5 +horizontal_offset = 10.0 stagger_offset = 0.35 metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/resources/player_weapon_resources/tri.tres b/resources/player_weapon_resources/tri.tres index eed118e..d8f0033 100644 --- a/resources/player_weapon_resources/tri.tres +++ b/resources/player_weapon_resources/tri.tres @@ -5,7 +5,7 @@ [resource] script = ExtResource("2_syw6j") -shot_name = "vanguard" +shot_name = "tri" bullet_scene = ExtResource("1_07hyh") damage = 3 speed = 450 diff --git a/resources/player_weapon_resources/vanguard.tres b/resources/player_weapon_resources/vanguard.tres index 72941e4..a5f36a9 100644 --- a/resources/player_weapon_resources/vanguard.tres +++ b/resources/player_weapon_resources/vanguard.tres @@ -12,6 +12,6 @@ speed = 500 projectiles = 5 spacing = 30.0 origin = -15 -horizontal_offset = 8.5 -stagger_offset = 0.2 +horizontal_offset = 8.25 +stagger_offset = 0.5 metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/scripts/shoot_component.gd b/scripts/shoot_component.gd index 9fa5479..8a2e703 100644 --- a/scripts/shoot_component.gd +++ b/scripts/shoot_component.gd @@ -26,6 +26,7 @@ func shoot(): # Calculate horizontal offset for this bullet (symmetrical: left=-ve, right=+ve) var bullet_horizontal_offset: float = index_from_center * weapon_data.horizontal_offset + print("horizontal_offset: ", weapon_data.horizontal_offset, " index: ", index_from_center, " result: ", bullet_horizontal_offset) # Calculate vertical offset from center point (symmetrical vertical spread) var distance_from_center: float = abs(index_from_center) diff --git a/scripts/weapon_shot.gd b/scripts/weapon_shot.gd index 70c167a..7a3a6ee 100644 --- a/scripts/weapon_shot.gd +++ b/scripts/weapon_shot.gd @@ -14,4 +14,4 @@ extends Resource @export_category("Spread") @export var horizontal_offset: float = 6.5 # Horizontal distance between projectiles -@export var stagger_offset: float = 0.1 # Time delay per projectile index +@export var stagger_offset: float = 0.25 # Time delay per projectile index From 6c41810add506469efcf1f252f5d980dca8d675d Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 20 Jun 2026 16:08:40 +0100 Subject: [PATCH 10/37] Additional resource tweaks. --- resources/player_weapon_resources/tri.tres | 1 + .../player_weapon_resources/vanguard.tres | 3 ++- scenes/player_weapons/weapon_stock.gd | 18 ++++++++++++++++++ scripts/shoot_component.gd | 5 ++++- scripts/weapon_shot.gd | 16 +++++++++++----- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/resources/player_weapon_resources/tri.tres b/resources/player_weapon_resources/tri.tres index d8f0033..0b63301 100644 --- a/resources/player_weapon_resources/tri.tres +++ b/resources/player_weapon_resources/tri.tres @@ -14,4 +14,5 @@ spacing = 30.0 origin = -15 horizontal_offset = 8.5 stagger_offset = 0.2 +stagger_animation = true metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/resources/player_weapon_resources/vanguard.tres b/resources/player_weapon_resources/vanguard.tres index a5f36a9..dcb3580 100644 --- a/resources/player_weapon_resources/vanguard.tres +++ b/resources/player_weapon_resources/vanguard.tres @@ -1,6 +1,6 @@ [gd_resource type="Resource" script_class="WeaponShot" format=3 uid="uid://bhc6aja38vyr"] -[ext_resource type="PackedScene" uid="uid://clpyd8qfwthk2" path="res://scenes/player_weapons/weapon_spreadshot.tscn" id="1_hm46f"] +[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] @@ -14,4 +14,5 @@ spacing = 30.0 origin = -15 horizontal_offset = 8.25 stagger_offset = 0.5 +stagger_animation = true metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/scenes/player_weapons/weapon_stock.gd b/scenes/player_weapons/weapon_stock.gd index 55fd8e7..d1f5198 100644 --- a/scenes/player_weapons/weapon_stock.gd +++ b/scenes/player_weapons/weapon_stock.gd @@ -41,3 +41,21 @@ func _on_visible_on_screen_notifier_2d_screen_exited(): 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) diff --git a/scripts/shoot_component.gd b/scripts/shoot_component.gd index 8a2e703..eb6a2a9 100644 --- a/scripts/shoot_component.gd +++ b/scripts/shoot_component.gd @@ -26,7 +26,6 @@ func shoot(): # Calculate horizontal offset for this bullet (symmetrical: left=-ve, right=+ve) var bullet_horizontal_offset: float = index_from_center * weapon_data.horizontal_offset - print("horizontal_offset: ", weapon_data.horizontal_offset, " index: ", index_from_center, " result: ", bullet_horizontal_offset) # Calculate vertical offset from center point (symmetrical vertical spread) var distance_from_center: float = abs(index_from_center) @@ -42,5 +41,9 @@ func shoot(): # 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 diff --git a/scripts/weapon_shot.gd b/scripts/weapon_shot.gd index 7a3a6ee..c535924 100644 --- a/scripts/weapon_shot.gd +++ b/scripts/weapon_shot.gd @@ -1,17 +1,23 @@ class_name WeaponShot extends Resource -@export_category("Info") +@export_category("Parameters") @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 +# Vertical spacing between projectiles @export var spacing: float = 35 +# Origin offset from center of player @export var origin: int = -23 @export_category("Spread") -@export var horizontal_offset: float = 6.5 # Horizontal distance between projectiles -@export var stagger_offset: float = 0.25 # Time delay per projectile index +# 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 From a6d137bf7a91e9dc61ab769aaca73420fbfce4e2 Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 21 Jun 2026 11:31:44 +0100 Subject: [PATCH 11/37] Setup for adding Notification Component. --- scenes/world.tscn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scenes/world.tscn b/scenes/world.tscn index 9148110..ef39be3 100644 --- a/scenes/world.tscn +++ b/scenes/world.tscn @@ -6,9 +6,9 @@ [node name="World" type="Node2D" unique_id=1317852169] -[node name="Level" type="Node2D" parent="." unique_id=934289771] +[node name="UI" parent="." unique_id=480295610 instance=ExtResource("1_nnsk1")] -[node name="UI" parent="Level" unique_id=480295610 instance=ExtResource("1_nnsk1")] +[node name="Level" type="Node2D" parent="." unique_id=934289771] [node name="Background" type="Node2D" parent="Level" unique_id=485120278] z_index = -1 From 18dc548dd66f11f2d45488c5f43cfa94fcd47966 Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 21 Jun 2026 17:55:47 +0100 Subject: [PATCH 12/37] Implemented basic notification system for weapons changing. --- graphics/stock.png | Bin 0 -> 256 bytes graphics/stock.png.import | 40 +++++++++ graphics/tri.png | Bin 0 -> 271 bytes graphics/tri.png.import | 40 +++++++++ graphics/vanguard.png | Bin 0 -> 254 bytes graphics/vanguard.png.import | 40 +++++++++ project.godot | 4 + resources/player_weapon_resources/stock.tres | 2 +- scenes/notification_display.tscn | 42 +++++++++ scenes/world.tscn | 6 ++ scripts/event_bus.gd | 3 +- scripts/notification_display.gd | 89 +++++++++++++++++++ scripts/notification_display.gd.uid | 1 + scripts/notification_manager.gd | 23 +++++ scripts/notification_manager.gd.uid | 1 + scripts/weapon_component.gd | 11 +++ 16 files changed, 300 insertions(+), 2 deletions(-) create mode 100644 graphics/stock.png create mode 100644 graphics/stock.png.import create mode 100644 graphics/tri.png create mode 100644 graphics/tri.png.import create mode 100644 graphics/vanguard.png create mode 100644 graphics/vanguard.png.import create mode 100644 scenes/notification_display.tscn create mode 100644 scripts/notification_display.gd create mode 100644 scripts/notification_display.gd.uid create mode 100644 scripts/notification_manager.gd create mode 100644 scripts/notification_manager.gd.uid diff --git a/graphics/stock.png b/graphics/stock.png new file mode 100644 index 0000000000000000000000000000000000000000..bec290680a0d9fac2b080caeb52c4df33eefac3a GIT binary patch literal 256 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1IggaDrqS0JsV zVB)G_lV)kyA7*{OQ0?Y|w0DPR{r+S&^JzfVJ_GY9dES}&LEb7xHkS7GB?bvi(RmM( zXaA2s`{eZPKmY&#pS^Z_OI>?rR#s$KP?=NL8Y82d;mOylclA&A>dH6xoxJBf&<=%? zAirP+plWIEF|}O-^uO=DES*;_52-P=t8~W0KR#gE|clOPKbtGU!Kh V9-Jajy&kBV!PC{xWt~$(696a0Z7u)+ literal 0 HcmV?d00001 diff --git a/graphics/stock.png.import b/graphics/stock.png.import new file mode 100644 index 0000000..0f7e7f0 --- /dev/null +++ b/graphics/stock.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dtggedl0127vk" +path="res://.godot/imported/stock.png-0cb798b4967b33f195d444f0ce113e61.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://graphics/stock.png" +dest_files=["res://.godot/imported/stock.png-0cb798b4967b33f195d444f0ce113e61.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/graphics/tri.png b/graphics/tri.png new file mode 100644 index 0000000000000000000000000000000000000000..a2464416cc665260e348c2c5510fd41e6c8dd1c7 GIT binary patch literal 271 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1IggaDrqS0JsV zVB)G_lV)kyA7*{OQ0?Y|w0DPR{r+S&^JzfVJ_GY9dES}&LEb7xHkS7GB?bvi(RmM( zXaA2s`{eZPKmY&#pS^Z_OI>?rR#s$KP?=NL8Y82d;mOylclA&A>dH6xoxJBf&<=%? zAirP+plW1n0W%CLPSCxLPXRKF-&aXXfR-I=~ZA0V|ZxA lrV{SVD)6t#N|u*_;bb;<;1}(u3xS#$JYD@<);T3K0RU-8a8v*Q literal 0 HcmV?d00001 diff --git a/graphics/tri.png.import b/graphics/tri.png.import new file mode 100644 index 0000000..75a75d6 --- /dev/null +++ b/graphics/tri.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cne450xyao5xl" +path="res://.godot/imported/tri.png-6a3868cfc07d960f5a88b231524dc08e.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://graphics/tri.png" +dest_files=["res://.godot/imported/tri.png-6a3868cfc07d960f5a88b231524dc08e.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/graphics/vanguard.png b/graphics/vanguard.png new file mode 100644 index 0000000000000000000000000000000000000000..610b89d5f641f77eb6493fa5956e50a22415a5e4 GIT binary patch literal 254 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1IggaDrqS0JsV zVB)G_lV)kyA7*{OQ0?Y|w0DPR{r+S&^JzfVJ_GY9dES}&LEb7xHkS7GB?bvi(RmM( zXaA2s`{eZPKmY&#pS^Z_OI>?rR#s$KP?=NL8Y82d;mOylclA&A>dH6xoxJBf&<=%? zAirP+plW void: + label.add_theme_font_size_override("font_size", 8) + label.text = weapon_name + + # Auto-load icon from graphics folder matching the weapon name + var icon_path = "res://graphics/" + weapon_name.to_lower() + ".png" + if ResourceLoader.exists(icon_path): + icon.texture = load(icon_path) + else: + icon.texture = null + + _player = player_node + _player.tree_exiting.connect(queue_free) + _sprite_size = player_sprite_size + _origin_offset = origin_offset + _follow_player = true + + # Wait one frame for layout to resolve shrink-to-fit widths + await get_tree().process_frame + + # Use container's natural width, but fix height at 16px + size = Vector2(_container.size.x, 16.0) + + # Position using origin offset for Y, to the right of player for X + _update_position() + modulate.a = 1.0 + + # Fade out and free + var tween = create_tween() + tween.tween_property(self, "modulate:a", 0.0, 2.0) + tween.tween_callback(_on_fade_complete) + + +func _process(_delta: float) -> void: + if _follow_player and _player: + _update_position() + + +func _update_position() -> void: + if _player == null: + return + + var player_pos = _player.position + + # Y position uses the weapon origin offset from player center + var notif_y = player_pos.y + _origin_offset - (size.y / 2.0) + + # X position is 10px to the right of player's sprite edge + var right_edge = player_pos.x + (_sprite_size.x / 2.0) + var notif_x = right_edge + 10.0 + + var is_flipped = false + + # Clamp to screen bounds — flip to left if it would go off-screen right + var viewport_size = get_viewport_rect().size + if notif_x + size.x > viewport_size.x: + is_flipped = true + var left_edge = player_pos.x - (_sprite_size.x / 2.0) + notif_x = left_edge - 10.0 - size.x + + # Swap icon/label order so the icon is always closest to the player + if is_flipped: + _container.move_child(label, 0) + _container.move_child(icon, 1) + else: + _container.move_child(icon, 0) + _container.move_child(label, 1) + + # Final clamp: ensure the entire notification is within screen bounds + notif_x = clamp(notif_x, 0, viewport_size.x - size.x) + notif_y = clamp(notif_y, 0, viewport_size.y - size.y) + + position = Vector2(notif_x, notif_y) + + +func _on_fade_complete() -> void: + _follow_player = false + queue_free() diff --git a/scripts/notification_display.gd.uid b/scripts/notification_display.gd.uid new file mode 100644 index 0000000..3dfcfa6 --- /dev/null +++ b/scripts/notification_display.gd.uid @@ -0,0 +1 @@ +uid://3a0cypjsx5cq diff --git a/scripts/notification_manager.gd b/scripts/notification_manager.gd new file mode 100644 index 0000000..eb8028e --- /dev/null +++ b/scripts/notification_manager.gd @@ -0,0 +1,23 @@ +class_name NotificationManager extends Node + +@export var notification_scene: PackedScene + +var _active_notification: NotificationDisplay = null + +func _ready() -> void: + EventBus.weapon_changed.connect(_on_weapon_changed) + + +func _on_weapon_changed(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: float) -> void: + if notification_scene == null: + return + + # Free any existing notification so the new one can fade in cleanly + if _active_notification: + _active_notification.queue_free() + _active_notification = null + + var notification = notification_scene.instantiate() + add_child(notification) + _active_notification = notification + notification.show_notification(weapon_name, player_node, player_sprite_size, origin_offset) diff --git a/scripts/notification_manager.gd.uid b/scripts/notification_manager.gd.uid new file mode 100644 index 0000000..9d13c9e --- /dev/null +++ b/scripts/notification_manager.gd.uid @@ -0,0 +1 @@ +uid://boce4kgerpff2 diff --git a/scripts/weapon_component.gd b/scripts/weapon_component.gd index 41ecc74..37dc306 100644 --- a/scripts/weapon_component.gd +++ b/scripts/weapon_component.gd @@ -15,6 +15,13 @@ func _ready() -> void: return +func _emit_weapon_changed() -> void: + var ship: Sprite2D = get_parent().get_node("Ship") + var sprite_size = ship.get_rect().size + var origin_offset = weapon_data.origin if weapon_data else 0.0 + EventBus.weapon_changed.emit(weapon_data.shot_name, get_parent(), sprite_size, origin_offset) + + func get_bullet_scene() -> PackedScene: return weapon_data.bullet_scene if weapon_data else null @@ -27,6 +34,8 @@ func select_weapon_by_name(name: String) -> bool: _current_weapon_index = i weapon_data = available_weapons[i] print("Switched to: ", name) + + _emit_weapon_changed() return true return false @@ -39,3 +48,5 @@ func cycle_weapon() -> void: # Used for testing weapon cycling _current_weapon_index = (_current_weapon_index + 1) % available_weapons.size() weapon_data = available_weapons[_current_weapon_index] print("Switched to: ", weapon_data.shot_name) + + _emit_weapon_changed() From 64d55572c209315899ab628fbc8247555628d2f6 Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 22 Jun 2026 00:38:37 +0100 Subject: [PATCH 13/37] Slight visual updates. --- graphics/stock.png | Bin 256 -> 256 bytes graphics/tri.png | Bin 271 -> 271 bytes graphics/vanguard.png | Bin 254 -> 254 bytes scenes/notification_display.tscn | 5 +---- 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/graphics/stock.png b/graphics/stock.png index bec290680a0d9fac2b080caeb52c4df33eefac3a..2ffd2efc43a0998cf64f5c7858bfc01b677199cc 100644 GIT binary patch delta 54 zcmZo*YG9ghQGbF1GtUhc7gtx+2O`Wf7?Ye<9@J@gSi-cAm4V+yY~vfgucZt?;OXk; Jvd$@?2>|r05*Gjf delta 54 zcmZo*YG9ghQ9r?jndb(Ji>s^TLlNc~j7d%_59%~LEMeNm%Ag<3d2otA^?C*%@O1Ta JS?83{1OVnR5rhB$ diff --git a/graphics/tri.png b/graphics/tri.png index a2464416cc665260e348c2c5510fd41e6c8dd1c7..13ac5255d5424469a96182dc3c30867bc1945eaa 100644 GIT binary patch delta 33 ncmeBY>Svm8k!ga%#LF5YKP1IUZ(W(|%K!wPu6{1-oD!M<*J=zL delta 33 ncmeBY>Svm8ktxAt;$;nyliA#XU$mbtWB>wBS3j3^P6XbIMcoMw%se|-TwFbc1w>nwlvp3wa4ee6AjQBC#3=SW#$ula0}yz+`njxg HN@xNAuuTs$ delta 52 zcmeyz_>XbIMco7!W}Y1^F0P)!0-~)-N~{lTI2KK3kYZpc3gn1f%Cuu60}yz+`njxg HN@xNAu9^>V diff --git a/scenes/notification_display.tscn b/scenes/notification_display.tscn index 32ef4d6..982c58f 100644 --- a/scenes/notification_display.tscn +++ b/scenes/notification_display.tscn @@ -12,9 +12,6 @@ label = NodePath("HBoxContainer/Label") [node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=228546504] layout_mode = 0 -separation = 4 -theme_override_constants/margin_left = 4 -theme_override_constants/margin_right = 4 [node name="Icon" type="TextureRect" parent="HBoxContainer" unique_id=3] custom_minimum_size = Vector2(16, 16) @@ -39,4 +36,4 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -color = Color(0.13333334, 0.1254902, 0.20392157, 1) +color = Color(0.4117647, 0.4117647, 0.41568628, 1) From f69862af8cb846d193e9b4611b6a68850b7b50c5 Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 22 Jun 2026 01:19:49 +0100 Subject: [PATCH 14/37] Added animation to notification display. --- scripts/notification_display.gd | 45 +++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/scripts/notification_display.gd b/scripts/notification_display.gd index 17fa3ff..8e5a713 100644 --- a/scripts/notification_display.gd +++ b/scripts/notification_display.gd @@ -32,14 +32,42 @@ func show_notification(weapon_name: String, player_node: Node2D, player_sprite_s # Use container's natural width, but fix height at 16px size = Vector2(_container.size.x, 16.0) - # Position using origin offset for Y, to the right of player for X + # Calculate target position _update_position() - modulate.a = 1.0 + var target_pos = position - # Fade out and free - var tween = create_tween() - tween.tween_property(self, "modulate:a", 0.0, 2.0) - tween.tween_callback(_on_fade_complete) + # Start 10px above destination, fully transparent + position.y = target_pos.y - 10.0 + modulate.a = 0.0 + + # Pause following during fade-in so the tween isn't overridden by _process + _follow_player = false + + # Fade in and slide into position with overshoot + var tween = create_tween().set_parallel() + tween.tween_property(self, "modulate:a", 1.0, 0.3) + var move_tween = tween.tween_property(self, "position:y", target_pos.y, 0.3) + move_tween.set_trans(Tween.TRANS_ELASTIC).set_ease(Tween.EASE_OUT) + + # Wait for fade-in to finish, then resume following + await tween.finished + _follow_player = true + + # Stay fully visible for a moment before fading + await get_tree().create_timer(0.35).timeout + + # Record current position as the fade-out starting point + await get_tree().process_frame + var fade_start_y = position.y + + # Fade out and drift downward with steady acceleration + _follow_player = false + var fade_out = create_tween().set_parallel() + fade_out.tween_property(self, "modulate:a", 0.0, .35) + var drift = fade_out.tween_property(self, "position:y", fade_start_y + 7, .3) + drift.set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_IN) + await fade_out.finished + queue_free() func _process(_delta: float) -> void: @@ -82,8 +110,3 @@ func _update_position() -> void: notif_y = clamp(notif_y, 0, viewport_size.y - size.y) position = Vector2(notif_x, notif_y) - - -func _on_fade_complete() -> void: - _follow_player = false - queue_free() From 68d0cf95808ff67c4ef1216f35be7b9efb2c41b4 Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 22 Jun 2026 01:24:56 +0100 Subject: [PATCH 15/37] Temporarily disabled notifications from following the player. --- scripts/notification_display.gd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/notification_display.gd b/scripts/notification_display.gd index 8e5a713..645601f 100644 --- a/scripts/notification_display.gd +++ b/scripts/notification_display.gd @@ -24,7 +24,7 @@ func show_notification(weapon_name: String, player_node: Node2D, player_sprite_s _player.tree_exiting.connect(queue_free) _sprite_size = player_sprite_size _origin_offset = origin_offset - _follow_player = true + _follow_player = false # Disable movement for testing # Wait one frame for layout to resolve shrink-to-fit widths await get_tree().process_frame @@ -51,10 +51,10 @@ func show_notification(weapon_name: String, player_node: Node2D, player_sprite_s # Wait for fade-in to finish, then resume following await tween.finished - _follow_player = true + # _follow_player = true # Stay fully visible for a moment before fading - await get_tree().create_timer(0.35).timeout + await get_tree().create_timer(0.25).timeout # Record current position as the fade-out starting point await get_tree().process_frame From ae34cb934adbb2e63211765862f7e892aa01c46f Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 22 Jun 2026 12:58:25 +0100 Subject: [PATCH 16/37] Added segment lines to notification display. --- scripts/notification_display.gd | 50 +++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/scripts/notification_display.gd b/scripts/notification_display.gd index 645601f..e310866 100644 --- a/scripts/notification_display.gd +++ b/scripts/notification_display.gd @@ -9,6 +9,10 @@ var _sprite_size: Vector2 = Vector2.ZERO var _origin_offset: float = 0.0 var _follow_player: bool = false +var _connector_line: Line2D = null +var _connector_visible: bool = false + + func show_notification(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: float) -> void: label.add_theme_font_size_override("font_size", 8) label.text = weapon_name @@ -51,10 +55,17 @@ func show_notification(weapon_name: String, player_node: Node2D, player_sprite_s # Wait for fade-in to finish, then resume following await tween.finished - # _follow_player = true + _follow_player = true + + # Create connector line from notification to player origin + _connector_line = Line2D.new() + _connector_line.default_color = Color.WHITE + _connector_line.width = 1.0 + add_child(_connector_line) + _connector_visible = true # Stay fully visible for a moment before fading - await get_tree().create_timer(0.25).timeout + await get_tree().create_timer(0.5).timeout # Record current position as the fade-out starting point await get_tree().process_frame @@ -73,6 +84,8 @@ func show_notification(weapon_name: String, player_node: Node2D, player_sprite_s func _process(_delta: float) -> void: if _follow_player and _player: _update_position() + if _connector_visible and _player: + _update_connector() func _update_position() -> void: @@ -110,3 +123,36 @@ func _update_position() -> void: notif_y = clamp(notif_y, 0, viewport_size.y - size.y) position = Vector2(notif_x, notif_y) + + +func _update_connector() -> void: + if _connector_line == null or _player == null: + return + + # Icon position in the notification's local space + var icon_pos = _container.position + icon.position + var icon_mid_y = icon_pos.y + icon.size.y / 2.0 + + # Point 0: edge of the container closest to the icon, at icon's vertical midpoint + var point0: Vector2 + var direction: float + + if _container.get_child(0) == icon: + # Icon on the left (not flipped) — container's left edge, line goes left toward player + point0 = Vector2(_container.position.x, icon_mid_y) + direction = -1.0 + else: + # Icon on the right (flipped) — container's right edge, line goes right toward player + point0 = Vector2(_container.position.x + _container.size.x, icon_mid_y) + direction = 1.0 + + # Point 1: 8px straight from point 0 toward the player + const SEGMENT_ORIGIN: float = 8.0 # length of initial segment from origin + var point1 = Vector2(point0.x + SEGMENT_ORIGIN * direction, icon_mid_y) + + # Point 2: player's origin + ENDPOINT_OFFSET, converted to notification's local space + const ENDPOINT_OFFSET = Vector2(4, 7) # offset from player's origin to connector endpoint + var target = _player.position + Vector2(+ENDPOINT_OFFSET.x, _origin_offset + ENDPOINT_OFFSET.y) + var point2 = target - position + + _connector_line.points = PackedVector2Array([point0, point1, point2]) From 8e821ead28c2dd5c08d0e2ad12bb389d959a312f Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 22 Jun 2026 22:26:52 +0100 Subject: [PATCH 17/37] Slight tweak to connector rendering. --- scripts/notification_display.gd | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/notification_display.gd b/scripts/notification_display.gd index e310866..2150af8 100644 --- a/scripts/notification_display.gd +++ b/scripts/notification_display.gd @@ -44,12 +44,20 @@ func show_notification(weapon_name: String, player_node: Node2D, player_sprite_s position.y = target_pos.y - 10.0 modulate.a = 0.0 + # Create connector line immediately so it fades in with the notification + _connector_line = Line2D.new() + _connector_line.default_color = Color(1.0, 1.0, 1.0, 0.0) + _connector_line.width = 1.0 + add_child(_connector_line) + _connector_visible = true + # Pause following during fade-in so the tween isn't overridden by _process _follow_player = false - # Fade in and slide into position with overshoot + # Fade in notification and connector together, slide into position with overshoot var tween = create_tween().set_parallel() tween.tween_property(self, "modulate:a", 1.0, 0.3) + tween.tween_property(_connector_line, "default_color:a", 1.0, 0.3) var move_tween = tween.tween_property(self, "position:y", target_pos.y, 0.3) move_tween.set_trans(Tween.TRANS_ELASTIC).set_ease(Tween.EASE_OUT) @@ -57,13 +65,6 @@ func show_notification(weapon_name: String, player_node: Node2D, player_sprite_s await tween.finished _follow_player = true - # Create connector line from notification to player origin - _connector_line = Line2D.new() - _connector_line.default_color = Color.WHITE - _connector_line.width = 1.0 - add_child(_connector_line) - _connector_visible = true - # Stay fully visible for a moment before fading await get_tree().create_timer(0.5).timeout From 1200ac7e32df80b8ef06c6ff0b21ab0db56b46e7 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 23 Jun 2026 18:19:28 +0100 Subject: [PATCH 18/37] Initial scaffolding. --- .../player_weapon_resources/vanguard.tres | 2 +- scenes/EffectComponent.tscn | 6 +++++ scenes/effects/flash_effect.gd | 27 +++++++++++++++++++ scenes/effects/flash_effect.gd.uid | 1 + scripts/base_effect.gd | 16 +++++++++++ scripts/base_effect.gd.uid | 1 + scripts/effects_component.gd | 25 +++++++++++++++++ scripts/effects_component.gd.uid | 1 + 8 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 scenes/EffectComponent.tscn create mode 100644 scenes/effects/flash_effect.gd create mode 100644 scenes/effects/flash_effect.gd.uid create mode 100644 scripts/base_effect.gd create mode 100644 scripts/base_effect.gd.uid create mode 100644 scripts/effects_component.gd create mode 100644 scripts/effects_component.gd.uid diff --git a/resources/player_weapon_resources/vanguard.tres b/resources/player_weapon_resources/vanguard.tres index dcb3580..61f7a1c 100644 --- a/resources/player_weapon_resources/vanguard.tres +++ b/resources/player_weapon_resources/vanguard.tres @@ -8,7 +8,7 @@ script = ExtResource("2_w7xlm") shot_name = "vanguard" bullet_scene = ExtResource("1_hm46f") damage = 5 -speed = 500 +speed = 550 projectiles = 5 spacing = 30.0 origin = -15 diff --git a/scenes/EffectComponent.tscn b/scenes/EffectComponent.tscn new file mode 100644 index 0000000..bfd716f --- /dev/null +++ b/scenes/EffectComponent.tscn @@ -0,0 +1,6 @@ +[gd_scene format=3 uid="uid://bq3xhbfgkt22l"] + +[ext_resource type="Script" uid="uid://65d3hbrpm21x" path="res://scripts/effects_component.gd" id="1_ee0kt"] + +[node name="EffectsComponent" type="Node2D" unique_id=1393438576] +script = ExtResource("1_ee0kt") diff --git a/scenes/effects/flash_effect.gd b/scenes/effects/flash_effect.gd new file mode 100644 index 0000000..db8fb26 --- /dev/null +++ b/scenes/effects/flash_effect.gd @@ -0,0 +1,27 @@ +class_name FlashEffect +extends BaseEffect + +@export var flash_color: Color = Color.WHITE +@export var flash_speed: float = 10.0 + +var _timer: float = 0.0 +var _original_material: Material + +func start(target: Node) -> void: + _timer = 0.0 + if target is CanvasItem: + _original_material = target.material + # Apply a ShaderMaterial that handles the flash + var flash_material = ShaderMaterial.new() + flash_material.shader = preload("res://shaders/flash.gdshader") + target.material = flash_material + +func process(delta: float, target: Node) -> void: + _timer += delta + if target.material is ShaderMaterial: + var intensity = (sin(_timer * flash_speed) + 1.0) / 2.0 + target.material.set_shader_parameter("flash_intensity", intensity) + +func stop(target: Node) -> void: + if target is CanvasItem: + target.material = _original_material diff --git a/scenes/effects/flash_effect.gd.uid b/scenes/effects/flash_effect.gd.uid new file mode 100644 index 0000000..79af5c6 --- /dev/null +++ b/scenes/effects/flash_effect.gd.uid @@ -0,0 +1 @@ +uid://deak7vcr7ss5l diff --git a/scripts/base_effect.gd b/scripts/base_effect.gd new file mode 100644 index 0000000..e871e76 --- /dev/null +++ b/scripts/base_effect.gd @@ -0,0 +1,16 @@ +class_name BaseEffect +extends Resource + +@export var duration: float = 0.5 + +# Called when the effect is applied +func start(target: Node) -> void: + pass + +# Called every frame (if needed) +func process(delta: float) -> void: + pass + +# Clean up any changes to the target +func stop(target: Node) -> void: + pass diff --git a/scripts/base_effect.gd.uid b/scripts/base_effect.gd.uid new file mode 100644 index 0000000..221b0c2 --- /dev/null +++ b/scripts/base_effect.gd.uid @@ -0,0 +1 @@ +uid://cs7xpxd1vpl56 diff --git a/scripts/effects_component.gd b/scripts/effects_component.gd new file mode 100644 index 0000000..c5e5308 --- /dev/null +++ b/scripts/effects_component.gd @@ -0,0 +1,25 @@ +class_name EffectComponent +extends Node2D + +@export var target_node: Node + +var active_effects: Array[BaseEffect] = [] + +func _process(delta: float) -> void: + # Process all active effects backwards so we can safely remove finished ones + for i in range(active_effects.size() - 1, -1, -1): + var effect = active_effects[i] + effect.process(delta, target_node) + + # Example: simple time-based expiration + effect.duration -= delta + if effect.duration <= 0.0: + remove_effect(effect) + +func apply_effect(effect: BaseEffect) -> void: + effect.start(target_node) + active_effects.append(effect) + +func remove_effect(effect: BaseEffect) -> void: + effect.stop(target_node) + active_effects.erase(effect) diff --git a/scripts/effects_component.gd.uid b/scripts/effects_component.gd.uid new file mode 100644 index 0000000..16a022f --- /dev/null +++ b/scripts/effects_component.gd.uid @@ -0,0 +1 @@ +uid://65d3hbrpm21x From b4c4a66ce817884bd284abf19a621a52dcbf5189 Mon Sep 17 00:00:00 2001 From: henry Date: Wed, 24 Jun 2026 14:48:02 +0100 Subject: [PATCH 19/37] Added effects manager and two effects to test attached to the player scene. --- resources/effects/flash_weapon_change.tres | 8 ++ resources/effects/invincibility_blink.tres | 13 +++ scenes/EffectComponent.tscn | 4 +- scenes/effects/flash_effect.gd | 27 ----- scenes/player.gd | 5 + scenes/player.tscn | 10 ++ scenes/world.tscn | 5 + scripts/{ => effects}/base_effect.gd | 12 +- scripts/{ => effects}/base_effect.gd.uid | 0 scripts/effects/blinker_effect.gd | 90 +++++++++++++++ scripts/effects/blinker_effect.gd.uid | 1 + scripts/{ => effects}/effects_component.gd | 25 +++-- .../{ => effects}/effects_component.gd.uid | 0 scripts/effects/flash_effect.gd | 105 ++++++++++++++++++ .../effects/flash_effect.gd.uid | 0 scripts/movement_component.gd | 2 + scripts/weapon_component.gd | 10 ++ shaders/flash.gdshader | 44 ++++++++ shaders/flash.gdshader.uid | 1 + 19 files changed, 322 insertions(+), 40 deletions(-) create mode 100644 resources/effects/flash_weapon_change.tres create mode 100644 resources/effects/invincibility_blink.tres delete mode 100644 scenes/effects/flash_effect.gd rename scripts/{ => effects}/base_effect.gd (53%) rename scripts/{ => effects}/base_effect.gd.uid (100%) create mode 100644 scripts/effects/blinker_effect.gd create mode 100644 scripts/effects/blinker_effect.gd.uid rename scripts/{ => effects}/effects_component.gd (51%) rename scripts/{ => effects}/effects_component.gd.uid (100%) create mode 100644 scripts/effects/flash_effect.gd rename {scenes => scripts}/effects/flash_effect.gd.uid (100%) create mode 100644 shaders/flash.gdshader create mode 100644 shaders/flash.gdshader.uid diff --git a/resources/effects/flash_weapon_change.tres b/resources/effects/flash_weapon_change.tres new file mode 100644 index 0000000..d8bd944 --- /dev/null +++ b/resources/effects/flash_weapon_change.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="FlashEffect" format=3 uid="uid://c86rdr6gtto66"] + +[ext_resource type="Shader" uid="uid://dp4svqyxg1dum" path="res://shaders/flash.gdshader" id="1_37i75"] +[ext_resource type="Script" uid="uid://deak7vcr7ss5l" path="res://scripts/effects/flash_effect.gd" id="2_y51sa"] + +[resource] +script = ExtResource("2_y51sa") +metadata/_custom_type_script = "uid://deak7vcr7ss5l" diff --git a/resources/effects/invincibility_blink.tres b/resources/effects/invincibility_blink.tres new file mode 100644 index 0000000..40fac80 --- /dev/null +++ b/resources/effects/invincibility_blink.tres @@ -0,0 +1,13 @@ +[gd_resource type="Resource" script_class="BlinkerEffect" format=3 uid="uid://bld2k7san214b"] + +[ext_resource type="Script" uid="uid://cj4grtaun2h5a" path="res://scripts/effects/blinker_effect.gd" id="1_blink"] + +[resource] +script = ExtResource("1_blink") +blink_frequency = 12.0 +blink_length = 0.2 +min_alpha = 0.1 +start_ease = 0.1 +start_ease_mode = 0 +end_ease_mode = 0 +duration = 0.75 diff --git a/scenes/EffectComponent.tscn b/scenes/EffectComponent.tscn index bfd716f..5152fdf 100644 --- a/scenes/EffectComponent.tscn +++ b/scenes/EffectComponent.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://bq3xhbfgkt22l"] -[ext_resource type="Script" uid="uid://65d3hbrpm21x" path="res://scripts/effects_component.gd" id="1_ee0kt"] +[ext_resource type="Script" uid="uid://65d3hbrpm21x" path="res://scripts/effects/effects_component.gd" id="1_ee0kt"] -[node name="EffectsComponent" type="Node2D" unique_id=1393438576] +[node name="EffectsComponent" type="Node" unique_id=1393438576] script = ExtResource("1_ee0kt") diff --git a/scenes/effects/flash_effect.gd b/scenes/effects/flash_effect.gd deleted file mode 100644 index db8fb26..0000000 --- a/scenes/effects/flash_effect.gd +++ /dev/null @@ -1,27 +0,0 @@ -class_name FlashEffect -extends BaseEffect - -@export var flash_color: Color = Color.WHITE -@export var flash_speed: float = 10.0 - -var _timer: float = 0.0 -var _original_material: Material - -func start(target: Node) -> void: - _timer = 0.0 - if target is CanvasItem: - _original_material = target.material - # Apply a ShaderMaterial that handles the flash - var flash_material = ShaderMaterial.new() - flash_material.shader = preload("res://shaders/flash.gdshader") - target.material = flash_material - -func process(delta: float, target: Node) -> void: - _timer += delta - if target.material is ShaderMaterial: - var intensity = (sin(_timer * flash_speed) + 1.0) / 2.0 - target.material.set_shader_parameter("flash_intensity", intensity) - -func stop(target: Node) -> void: - if target is CanvasItem: - target.material = _original_material diff --git a/scenes/player.gd b/scenes/player.gd index f61a309..ace3c7a 100644 --- a/scenes/player.gd +++ b/scenes/player.gd @@ -19,6 +19,10 @@ var previous_position: Vector2 var ship_displacement: float var travel: float = 0 +# Effects Testing +var flash_effect = preload("res://resources/effects/flash_weapon_change.tres") +var blink_effect = preload("res://resources/effects/invincibility_blink.tres") + func _ready() -> void: ## Set initial start position @@ -50,3 +54,4 @@ func _process(delta) -> void: # Cycle weapon (testing key) if input_component.cycle_weapon: weapon_component.cycle_weapon() + $EffectsComponent.apply_effect(flash_effect) diff --git a/scenes/player.tscn b/scenes/player.tscn index b78146a..a323687 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -12,6 +12,7 @@ [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"] +[ext_resource type="Script" uid="uid://65d3hbrpm21x" path="res://scripts/effects/effects_component.gd" id="12_effcomp"] [sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"] atlas = ExtResource("5_qlg0r") @@ -92,6 +93,8 @@ size = Vector2(24, 30) [sub_resource type="RectangleShape2D" id="RectangleShape2D_dqkch"] size = Vector2(6, 5.75) +[sub_resource type="Resource" id="Resource_jej6c"] + [node name="Player" type="Area2D" unique_id=652131079] script = ExtResource("1_ur7pv") @@ -155,6 +158,13 @@ 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")]) +weapon_change_flash = SubResource("Resource_jej6c") metadata/_custom_type_script = "uid://ylmao2ndp22y" +[node name="EffectsComponent" type="Node" parent="." unique_id=1393438576 node_paths=PackedStringArray("target_node")] +unique_name_in_owner = true +script = ExtResource("12_effcomp") +target_node = NodePath("../Ship") +metadata/_custom_type_script = "uid://65d3hbrpm21x" + [connection signal="timeout" from="WeaponCooldown" to="." method="_on_weapon_cooldown_timeout"] diff --git a/scenes/world.tscn b/scenes/world.tscn index 616c55d..36f4ea1 100644 --- a/scenes/world.tscn +++ b/scenes/world.tscn @@ -14,6 +14,11 @@ script = ExtResource("2_k0juu") notification_scene = ExtResource("3_71j4m") +[node name="FPS" type="Label" parent="UI" unique_id=1606313100] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 + [node name="Level" type="Node2D" parent="." unique_id=934289771] [node name="Background" type="Node2D" parent="Level" unique_id=485120278] diff --git a/scripts/base_effect.gd b/scripts/effects/base_effect.gd similarity index 53% rename from scripts/base_effect.gd rename to scripts/effects/base_effect.gd index e871e76..60aaad1 100644 --- a/scripts/base_effect.gd +++ b/scripts/effects/base_effect.gd @@ -3,14 +3,20 @@ extends Resource @export var duration: float = 0.5 +var _elapsed: float = 0.0 + # Called when the effect is applied func start(target: Node) -> void: - pass + _elapsed = 0.0 # Called every frame (if needed) -func process(delta: float) -> void: - pass +func process(delta: float, target: Node) -> void: + _elapsed += delta # Clean up any changes to the target func stop(target: Node) -> void: pass + +# Returns true when the effect has run its course +func is_finished() -> bool: + return _elapsed >= duration diff --git a/scripts/base_effect.gd.uid b/scripts/effects/base_effect.gd.uid similarity index 100% rename from scripts/base_effect.gd.uid rename to scripts/effects/base_effect.gd.uid diff --git a/scripts/effects/blinker_effect.gd b/scripts/effects/blinker_effect.gd new file mode 100644 index 0000000..9684619 --- /dev/null +++ b/scripts/effects/blinker_effect.gd @@ -0,0 +1,90 @@ +class_name BlinkerEffect +extends BaseEffect + +## How many blink cycles per second. +@export_range(0.0, 60.0) var blink_frequency: float = 8.0 + +## Fraction of each cycle the sprite is visible (0.0–1.0). +@export_range(0.0, 1.0) var blink_length: float = 0.5 + +## Minimum alpha when "off" (0.0 = fully invisible, 1.0 = fully visible). +@export_range(0.0, 1.0) var min_alpha: float = 0.0 + +## Maximum alpha when "on" (0.0–1.0). +@export_range(0.0, 1.0) var max_alpha: float = 1.0 + +## Duration of the fade-in at the start of the effect (seconds). +@export_range(0.0, 5.0) var start_ease: float = 0.0 + +## Easing curve for the fade-in. +@export_enum("Linear", "Smooth", "Ease-In", "Ease-Out", "Ease-In-Out") var start_ease_mode: int = 1 + +## Duration of the fade-out at the end of the effect (seconds). +@export_range(0.0, 5.0) var end_ease: float = 0.0 + +## Easing curve for the fade-out. +@export_enum("Linear", "Smooth", "Ease-In", "Ease-Out", "Ease-In-Out") var end_ease_mode: int = 1 + +var _original_modulate: Color + + +func start(target: Node) -> void: + super.start(target) + if target is CanvasItem: + _original_modulate = target.modulate + + +func process(delta: float, target: Node) -> void: + super.process(delta, target) + if target is CanvasItem: + var alpha: float = _compute_alpha(_elapsed) + target.modulate = Color(_original_modulate.r, _original_modulate.g, _original_modulate.b, alpha) + + +func stop(target: Node) -> void: + if target is CanvasItem: + target.modulate = _original_modulate + + +## Compute the combined eased alpha for a given elapsed time. +func _compute_alpha(elapsed: float) -> float: + if duration <= 0.0: + return 1.0 + + var t: float = min(elapsed, duration) + + # Blink pulse: on/off cycling at the given frequency and duty cycle + var period := 1.0 / blink_frequency if blink_frequency > 0.0 else 1.0 + var phase := fmod(t, period) / period + + var pulse: float = min_alpha + if phase < blink_length: + var pulse_progress = phase / blink_length if blink_length > 0.0 else 1.0 + if pulse_progress < 0.5: + pulse = min_alpha + (max_alpha - min_alpha) * _ease_value(pulse_progress * 2.0, 2) + else: + pulse = min_alpha + (max_alpha - min_alpha) * _ease_value((1.0 - pulse_progress) * 2.0, 3) + + # Start ease: fade from fully visible into the blink pattern + if t < start_ease and start_ease > 0.0: + var fade_in = _ease_value(t / start_ease, start_ease_mode) + return lerp(max_alpha, pulse, fade_in) + + # End ease: fade from blink pattern back to fully visible + if t > duration - end_ease and end_ease > 0.0: + var fade_progress = (t - (duration - end_ease)) / end_ease + var fade_out = _ease_value(fade_progress, end_ease_mode) + return lerp(pulse, max_alpha, fade_out) + + return pulse + + +## Apply easing to a 0.0–1.0 normalized value based on the selected mode. +func _ease_value(value: float, mode: int) -> float: + match mode: + 0: return value # Linear + 1: return smoothstep(0.0, 1.0, value) # Smooth + 2: return ease(value, -2.0) # Ease-In (accelerating) + 3: return ease(value, 2.0) # Ease-Out (decelerating) + 4: return ease(value, 3.0) # Ease-In-Out (S-curve) + return value diff --git a/scripts/effects/blinker_effect.gd.uid b/scripts/effects/blinker_effect.gd.uid new file mode 100644 index 0000000..c87f585 --- /dev/null +++ b/scripts/effects/blinker_effect.gd.uid @@ -0,0 +1 @@ +uid://cj4grtaun2h5a diff --git a/scripts/effects_component.gd b/scripts/effects/effects_component.gd similarity index 51% rename from scripts/effects_component.gd rename to scripts/effects/effects_component.gd index c5e5308..361641f 100644 --- a/scripts/effects_component.gd +++ b/scripts/effects/effects_component.gd @@ -1,24 +1,33 @@ class_name EffectComponent -extends Node2D +extends Node -@export var target_node: Node +## The node this component applies effects to. +## If left null, defaults to the first parent CanvasItem. +@export var target_node: Node = null var active_effects: Array[BaseEffect] = [] +func _ready() -> void: + if target_node == null: + # Auto-resolve to the parent if nothing is set + target_node = get_parent() + func _process(delta: float) -> void: + if target_node == null: + return + # Process all active effects backwards so we can safely remove finished ones for i in range(active_effects.size() - 1, -1, -1): var effect = active_effects[i] effect.process(delta, target_node) - - # Example: simple time-based expiration - effect.duration -= delta - if effect.duration <= 0.0: + + if effect.is_finished(): remove_effect(effect) func apply_effect(effect: BaseEffect) -> void: - effect.start(target_node) - active_effects.append(effect) + var instance = effect.duplicate() + instance.start(target_node) + active_effects.append(instance) func remove_effect(effect: BaseEffect) -> void: effect.stop(target_node) diff --git a/scripts/effects_component.gd.uid b/scripts/effects/effects_component.gd.uid similarity index 100% rename from scripts/effects_component.gd.uid rename to scripts/effects/effects_component.gd.uid diff --git a/scripts/effects/flash_effect.gd b/scripts/effects/flash_effect.gd new file mode 100644 index 0000000..d681dd7 --- /dev/null +++ b/scripts/effects/flash_effect.gd @@ -0,0 +1,105 @@ +class_name FlashEffect +extends BaseEffect + +## Shader applied to the target sprite during the flash. +@export var flash_shader: Shader = preload("res://shaders/flash.gdshader") + +## Color of the flash overlay. +@export var flash_color: Color = Color.WHITE + +## How many flash cycles per second. +@export_range(0.0, 60.0) var flash_frequency: float = 10.0 + +## Fraction of each cycle the flash is visible (0.0–1.0, i.e. duty cycle). +@export_range(0.0, 1.0) var flash_length: float = 0.5 + +## How the flash blends with the original sprite. +@export_enum("Mix", "Additive", "Screen") var blend_mode: int = 0 + +## Additional brightness added to the flash color (0.0 = none, 1.0 = double). +@export_range(0.0, 1.0) var brightness_boost: float = 0.0 + +## Duration of the fade-in at the start of the effect (seconds). +@export_range(0.0, 5.0) var start_ease: float = 0.0 + +## Easing curve for the fade-in. +@export_enum("Linear", "Smooth", "Ease-In", "Ease-Out", "Ease-In-Out") var start_ease_mode: int = 1 + +## Duration of the fade-out at the end of the effect (seconds). +@export_range(0.0, 5.0) var end_ease: float = 0.0 + +## Easing curve for the fade-out. +@export_enum("Linear", "Smooth", "Ease-In", "Ease-Out", "Ease-In-Out") var end_ease_mode: int = 1 + +var _original_material: Material + + +func start(target: Node) -> void: + super.start(target) + if target is CanvasItem: + _original_material = target.material + var flash_material := ShaderMaterial.new() + flash_material.shader = flash_shader + flash_material.set_shader_parameter("flash_color", flash_color) + flash_material.set_shader_parameter("flash_intensity", 0.0) + flash_material.set_shader_parameter("blend_mode", blend_mode) + flash_material.set_shader_parameter("brightness_boost", brightness_boost) + target.material = flash_material + + +func process(delta: float, target: Node) -> void: + super.process(delta, target) + if target.material is ShaderMaterial: + var intensity := _compute_intensity(_elapsed) + target.material.set_shader_parameter("flash_intensity", intensity) + + +func stop(target: Node) -> void: + if target is CanvasItem: + target.material = _original_material + + +## Compute the combined eased flash intensity for a given elapsed time. +## Returns a value 0.0–1.0 where 1.0 means full flash visibility. +func _compute_intensity(elapsed: float) -> float: + if duration <= 0.0: + return 0.0 + + # Clamp elapsed to duration to avoid overshoot on the final frame + var t: float = min(elapsed, duration) + + # Overall envelope: fade in during start_ease, hold, fade out during end_ease + var envelope: float = 1.0 + if t < start_ease and start_ease > 0.0: + envelope = _ease_value(t / start_ease, start_ease_mode) + elif t > duration - end_ease and end_ease > 0.0: + var fade_progress = (t - (duration - end_ease)) / end_ease + envelope = 1.0 - _ease_value(fade_progress, end_ease_mode) + + # Flash pattern: on/off cycling at the given frequency and duty cycle + # Each flash pulse also eases in and out for a smoother look + var period := 1.0 / flash_frequency if flash_frequency > 0.0 else 1.0 + var phase := fmod(t, period) / period # 0.0–1.0 position within the current cycle + + var pulse: float = 0.0 + if phase < flash_length: + # Inside the "on" portion of this cycle — ease within the pulse itself + var pulse_progress = phase / flash_length if flash_length > 0.0 else 1.0 + # Ease in for the first half of the pulse (build up), ease out for the second (fade down) + if pulse_progress < 0.5: + pulse = _ease_value(pulse_progress * 2.0, 2) # Ease-In (build up) + else: + pulse = _ease_value((1.0 - pulse_progress) * 2.0, 3) # Ease-Out (fade down) + + return envelope * pulse + + +## Apply easing to a 0.0–1.0 normalized value based on the selected mode. +func _ease_value(value: float, mode: int) -> float: + match mode: + 0: return value # Linear + 1: return smoothstep(0.0, 1.0, value) # Smooth + 2: return ease(value, -2.0) # Ease-In (accelerating) + 3: return ease(value, 2.0) # Ease-Out (decelerating) + 4: return ease(value, 3.0) # Ease-In-Out (S-curve) + return value diff --git a/scenes/effects/flash_effect.gd.uid b/scripts/effects/flash_effect.gd.uid similarity index 100% rename from scenes/effects/flash_effect.gd.uid rename to scripts/effects/flash_effect.gd.uid diff --git a/scripts/movement_component.gd b/scripts/movement_component.gd index 0539438..655d778 100644 --- a/scripts/movement_component.gd +++ b/scripts/movement_component.gd @@ -30,11 +30,13 @@ func tick(delta: float): %Ship.frame = 2 %Ship/Thrusters.flip_h = true %Ship/Thrusters.animation = "banked" + %Ship/Thrusters.position.x = %Ship.position.x+1 elif input.x < 0: player.position.x = player.position.x-1 %Ship.frame = 1 %Ship/Thrusters.flip_h = false %Ship/Thrusters.animation = "banked" + %Ship/Thrusters.position.x = %Ship.position.x-1 else: %Ship.frame = 0 player.position.x = player.position.x diff --git a/scripts/weapon_component.gd b/scripts/weapon_component.gd index 37dc306..ab00c34 100644 --- a/scripts/weapon_component.gd +++ b/scripts/weapon_component.gd @@ -2,9 +2,12 @@ class_name WeaponComponent extends Node @export var weapon_data: WeaponShot = null @export var available_weapons: Array[WeaponShot] = [] +@export var weapon_change_flash: BaseEffect = null var _current_weapon_index: int = 0 +@onready var effects_component: EffectComponent = %EffectsComponent + func _ready() -> void: # Set the default weapon to be stock, i.e. index 1 @@ -36,10 +39,16 @@ func select_weapon_by_name(name: String) -> bool: print("Switched to: ", name) _emit_weapon_changed() + _trigger_change_flash() return true return false +func _trigger_change_flash() -> void: + if weapon_change_flash and effects_component: + effects_component.apply_effect(weapon_change_flash) + + func cycle_weapon() -> void: # Used for testing weapon cycling if available_weapons.is_empty(): @@ -50,3 +59,4 @@ func cycle_weapon() -> void: # Used for testing weapon cycling print("Switched to: ", weapon_data.shot_name) _emit_weapon_changed() + _trigger_change_flash() diff --git a/shaders/flash.gdshader b/shaders/flash.gdshader new file mode 100644 index 0000000..83fcd33 --- /dev/null +++ b/shaders/flash.gdshader @@ -0,0 +1,44 @@ +shader_type canvas_item; + +// Color of the flash overlay +uniform vec4 flash_color : source_color = vec4(1.0, 1.0, 1.0, 1.0); + +// Overall intensity of the flash (0.0 = none, 1.0 = full) +// Set dynamically by FlashEffect.gd each frame +uniform float flash_intensity : hint_range(0.0, 1.0) = 0.0; + +// How the flash blends with the original sprite +uniform int blend_mode : hint_enum("Mix", "Additive", "Screen") = 0; + +// Additional brightness added to the flash color (0.0 = none, 1.0 = double) +uniform float brightness_boost : hint_range(0.0, 1.0) = 0.0; + +void fragment() { + vec4 original = texture(TEXTURE, UV); + + vec3 flash_rgb = flash_color.rgb * (1.0 + brightness_boost); + + vec3 result; + float alpha = original.a; + + if (original.a == 0.0) { + // Skip processing for fully transparent pixels + COLOR = original; + } else if (blend_mode == 0) { + // Mix: Linear interpolation between original and flash color + result = mix(original.rgb, flash_rgb, flash_intensity); + // Modulate alpha by flash intensity for a flickering transparency effect + alpha = mix(original.a, flash_color.a, flash_intensity); + } else if (blend_mode == 1) { + // Additive: Flash adds light to the original, clamped to avoid HDR blowout + result = clamp(original.rgb + flash_rgb * flash_intensity, 0.0, 1.0); + // Additive naturally brightens, so boost alpha when flashing + alpha = clamp(original.a + flash_color.a * flash_intensity, 0.0, 1.0); + } else { + // Screen: Brightens without washing out highlights + result = original.rgb + (1.0 - original.rgb) * flash_rgb * flash_intensity; + alpha = clamp(original.a + (1.0 - original.a) * flash_color.a * flash_intensity, 0.0, 1.0); + } + + COLOR = vec4(result, alpha); +} diff --git a/shaders/flash.gdshader.uid b/shaders/flash.gdshader.uid new file mode 100644 index 0000000..82bde5d --- /dev/null +++ b/shaders/flash.gdshader.uid @@ -0,0 +1 @@ +uid://dp4svqyxg1dum From 650239a9e8f32bcfa3f66b37d585017b22f8c521 Mon Sep 17 00:00:00 2001 From: henry Date: Wed, 24 Jun 2026 18:41:37 +0100 Subject: [PATCH 20/37] Added fps display. --- scenes/world.tscn | 3 +++ scripts/fps_display.gd | 15 +++++++++++++++ scripts/fps_display.gd.uid | 1 + scripts/movement_component.gd | 1 + 4 files changed, 20 insertions(+) create mode 100644 scripts/fps_display.gd create mode 100644 scripts/fps_display.gd.uid diff --git a/scenes/world.tscn b/scenes/world.tscn index 36f4ea1..6383760 100644 --- a/scenes/world.tscn +++ b/scenes/world.tscn @@ -5,6 +5,7 @@ [ext_resource type="Texture2D" uid="uid://b3dqvd23nbmrm" path="res://graphics/cloud layers.png" id="3_4wyf3"] [ext_resource type="PackedScene" uid="uid://c3scm07fgpkcp" path="res://scenes/notification_display.tscn" id="3_71j4m"] [ext_resource type="PackedScene" uid="uid://6wq3ynesnsha" path="res://scenes/player.tscn" id="3_k0juu"] +[ext_resource type="Script" uid="uid://eblemtukrey6" path="res://scripts/fps_display.gd" id="4_qfnet"] [node name="World" type="Node2D" unique_id=1317852169] @@ -18,6 +19,8 @@ notification_scene = ExtResource("3_71j4m") layout_mode = 0 offset_right = 40.0 offset_bottom = 23.0 +theme_override_font_sizes/font_size = 8 +script = ExtResource("4_qfnet") [node name="Level" type="Node2D" parent="." unique_id=934289771] diff --git a/scripts/fps_display.gd b/scripts/fps_display.gd new file mode 100644 index 0000000..b58041a --- /dev/null +++ b/scripts/fps_display.gd @@ -0,0 +1,15 @@ +extends Label + +var last_time = 0 +var frame_count = 0 +var fps = 0 + +func _process(delta): + frame_count += 1 + last_time += delta + + if last_time >= 1.0: # Update every second + fps = frame_count + text = " " + str(fps) + " FPS" + last_time = 0 + frame_count = 0 diff --git a/scripts/fps_display.gd.uid b/scripts/fps_display.gd.uid new file mode 100644 index 0000000..3f9ff74 --- /dev/null +++ b/scripts/fps_display.gd.uid @@ -0,0 +1 @@ +uid://eblemtukrey6 diff --git a/scripts/movement_component.gd b/scripts/movement_component.gd index 655d778..84c9a57 100644 --- a/scripts/movement_component.gd +++ b/scripts/movement_component.gd @@ -42,6 +42,7 @@ func tick(delta: float): player.position.x = player.position.x %Ship/Thrusters.flip_h = false %Ship/Thrusters.animation = "fwd" + %Ship/Thrusters.position.x = %Ship.position.x-0.3 # Get previous positon for equidistant bullet calculation player.previous_position = player.position From 389485e82c7ead74fb21ceaf4a4636de3a92a711 Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 25 Jun 2026 01:25:34 +0100 Subject: [PATCH 21/37] Locked frame rate at 60fps and adjusted weapon speed to work with that. --- project.godot | 1 + resources/player_weapon_resources/stock.tres | 2 +- resources/player_weapon_resources/tri.tres | 2 +- resources/player_weapon_resources/vanguard.tres | 2 +- scenes/player_weapons/weapon_stock.tscn | 4 ++-- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/project.godot b/project.godot index 2402a23..9c7cec1 100644 --- a/project.godot +++ b/project.godot @@ -13,6 +13,7 @@ config_version=5 config/name="Facsimile Wing" run/main_scene="uid://bj4fytc3sy482" config/features=PackedStringArray("4.7", "Forward Plus") +run/max_fps=60 config/icon="res://icon.svg" [autoload] diff --git a/resources/player_weapon_resources/stock.tres b/resources/player_weapon_resources/stock.tres index e8b91cb..184daab 100644 --- a/resources/player_weapon_resources/stock.tres +++ b/resources/player_weapon_resources/stock.tres @@ -8,7 +8,7 @@ script = ExtResource("2_ym48c") shot_name = "stock" bullet_scene = ExtResource("1_lcw6o") damage = 2 -speed = 500 +speed = 300 spacing = 25.0 origin = -15 horizontal_offset = 10.0 diff --git a/resources/player_weapon_resources/tri.tres b/resources/player_weapon_resources/tri.tres index 0b63301..b567df8 100644 --- a/resources/player_weapon_resources/tri.tres +++ b/resources/player_weapon_resources/tri.tres @@ -8,7 +8,7 @@ script = ExtResource("2_syw6j") shot_name = "tri" bullet_scene = ExtResource("1_07hyh") damage = 3 -speed = 450 +speed = 420 projectiles = 3 spacing = 30.0 origin = -15 diff --git a/resources/player_weapon_resources/vanguard.tres b/resources/player_weapon_resources/vanguard.tres index 61f7a1c..dcb3580 100644 --- a/resources/player_weapon_resources/vanguard.tres +++ b/resources/player_weapon_resources/vanguard.tres @@ -8,7 +8,7 @@ script = ExtResource("2_w7xlm") shot_name = "vanguard" bullet_scene = ExtResource("1_hm46f") damage = 5 -speed = 550 +speed = 500 projectiles = 5 spacing = 30.0 origin = -15 diff --git a/scenes/player_weapons/weapon_stock.tscn b/scenes/player_weapons/weapon_stock.tscn index 5eddb30..9989ab5 100644 --- a/scenes/player_weapons/weapon_stock.tscn +++ b/scenes/player_weapons/weapon_stock.tscn @@ -29,11 +29,11 @@ animations = [{ }], "loop": 1, "name": &"default", -"speed": 24.0 +"speed": 30.0 }] [sub_resource type="RectangleShape2D" id="RectangleShape2D_mvdrj"] -size = Vector2(6.666667, 14) +size = Vector2(10, 16) [node name="StockWeapon" type="Area2D" unique_id=1832200900] script = ExtResource("1_u1d5o") From dd4652b7320493ac7503c8f1810e13c629af20c1 Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 25 Jun 2026 01:26:16 +0100 Subject: [PATCH 22/37] Added an FPS display for performance monitoring. --- scenes/world.tscn | 2 +- scripts/utility/fps_display.gd | 15 +++++++++++++++ scripts/utility/fps_display.gd.uid | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 scripts/utility/fps_display.gd create mode 100644 scripts/utility/fps_display.gd.uid diff --git a/scenes/world.tscn b/scenes/world.tscn index 6383760..515828a 100644 --- a/scenes/world.tscn +++ b/scenes/world.tscn @@ -5,7 +5,7 @@ [ext_resource type="Texture2D" uid="uid://b3dqvd23nbmrm" path="res://graphics/cloud layers.png" id="3_4wyf3"] [ext_resource type="PackedScene" uid="uid://c3scm07fgpkcp" path="res://scenes/notification_display.tscn" id="3_71j4m"] [ext_resource type="PackedScene" uid="uid://6wq3ynesnsha" path="res://scenes/player.tscn" id="3_k0juu"] -[ext_resource type="Script" uid="uid://eblemtukrey6" path="res://scripts/fps_display.gd" id="4_qfnet"] +[ext_resource type="Script" uid="uid://eblemtukrey6" path="res://scripts/utility/fps_display.gd" id="4_qfnet"] [node name="World" type="Node2D" unique_id=1317852169] diff --git a/scripts/utility/fps_display.gd b/scripts/utility/fps_display.gd new file mode 100644 index 0000000..b58041a --- /dev/null +++ b/scripts/utility/fps_display.gd @@ -0,0 +1,15 @@ +extends Label + +var last_time = 0 +var frame_count = 0 +var fps = 0 + +func _process(delta): + frame_count += 1 + last_time += delta + + if last_time >= 1.0: # Update every second + fps = frame_count + text = " " + str(fps) + " FPS" + last_time = 0 + frame_count = 0 diff --git a/scripts/utility/fps_display.gd.uid b/scripts/utility/fps_display.gd.uid new file mode 100644 index 0000000..3f9ff74 --- /dev/null +++ b/scripts/utility/fps_display.gd.uid @@ -0,0 +1 @@ +uid://eblemtukrey6 From 4f90c82b8f49c517b4d50fb99eb93d5789d632ec Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 25 Jun 2026 01:26:49 +0100 Subject: [PATCH 23/37] Attempted to figure how to adjust notification label size. Nah. --- scenes/notification_display.tscn | 3 ++- scripts/fps_display.gd | 15 --------------- scripts/fps_display.gd.uid | 1 - scripts/notification_display.gd | 15 +++++++++++++-- 4 files changed, 15 insertions(+), 19 deletions(-) delete mode 100644 scripts/fps_display.gd delete mode 100644 scripts/fps_display.gd.uid diff --git a/scenes/notification_display.tscn b/scenes/notification_display.tscn index 982c58f..4180e5e 100644 --- a/scenes/notification_display.tscn +++ b/scenes/notification_display.tscn @@ -11,7 +11,8 @@ icon = NodePath("HBoxContainer/Icon") label = NodePath("HBoxContainer/Label") [node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=228546504] -layout_mode = 0 +layout_mode = 1 +theme_override_constants/separator = 4 [node name="Icon" type="TextureRect" parent="HBoxContainer" unique_id=3] custom_minimum_size = Vector2(16, 16) diff --git a/scripts/fps_display.gd b/scripts/fps_display.gd deleted file mode 100644 index b58041a..0000000 --- a/scripts/fps_display.gd +++ /dev/null @@ -1,15 +0,0 @@ -extends Label - -var last_time = 0 -var frame_count = 0 -var fps = 0 - -func _process(delta): - frame_count += 1 - last_time += delta - - if last_time >= 1.0: # Update every second - fps = frame_count - text = " " + str(fps) + " FPS" - last_time = 0 - frame_count = 0 diff --git a/scripts/fps_display.gd.uid b/scripts/fps_display.gd.uid deleted file mode 100644 index 3f9ff74..0000000 --- a/scripts/fps_display.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://eblemtukrey6 diff --git a/scripts/notification_display.gd b/scripts/notification_display.gd index 2150af8..4dbbc48 100644 --- a/scripts/notification_display.gd +++ b/scripts/notification_display.gd @@ -13,7 +13,19 @@ var _connector_line: Line2D = null var _connector_visible: bool = false +func _ready() -> void: + # Start fully transparent so the initial (0,0) position is invisible. + # This runs during add_child() before any rendering occurs. + modulate.a = 0.0 + + # 4px horizontal padding inside the background box + _container.add_theme_constant_override("margin_left", 4) + _container.add_theme_constant_override("margin_right", 4) + + func show_notification(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: float) -> void: + modulate.a = 0.0 + label.add_theme_font_size_override("font_size", 8) label.text = weapon_name @@ -40,9 +52,8 @@ func show_notification(weapon_name: String, player_node: Node2D, player_sprite_s _update_position() var target_pos = position - # Start 10px above destination, fully transparent + # Start 10px above destination (already transparent from line 17) position.y = target_pos.y - 10.0 - modulate.a = 0.0 # Create connector line immediately so it fades in with the notification _connector_line = Line2D.new() From 4f3839448bb3dd9497e86e11b2d650c37792fb4b Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 25 Jun 2026 02:06:28 +0100 Subject: [PATCH 24/37] Modified weapon scripts and resources with a simplified spread angle variable. --- graphics/spread.png | Bin 0 -> 282 bytes graphics/spread.png.import | 40 ++++++++++++++++++ resources/player_weapon_resources/spread.tres | 19 +++++++++ scenes/player.tscn | 3 +- scenes/player_weapons/weapon_stock.gd | 8 +++- scripts/shoot_component.gd | 6 +++ scripts/weapon_shot.gd | 2 + 7 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 graphics/spread.png create mode 100644 graphics/spread.png.import create mode 100644 resources/player_weapon_resources/spread.tres diff --git a/graphics/spread.png b/graphics/spread.png new file mode 100644 index 0000000000000000000000000000000000000000..b653e7ceb540a163a60d4cd8a0fbadc527e4fde5 GIT binary patch literal 282 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1IggaDrqS0JsV zVB)G_lV)kyA7*{OQ0?Y|w0DPR{r+S&^JzfVJ_GY9dES}&LEb7xHkS7GB?bvi(RmM( zXaA2s`{eZPKmY&#pS^Z_OI>?rR#s$KP?=NL8Y82d;mOylclA&A>dH6xoxJBf&<=%? zAirP+plWzopr0K|iJr~m)} literal 0 HcmV?d00001 diff --git a/graphics/spread.png.import b/graphics/spread.png.import new file mode 100644 index 0000000..24193a1 --- /dev/null +++ b/graphics/spread.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dwc5fjwhqikoo" +path="res://.godot/imported/spread.png-77a3efff77439dd55f282fc699502b2f.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://graphics/spread.png" +dest_files=["res://.godot/imported/spread.png-77a3efff77439dd55f282fc699502b2f.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/resources/player_weapon_resources/spread.tres b/resources/player_weapon_resources/spread.tres new file mode 100644 index 0000000..e8b930b --- /dev/null +++ b/resources/player_weapon_resources/spread.tres @@ -0,0 +1,19 @@ +[gd_resource type="Resource" script_class="WeaponShot" format=3 uid="uid://ds53sryglmf27"] + +[ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/player_weapons/weapon_stock.tscn" id="1_pn64g"] +[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://scripts/weapon_shot.gd" id="2_4b7mw"] + +[resource] +script = ExtResource("2_4b7mw") +shot_name = "spread" +bullet_scene = ExtResource("1_pn64g") +damage = 5 +speed = 500 +projectiles = 5 +spacing = 30.0 +origin = -15 +horizontal_offset = 8.25 +spread_angle = 15.0 +stagger_offset = 0.5 +stagger_animation = true +metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/scenes/player.tscn b/scenes/player.tscn index a323687..e56122c 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -13,6 +13,7 @@ [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"] [ext_resource type="Script" uid="uid://65d3hbrpm21x" path="res://scripts/effects/effects_component.gd" id="12_effcomp"] +[ext_resource type="Resource" uid="uid://ds53sryglmf27" path="res://resources/player_weapon_resources/spread.tres" id="13_f1ej7"] [sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"] atlas = ExtResource("5_qlg0r") @@ -157,7 +158,7 @@ script = ExtResource("6_y4r1p") 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")]) +available_weapons = Array[ExtResource("10_d2wvv")]([ExtResource("8_stock"), ExtResource("11_3v2ag"), ExtResource("9_ur7pv"), ExtResource("13_f1ej7")]) weapon_change_flash = SubResource("Resource_jej6c") metadata/_custom_type_script = "uid://ylmao2ndp22y" diff --git a/scenes/player_weapons/weapon_stock.gd b/scenes/player_weapons/weapon_stock.gd index d1f5198..6c2f9e6 100644 --- a/scenes/player_weapons/weapon_stock.gd +++ b/scenes/player_weapons/weapon_stock.gd @@ -10,6 +10,9 @@ var time_offset: float = 0.5 # When this bullet should fire (absolute time) var fire_time: float = 0.0 +# Angle offset for spread shots (in degrees) +var angle: float = 0.0 + # Track if this bullet is currently active in the shot var is_active: bool = false @@ -20,8 +23,9 @@ func _process(delta): if !is_active and current_time >= fire_time: activate() - # Move the bullet - position.y -= shot_data.speed * delta + # Move the bullet, factoring in spread angle + var velocity = Vector2.UP.rotated(deg_to_rad(angle)) * shot_data.speed + position += velocity * delta func activate(): is_active = true diff --git a/scripts/shoot_component.gd b/scripts/shoot_component.gd index eb6a2a9..48cc0e7 100644 --- a/scripts/shoot_component.gd +++ b/scripts/shoot_component.gd @@ -34,9 +34,15 @@ func shoot(): # 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)) + # Calculate angle for this bullet (only when projectiles >= 3) + var bullet_angle: float = 0.0 + if total_projectiles >= 3: + bullet_angle = (index_from_center / center_index) * (weapon_data.spread_angle / 2.0) + # Set timing properties on the bullet bullet.time_offset = time_offset bullet.fire_time = current_time + time_offset + bullet.angle = bullet_angle # Set the bullet data bullet.set_weapon_data(weapon_data.bullet_scene, weapon_data) diff --git a/scripts/weapon_shot.gd b/scripts/weapon_shot.gd index c535924..7b1190a 100644 --- a/scripts/weapon_shot.gd +++ b/scripts/weapon_shot.gd @@ -15,6 +15,8 @@ extends Resource @export_category("Spread") # Horizontal distance between projectiles @export var horizontal_offset: float = 6.5 +# Total spread angle in degrees (only applied when projectiles >= 3) +@export var spread_angle: float = 0.0 # Time delay per projectile index @export var stagger_offset: float = 0.25 From 30619bc7c15597b439ec31827ce17c5fc425e71d Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 25 Jun 2026 11:35:42 +0100 Subject: [PATCH 25/37] Fixed initial double shot issue; tweaked feel of weapons. --- graphics/spread.png | Bin 282 -> 259 bytes resources/player_weapon_resources/spread.tres | 6 +++--- resources/player_weapon_resources/stock.tres | 2 +- scenes/player_weapons/weapon_stock.gd | 2 +- scripts/shoot_component.gd | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/graphics/spread.png b/graphics/spread.png index b653e7ceb540a163a60d4cd8a0fbadc527e4fde5..a45b2ec4dc42ca677cf61a0b05ea2e40a66143e9 100644 GIT binary patch delta 65 zcmbQm)XX&Dq?M|ti(`ny)Z_^c%sfJi7AZ*iB?%t5(4^BFoS=}?$k1V8$7sR8P$VK= TE6?F&%K!wPu6{1-oD!Mn#DBXWT1_wi(`ny)Z_^c%se|-TwEVA38>9UaX4|1#bAp=g+Pl6gSz2Xhsc61 s#+yPL7|fy_WF*?S4}>O`OKf6bC=(D*o!t=kn*j(sUHx3vIVCg!01W;di2wiq diff --git a/resources/player_weapon_resources/spread.tres b/resources/player_weapon_resources/spread.tres index e8b930b..5ccfbb5 100644 --- a/resources/player_weapon_resources/spread.tres +++ b/resources/player_weapon_resources/spread.tres @@ -8,12 +8,12 @@ script = ExtResource("2_4b7mw") shot_name = "spread" bullet_scene = ExtResource("1_pn64g") damage = 5 -speed = 500 -projectiles = 5 +speed = 720 +projectiles = 4 spacing = 30.0 origin = -15 horizontal_offset = 8.25 -spread_angle = 15.0 +spread_angle = 7.5 stagger_offset = 0.5 stagger_animation = true metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/resources/player_weapon_resources/stock.tres b/resources/player_weapon_resources/stock.tres index 184daab..94afc1b 100644 --- a/resources/player_weapon_resources/stock.tres +++ b/resources/player_weapon_resources/stock.tres @@ -12,5 +12,5 @@ speed = 300 spacing = 25.0 origin = -15 horizontal_offset = 10.0 -stagger_offset = 0.35 +stagger_offset = 0.0 metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/scenes/player_weapons/weapon_stock.gd b/scenes/player_weapons/weapon_stock.gd index 6c2f9e6..5f18b6a 100644 --- a/scenes/player_weapons/weapon_stock.gd +++ b/scenes/player_weapons/weapon_stock.gd @@ -23,7 +23,7 @@ func _process(delta): if !is_active and current_time >= fire_time: activate() - # Move the bullet, factoring in spread angle + # Move the bullet every frame; stagger controls visibility, not movement var velocity = Vector2.UP.rotated(deg_to_rad(angle)) * shot_data.speed position += velocity * delta diff --git a/scripts/shoot_component.gd b/scripts/shoot_component.gd index 48cc0e7..5ed160b 100644 --- a/scripts/shoot_component.gd +++ b/scripts/shoot_component.gd @@ -21,8 +21,8 @@ func shoot(): # 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 * weapon_data.stagger_offset + # Calculate timing offset for staggered firing (center-first, pairs outward) + var time_offset: float = abs(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 @@ -51,5 +51,5 @@ func shoot(): 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 + # Reset travel after firing to prevent multiple bursts per tap + player.travel = 0.0 From 122f7bed5f9ca71426c2c9c48f291640ba528dab Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 25 Jun 2026 11:37:55 +0100 Subject: [PATCH 26/37] Further weapon feel modificaitons. --- resources/player_weapon_resources/spread.tres | 4 ++-- resources/player_weapon_resources/stock.tres | 5 ++--- resources/player_weapon_resources/tri.tres | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/resources/player_weapon_resources/spread.tres b/resources/player_weapon_resources/spread.tres index 5ccfbb5..9a91eaa 100644 --- a/resources/player_weapon_resources/spread.tres +++ b/resources/player_weapon_resources/spread.tres @@ -9,8 +9,8 @@ shot_name = "spread" bullet_scene = ExtResource("1_pn64g") damage = 5 speed = 720 -projectiles = 4 -spacing = 30.0 +projectiles = 5 +spacing = 100.0 origin = -15 horizontal_offset = 8.25 spread_angle = 7.5 diff --git a/resources/player_weapon_resources/stock.tres b/resources/player_weapon_resources/stock.tres index 94afc1b..a10efcd 100644 --- a/resources/player_weapon_resources/stock.tres +++ b/resources/player_weapon_resources/stock.tres @@ -8,9 +8,8 @@ script = ExtResource("2_ym48c") shot_name = "stock" bullet_scene = ExtResource("1_lcw6o") damage = 2 -speed = 300 -spacing = 25.0 +speed = 360 origin = -15 -horizontal_offset = 10.0 +horizontal_offset = 12.0 stagger_offset = 0.0 metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/resources/player_weapon_resources/tri.tres b/resources/player_weapon_resources/tri.tres index b567df8..f9e2f47 100644 --- a/resources/player_weapon_resources/tri.tres +++ b/resources/player_weapon_resources/tri.tres @@ -10,9 +10,9 @@ bullet_scene = ExtResource("1_07hyh") damage = 3 speed = 420 projectiles = 3 -spacing = 30.0 +spacing = 45.0 origin = -15 -horizontal_offset = 8.5 -stagger_offset = 0.2 +horizontal_offset = 12.5 +stagger_offset = 0.35 stagger_animation = true metadata/_custom_type_script = "uid://7n1itonn35fm" From 62e02d25557b16a99baf589604987b4d6b607058 Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 26 Jun 2026 12:31:19 +0100 Subject: [PATCH 27/37] Weapon feel modifications. --- resources/player_weapon_resources/stock.tres | 3 ++- resources/player_weapon_resources/tri.tres | 2 +- scenes/player_weapons/weapon_stock.tscn | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/resources/player_weapon_resources/stock.tres b/resources/player_weapon_resources/stock.tres index a10efcd..d4d85bf 100644 --- a/resources/player_weapon_resources/stock.tres +++ b/resources/player_weapon_resources/stock.tres @@ -8,7 +8,8 @@ script = ExtResource("2_ym48c") shot_name = "stock" bullet_scene = ExtResource("1_lcw6o") damage = 2 -speed = 360 +speed = 650 +spacing = 25.0 origin = -15 horizontal_offset = 12.0 stagger_offset = 0.0 diff --git a/resources/player_weapon_resources/tri.tres b/resources/player_weapon_resources/tri.tres index f9e2f47..f1ca45d 100644 --- a/resources/player_weapon_resources/tri.tres +++ b/resources/player_weapon_resources/tri.tres @@ -8,7 +8,7 @@ script = ExtResource("2_syw6j") shot_name = "tri" bullet_scene = ExtResource("1_07hyh") damage = 3 -speed = 420 +speed = 700 projectiles = 3 spacing = 45.0 origin = -15 diff --git a/scenes/player_weapons/weapon_stock.tscn b/scenes/player_weapons/weapon_stock.tscn index 9989ab5..4478174 100644 --- a/scenes/player_weapons/weapon_stock.tscn +++ b/scenes/player_weapons/weapon_stock.tscn @@ -29,7 +29,7 @@ animations = [{ }], "loop": 1, "name": &"default", -"speed": 30.0 +"speed": 24.0 }] [sub_resource type="RectangleShape2D" id="RectangleShape2D_mvdrj"] From 2db5f37975e53348349e3110da0807aa316a76d2 Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 26 Jun 2026 22:55:32 +0100 Subject: [PATCH 28/37] Added follow angle for spread shots so projectiles point in the direction they're going. --- resources/player_weapon_resources/spread.tres | 1 + scenes/player_weapons/weapon_stock.gd | 4 ++++ scripts/weapon_shot.gd | 2 ++ 3 files changed, 7 insertions(+) diff --git a/resources/player_weapon_resources/spread.tres b/resources/player_weapon_resources/spread.tres index 9a91eaa..4f3d629 100644 --- a/resources/player_weapon_resources/spread.tres +++ b/resources/player_weapon_resources/spread.tres @@ -16,4 +16,5 @@ horizontal_offset = 8.25 spread_angle = 7.5 stagger_offset = 0.5 stagger_animation = true +follow_angle = true metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/scenes/player_weapons/weapon_stock.gd b/scenes/player_weapons/weapon_stock.gd index 5f18b6a..95077ca 100644 --- a/scenes/player_weapons/weapon_stock.gd +++ b/scenes/player_weapons/weapon_stock.gd @@ -27,6 +27,10 @@ func _process(delta): var velocity = Vector2.UP.rotated(deg_to_rad(angle)) * shot_data.speed position += velocity * delta + # Rotate sprite to face travel direction when conditions are met + if shot_data.follow_angle and shot_data.projectiles > 2 and shot_data.spread_angle > 0: + $AnimatedSprite2D.rotation = deg_to_rad(angle) + func activate(): is_active = true visible = true diff --git a/scripts/weapon_shot.gd b/scripts/weapon_shot.gd index 7b1190a..c4d9bd7 100644 --- a/scripts/weapon_shot.gd +++ b/scripts/weapon_shot.gd @@ -23,3 +23,5 @@ extends Resource @export_category("Effects") # Offset animation playback per projectile index @export var stagger_animation: bool = false +# Rotate projectiles to point along their travel direction (requires >2 projectiles and spread_angle > 0) +@export var follow_angle: bool = false From 313e0135430b62e452043d4a268f71c475bd9a0f Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 26 Jun 2026 22:59:52 +0100 Subject: [PATCH 29/37] Slight tweak to remove warnings. --- resources/player_weapon_resources/spread.tres | 3 +-- scripts/weapon_component.gd | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/resources/player_weapon_resources/spread.tres b/resources/player_weapon_resources/spread.tres index 4f3d629..82ef411 100644 --- a/resources/player_weapon_resources/spread.tres +++ b/resources/player_weapon_resources/spread.tres @@ -13,8 +13,7 @@ projectiles = 5 spacing = 100.0 origin = -15 horizontal_offset = 8.25 -spread_angle = 7.5 +spread_angle = 25.0 stagger_offset = 0.5 stagger_animation = true -follow_angle = true metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/scripts/weapon_component.gd b/scripts/weapon_component.gd index ab00c34..9e09f6e 100644 --- a/scripts/weapon_component.gd +++ b/scripts/weapon_component.gd @@ -21,7 +21,7 @@ func _ready() -> void: func _emit_weapon_changed() -> void: var ship: Sprite2D = get_parent().get_node("Ship") var sprite_size = ship.get_rect().size - var origin_offset = weapon_data.origin if weapon_data else 0.0 + var origin_offset: int = weapon_data.origin if weapon_data else 0 EventBus.weapon_changed.emit(weapon_data.shot_name, get_parent(), sprite_size, origin_offset) @@ -31,12 +31,12 @@ func get_bullet_scene() -> PackedScene: func get_weapon_resource() -> Resource: return weapon_data -func select_weapon_by_name(name: String) -> bool: +func select_weapon_by_name(weapon_name: String) -> bool: for i in range(available_weapons.size()): - if available_weapons[i].shot_name == name: + if available_weapons[i].shot_name == weapon_name: _current_weapon_index = i weapon_data = available_weapons[i] - print("Switched to: ", name) + print("Switched to: ", weapon_name) _emit_weapon_changed() _trigger_change_flash() From 3303d937fd26c5dad550bea85fa908e21618e14c Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 26 Jun 2026 23:54:53 +0100 Subject: [PATCH 30/37] Added grouped shots as sub resources, as well as the abilit to mirror pairs. --- .../player_weapon_resources/patterns/fwd.tres | 9 ++ .../patterns/phallanx.tres | 11 ++ .../player_weapon_resources/vanguard+.tres | 22 +++ scenes/player.tscn | 3 +- scripts/shoot_component.gd | 130 +++++++++++++----- scripts/weapon_projectile_group.gd | 21 +++ scripts/weapon_projectile_group.gd.uid | 1 + scripts/weapon_shot.gd | 3 + 8 files changed, 166 insertions(+), 34 deletions(-) create mode 100644 resources/player_weapon_resources/patterns/fwd.tres create mode 100644 resources/player_weapon_resources/patterns/phallanx.tres create mode 100644 resources/player_weapon_resources/vanguard+.tres create mode 100644 scripts/weapon_projectile_group.gd create mode 100644 scripts/weapon_projectile_group.gd.uid diff --git a/resources/player_weapon_resources/patterns/fwd.tres b/resources/player_weapon_resources/patterns/fwd.tres new file mode 100644 index 0000000..6008dfb --- /dev/null +++ b/resources/player_weapon_resources/patterns/fwd.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="WeaponProjectileGroup" format=3 uid="uid://tdmd8jq8cm4y"] + +[ext_resource type="Script" uid="uid://d0ios82vubijg" path="res://scripts/weapon_projectile_group.gd" id="1_mhej7"] + +[resource] +script = ExtResource("1_mhej7") +bullet_count = 5 +group_delay = 5.0 +stagger_offset = 2.0 diff --git a/resources/player_weapon_resources/patterns/phallanx.tres b/resources/player_weapon_resources/patterns/phallanx.tres new file mode 100644 index 0000000..48f630f --- /dev/null +++ b/resources/player_weapon_resources/patterns/phallanx.tres @@ -0,0 +1,11 @@ +[gd_resource type="Resource" script_class="WeaponProjectileGroup" format=3 uid="uid://ch8qch6lx1mdx"] + +[ext_resource type="Script" uid="uid://d0ios82vubijg" path="res://scripts/weapon_projectile_group.gd" id="1_m23g4"] + +[resource] +script = ExtResource("1_m23g4") +spread_angle = 3.0 +angle_offset = 8.0 +horizontal_offset = 20.0 +group_delay = 0.25 +stagger_offset = 0.5 diff --git a/resources/player_weapon_resources/vanguard+.tres b/resources/player_weapon_resources/vanguard+.tres new file mode 100644 index 0000000..4d2d490 --- /dev/null +++ b/resources/player_weapon_resources/vanguard+.tres @@ -0,0 +1,22 @@ +[gd_resource type="Resource" script_class="WeaponShot" format=3 uid="uid://c41aoyka7nfr8"] + +[ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/player_weapons/weapon_stock.tscn" id="1_lqlv8"] +[ext_resource type="Script" uid="uid://d0ios82vubijg" path="res://scripts/weapon_projectile_group.gd" id="2_qeb4b"] +[ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://scripts/weapon_shot.gd" id="3_fh2eq"] +[ext_resource type="Resource" uid="uid://ch8qch6lx1mdx" path="res://resources/player_weapon_resources/patterns/phallanx.tres" id="3_qeb4b"] + +[resource] +script = ExtResource("3_fh2eq") +shot_name = "vanguard+" +bullet_scene = ExtResource("1_lqlv8") +damage = 5 +speed = 500 +projectiles = 5 +spacing = 30.0 +origin = -15 +horizontal_offset = 8.25 +stagger_offset = 0.5 +stagger_animation = true +follow_angle = true +groups = Array[ExtResource("2_qeb4b")]([ExtResource("3_qeb4b")]) +metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/scenes/player.tscn b/scenes/player.tscn index e56122c..92a9dc9 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -14,6 +14,7 @@ [ext_resource type="Resource" uid="uid://cck3gmnhu5agc" path="res://resources/player_weapon_resources/tri.tres" id="11_3v2ag"] [ext_resource type="Script" uid="uid://65d3hbrpm21x" path="res://scripts/effects/effects_component.gd" id="12_effcomp"] [ext_resource type="Resource" uid="uid://ds53sryglmf27" path="res://resources/player_weapon_resources/spread.tres" id="13_f1ej7"] +[ext_resource type="Resource" uid="uid://c41aoyka7nfr8" path="res://resources/player_weapon_resources/vanguard+.tres" id="14_oprun"] [sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"] atlas = ExtResource("5_qlg0r") @@ -158,7 +159,7 @@ script = ExtResource("6_y4r1p") 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"), ExtResource("13_f1ej7")]) +available_weapons = Array[ExtResource("10_d2wvv")]([ExtResource("8_stock"), ExtResource("11_3v2ag"), ExtResource("9_ur7pv"), ExtResource("13_f1ej7"), ExtResource("14_oprun")]) weapon_change_flash = SubResource("Resource_jej6c") metadata/_custom_type_script = "uid://ylmao2ndp22y" diff --git a/scripts/shoot_component.gd b/scripts/shoot_component.gd index 5ed160b..789970d 100644 --- a/scripts/shoot_component.gd +++ b/scripts/shoot_component.gd @@ -6,50 +6,114 @@ class_name ShootComponent extends Node func shoot(): var weapon_data = weapon_component.weapon_data var current_time = Time.get_ticks_msec() / 1000.0 - var total_projectiles = weapon_data.projectiles if player.travel > weapon_data.spacing: + _shoot_standard(weapon_data, current_time) + _shoot_grouped(weapon_data, current_time) - # Calculate center index for symmetrical staggering - var center_index = (total_projectiles - 1) / 2.0 + # Reset travel after firing to prevent multiple bursts per tap + player.travel = 0.0 - if total_projectiles > 0: - for b in range(total_projectiles): - 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 +# Standard projectile logic (backward compatible) +func _shoot_standard(weapon_data: WeaponShot, current_time: float): + var total_projectiles = weapon_data.projectiles + var center_index = (total_projectiles - 1) / 2.0 - # Calculate timing offset for staggered firing (center-first, pairs outward) - var time_offset: float = abs(index_from_center) * weapon_data.stagger_offset + if total_projectiles > 0: + for b in range(total_projectiles): + var bullet := weapon_data.bullet_scene.instantiate() as Area2D + get_tree().root.add_child(bullet) - # Calculate horizontal offset for this bullet (symmetrical: left=-ve, right=+ve) - var bullet_horizontal_offset: float = index_from_center * weapon_data.horizontal_offset + # Calculate index relative to center (0 = center, -1/+1 = first from center) + var index_from_center: float = b - center_index - # Calculate vertical offset from center point (symmetrical vertical spread) - var distance_from_center: float = abs(index_from_center) - var vertical_offset: float = (distance_from_center * weapon_data.origin * -1) / 2 + # Calculate timing offset for staggered firing (center-first, pairs outward) + var time_offset: float = abs(index_from_center) * weapon_data.stagger_offset - # 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)) + # Calculate horizontal offset for this bullet (symmetrical: left=-ve, right=+ve) + var bullet_horizontal_offset: float = index_from_center * weapon_data.horizontal_offset - # Calculate angle for this bullet (only when projectiles >= 3) - var bullet_angle: float = 0.0 - if total_projectiles >= 3: - bullet_angle = (index_from_center / center_index) * (weapon_data.spread_angle / 2.0) + # Calculate vertical offset from center point (symmetrical vertical spread) + var distance_from_center: float = abs(index_from_center) + var vertical_offset: float = (distance_from_center * weapon_data.origin * -1) / 2 - # Set timing properties on the bullet - bullet.time_offset = time_offset - bullet.fire_time = current_time + time_offset - bullet.angle = bullet_angle + # 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 the bullet data - bullet.set_weapon_data(weapon_data.bullet_scene, weapon_data) + # Calculate angle for this bullet (only when projectiles >= 3) + var bullet_angle: float = 0.0 + if total_projectiles >= 3: + bullet_angle = (index_from_center / center_index) * (weapon_data.spread_angle / 2.0) - # Offset animation playback per projectile if enabled - if weapon_data.stagger_animation: - bullet.set_animation_offset(index_from_center * weapon_data.stagger_offset) + # Set timing properties on the bullet + bullet.time_offset = time_offset + bullet.fire_time = current_time + time_offset + bullet.angle = bullet_angle - # Reset travel after firing to prevent multiple bursts per tap - player.travel = 0.0 + # 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) + + +# Grouped projectile logic (new functionality) +func _shoot_grouped(weapon_data: WeaponShot, current_time: float): + 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) + + _fire_grouped_bullet(bullet, group, b, current_time, weapon_data, false) + + # If mirroring is enabled, fire a mirrored copy + if group.mirror: + var mirror_bullet := weapon_data.bullet_scene.instantiate() as Area2D + get_tree().root.add_child(mirror_bullet) + _fire_grouped_bullet(mirror_bullet, group, b, current_time, weapon_data, true) + + +# Fire a single grouped bullet (original or mirrored) +func _fire_grouped_bullet(bullet: Area2D, group: WeaponProjectileGroup, b: int, + current_time: float, weapon_data: WeaponShot, mirror: bool): + # Calculate index relative to this group's center + var center_index: float = (group.bullet_count - 1) / 2.0 + var index_from_center: float = b - center_index + + # Horizontal offset: group offset + within-group spread + # Mirror: negate the horizontal offset contribution + var bullet_horizontal_offset: float = group.horizontal_offset + index_from_center * group.horizontal_spacing + if mirror: + bullet_horizontal_offset = -bullet_horizontal_offset + + # Base angle for the group, plus within-group spread + # Mirror: negate the angle and the spread contribution + var bullet_angle: float = group.angle_offset + if mirror: + bullet_angle = -group.angle_offset + if group.bullet_count >= 3: + var spread_contribution = (index_from_center / center_index) * (group.spread_angle / 2.0) + if mirror: + bullet_angle -= spread_contribution + else: + bullet_angle += spread_contribution + + # Position: apply horizontal offset and vertical origin from weapon data + bullet.position = player.position + Vector2(bullet_horizontal_offset, weapon_data.origin) + + # Timing: group delay + within-group stagger + var time_offset: float = group.group_delay + abs(index_from_center) * group.stagger_offset + + # Set timing properties on the bullet + bullet.time_offset = time_offset + bullet.fire_time = current_time + time_offset + bullet.angle = bullet_angle + + # 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) diff --git a/scripts/weapon_projectile_group.gd b/scripts/weapon_projectile_group.gd new file mode 100644 index 0000000..89b511e --- /dev/null +++ b/scripts/weapon_projectile_group.gd @@ -0,0 +1,21 @@ +class_name WeaponProjectileGroup +extends Resource + +@export_category("Group Settings") +@export var bullet_count: int = 3 +# Horizontal distance between bullets in this group +@export var horizontal_spacing: float = 6.5 +# Total spread angle for bullets in this group (in degrees) +@export var spread_angle: float = 0.0 +# Angle of the entire group from the shot origin (positive = right/up, negative = left) +@export var angle_offset: float = 0.0 +# Horizontal offset from the center line (positive = right, negative = left) +@export var horizontal_offset: float = 0.0 +@export_category("Timing") +# Time delay for this group's first bullet (relative to shot start) +@export var group_delay: float = 0.0 +# Stagger delay between bullets within this group +@export var stagger_offset: float = 0.25 +@export_category("Mirroring") +# If true, duplicate this group's bullets mirrored across the ship's vertical axis +@export var mirror: bool = false diff --git a/scripts/weapon_projectile_group.gd.uid b/scripts/weapon_projectile_group.gd.uid new file mode 100644 index 0000000..65a3b0d --- /dev/null +++ b/scripts/weapon_projectile_group.gd.uid @@ -0,0 +1 @@ +uid://d0ios82vubijg diff --git a/scripts/weapon_shot.gd b/scripts/weapon_shot.gd index c4d9bd7..a85e798 100644 --- a/scripts/weapon_shot.gd +++ b/scripts/weapon_shot.gd @@ -25,3 +25,6 @@ extends Resource @export var stagger_animation: bool = false # Rotate projectiles to point along their travel direction (requires >2 projectiles and spread_angle > 0) @export var follow_angle: bool = false + +@export_category("Grouped Projectiles") +@export var groups: Array[WeaponProjectileGroup] = [] From 6c5a0a0bae9905cde849e74bd0be8902c4c89861 Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 27 Jun 2026 13:28:38 +0100 Subject: [PATCH 31/37] Adjusted directory structure for clarity. --- resources/player_weapon_resources/patterns/phallanx.tres | 1 + scenes/EffectComponent.tscn | 2 +- scenes/player.tscn | 2 +- scripts/{effects => }/effects_component.gd | 0 scripts/{effects => }/effects_component.gd.uid | 0 5 files changed, 3 insertions(+), 2 deletions(-) rename scripts/{effects => }/effects_component.gd (100%) rename scripts/{effects => }/effects_component.gd.uid (100%) diff --git a/resources/player_weapon_resources/patterns/phallanx.tres b/resources/player_weapon_resources/patterns/phallanx.tres index 48f630f..a3937f2 100644 --- a/resources/player_weapon_resources/patterns/phallanx.tres +++ b/resources/player_weapon_resources/patterns/phallanx.tres @@ -9,3 +9,4 @@ angle_offset = 8.0 horizontal_offset = 20.0 group_delay = 0.25 stagger_offset = 0.5 +mirror = true diff --git a/scenes/EffectComponent.tscn b/scenes/EffectComponent.tscn index 5152fdf..e00466e 100644 --- a/scenes/EffectComponent.tscn +++ b/scenes/EffectComponent.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://bq3xhbfgkt22l"] -[ext_resource type="Script" uid="uid://65d3hbrpm21x" path="res://scripts/effects/effects_component.gd" id="1_ee0kt"] +[ext_resource type="Script" uid="uid://65d3hbrpm21x" path="res://scripts/effects_component.gd" id="1_ee0kt"] [node name="EffectsComponent" type="Node" unique_id=1393438576] script = ExtResource("1_ee0kt") diff --git a/scenes/player.tscn b/scenes/player.tscn index 92a9dc9..97df162 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -12,7 +12,7 @@ [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"] -[ext_resource type="Script" uid="uid://65d3hbrpm21x" path="res://scripts/effects/effects_component.gd" id="12_effcomp"] +[ext_resource type="Script" uid="uid://65d3hbrpm21x" path="res://scripts/effects_component.gd" id="12_effcomp"] [ext_resource type="Resource" uid="uid://ds53sryglmf27" path="res://resources/player_weapon_resources/spread.tres" id="13_f1ej7"] [ext_resource type="Resource" uid="uid://c41aoyka7nfr8" path="res://resources/player_weapon_resources/vanguard+.tres" id="14_oprun"] diff --git a/scripts/effects/effects_component.gd b/scripts/effects_component.gd similarity index 100% rename from scripts/effects/effects_component.gd rename to scripts/effects_component.gd diff --git a/scripts/effects/effects_component.gd.uid b/scripts/effects_component.gd.uid similarity index 100% rename from scripts/effects/effects_component.gd.uid rename to scripts/effects_component.gd.uid From 99a5d9838d6f31acfe7bdd6478bb23121c6d3150 Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 28 Jun 2026 01:45:11 +0100 Subject: [PATCH 32/37] Separated shot positioning math to helper utility and refactored shoot component - introduced shot origin issue. --- .../player_weapon_resources/patterns/fwd.tres | 1 + resources/player_weapon_resources/spread.tres | 3 +- resources/player_weapon_resources/stock.tres | 3 +- resources/player_weapon_resources/tri.tres | 3 +- .../player_weapon_resources/vanguard+.tres | 2 - .../player_weapon_resources/vanguard.tres | 3 +- scenes/player.tscn | 5 + scripts/event_bus.gd | 2 +- scripts/movement_component.gd | 2 +- scripts/notification_display.gd | 8 +- scripts/notification_manager.gd | 2 +- scripts/shoot_component.gd | 110 ++++++------------ scripts/weapon_component.gd | 2 +- scripts/weapon_fire_helper.gd | 88 ++++++++++++++ scripts/weapon_fire_helper.gd.uid | 1 + scripts/weapon_projectile_group.gd | 2 + scripts/weapon_shot.gd | 8 +- 17 files changed, 147 insertions(+), 98 deletions(-) create mode 100644 scripts/weapon_fire_helper.gd create mode 100644 scripts/weapon_fire_helper.gd.uid diff --git a/resources/player_weapon_resources/patterns/fwd.tres b/resources/player_weapon_resources/patterns/fwd.tres index 6008dfb..bba67ae 100644 --- a/resources/player_weapon_resources/patterns/fwd.tres +++ b/resources/player_weapon_resources/patterns/fwd.tres @@ -4,6 +4,7 @@ [resource] script = ExtResource("1_mhej7") +pattern_name = "fwd" bullet_count = 5 group_delay = 5.0 stagger_offset = 2.0 diff --git a/resources/player_weapon_resources/spread.tres b/resources/player_weapon_resources/spread.tres index 82ef411..bb4794c 100644 --- a/resources/player_weapon_resources/spread.tres +++ b/resources/player_weapon_resources/spread.tres @@ -2,6 +2,7 @@ [ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/player_weapons/weapon_stock.tscn" id="1_pn64g"] [ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://scripts/weapon_shot.gd" id="2_4b7mw"] +[ext_resource type="Script" uid="uid://d0ios82vubijg" path="res://scripts/weapon_projectile_group.gd" id="2_ak5x4"] [resource] script = ExtResource("2_4b7mw") @@ -10,8 +11,6 @@ bullet_scene = ExtResource("1_pn64g") damage = 5 speed = 720 projectiles = 5 -spacing = 100.0 -origin = -15 horizontal_offset = 8.25 spread_angle = 25.0 stagger_offset = 0.5 diff --git a/resources/player_weapon_resources/stock.tres b/resources/player_weapon_resources/stock.tres index d4d85bf..79f8f83 100644 --- a/resources/player_weapon_resources/stock.tres +++ b/resources/player_weapon_resources/stock.tres @@ -1,6 +1,7 @@ [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://d0ios82vubijg" path="res://scripts/weapon_projectile_group.gd" id="2_e245k"] [ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://scripts/weapon_shot.gd" id="2_ym48c"] [resource] @@ -9,8 +10,6 @@ shot_name = "stock" bullet_scene = ExtResource("1_lcw6o") damage = 2 speed = 650 -spacing = 25.0 -origin = -15 horizontal_offset = 12.0 stagger_offset = 0.0 metadata/_custom_type_script = "uid://7n1itonn35fm" diff --git a/resources/player_weapon_resources/tri.tres b/resources/player_weapon_resources/tri.tres index f1ca45d..c16b614 100644 --- a/resources/player_weapon_resources/tri.tres +++ b/resources/player_weapon_resources/tri.tres @@ -1,6 +1,7 @@ [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://d0ios82vubijg" path="res://scripts/weapon_projectile_group.gd" id="2_bhv8k"] [ext_resource type="Script" uid="uid://7n1itonn35fm" path="res://scripts/weapon_shot.gd" id="2_syw6j"] [resource] @@ -10,8 +11,6 @@ bullet_scene = ExtResource("1_07hyh") damage = 3 speed = 700 projectiles = 3 -spacing = 45.0 -origin = -15 horizontal_offset = 12.5 stagger_offset = 0.35 stagger_animation = true diff --git a/resources/player_weapon_resources/vanguard+.tres b/resources/player_weapon_resources/vanguard+.tres index 4d2d490..294d890 100644 --- a/resources/player_weapon_resources/vanguard+.tres +++ b/resources/player_weapon_resources/vanguard+.tres @@ -12,8 +12,6 @@ bullet_scene = ExtResource("1_lqlv8") damage = 5 speed = 500 projectiles = 5 -spacing = 30.0 -origin = -15 horizontal_offset = 8.25 stagger_offset = 0.5 stagger_animation = true diff --git a/resources/player_weapon_resources/vanguard.tres b/resources/player_weapon_resources/vanguard.tres index dcb3580..006c9a5 100644 --- a/resources/player_weapon_resources/vanguard.tres +++ b/resources/player_weapon_resources/vanguard.tres @@ -2,6 +2,7 @@ [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"] +[ext_resource type="Script" uid="uid://d0ios82vubijg" path="res://scripts/weapon_projectile_group.gd" id="2_xf183"] [resource] script = ExtResource("2_w7xlm") @@ -10,8 +11,6 @@ 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 diff --git a/scenes/player.tscn b/scenes/player.tscn index 97df162..c240cfb 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -10,6 +10,7 @@ [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://znfh8unmdxkvv" path="res://scripts/weapon_fire_helper.gd" id="15_firehelper"] [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"] [ext_resource type="Script" uid="uid://65d3hbrpm21x" path="res://scripts/effects_component.gd" id="12_effcomp"] @@ -151,6 +152,10 @@ player = NodePath("..") speed = 200.0 metadata/_custom_type_script = "uid://c0rikbakpcags" +[node name="WeaponFireHelper" type="Node" parent="." unique_id=623642426] +unique_name_in_owner = true +script = ExtResource("15_firehelper") + [node name="ShootComponent" type="Node" parent="." unique_id=623642425] unique_name_in_owner = true script = ExtResource("6_y4r1p") diff --git a/scripts/event_bus.gd b/scripts/event_bus.gd index fc12a05..07bd2b5 100644 --- a/scripts/event_bus.gd +++ b/scripts/event_bus.gd @@ -2,6 +2,6 @@ extends Node @warning_ignore_start("unused_signal") # since otherwise Godot will throw a warning that the signal is unused in current scope -signal weapon_changed(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: float) +signal weapon_changed(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: Vector2) @warning_ignore_restore("unused_signal") diff --git a/scripts/movement_component.gd b/scripts/movement_component.gd index 84c9a57..921c2d6 100644 --- a/scripts/movement_component.gd +++ b/scripts/movement_component.gd @@ -22,7 +22,7 @@ func tick(delta: float): # Calculate ship to bullet displacement player.ship_displacement = player.position.y - player.previous_position.y player.travel += abs(weapon_system.speed) * delta + (player.ship_displacement) - player.travel = clamp(player.travel, 0, 1.9 * weapon_system.spacing) + player.travel = clamp(player.travel, 0, 1.9 * weapon_system.projectile_vertical_spacing) # Thruster animation in relation to player movement if input.x > 0: diff --git a/scripts/notification_display.gd b/scripts/notification_display.gd index 4dbbc48..38622e0 100644 --- a/scripts/notification_display.gd +++ b/scripts/notification_display.gd @@ -6,7 +6,7 @@ class_name NotificationDisplay extends Control var _player: Node2D = null var _sprite_size: Vector2 = Vector2.ZERO -var _origin_offset: float = 0.0 +var _origin_offset: Vector2 = Vector2.ZERO var _follow_player: bool = false var _connector_line: Line2D = null @@ -23,7 +23,7 @@ func _ready() -> void: _container.add_theme_constant_override("margin_right", 4) -func show_notification(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: float) -> void: +func show_notification(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: Vector2) -> void: modulate.a = 0.0 label.add_theme_font_size_override("font_size", 8) @@ -107,7 +107,7 @@ func _update_position() -> void: var player_pos = _player.position # Y position uses the weapon origin offset from player center - var notif_y = player_pos.y + _origin_offset - (size.y / 2.0) + var notif_y = player_pos.y + _origin_offset.y - (size.y / 2.0) # X position is 10px to the right of player's sprite edge var right_edge = player_pos.x + (_sprite_size.x / 2.0) @@ -164,7 +164,7 @@ func _update_connector() -> void: # Point 2: player's origin + ENDPOINT_OFFSET, converted to notification's local space const ENDPOINT_OFFSET = Vector2(4, 7) # offset from player's origin to connector endpoint - var target = _player.position + Vector2(+ENDPOINT_OFFSET.x, _origin_offset + ENDPOINT_OFFSET.y) + var target = _player.position + Vector2(+ENDPOINT_OFFSET.x, _origin_offset.y + ENDPOINT_OFFSET.y) var point2 = target - position _connector_line.points = PackedVector2Array([point0, point1, point2]) diff --git a/scripts/notification_manager.gd b/scripts/notification_manager.gd index eb8028e..cc60141 100644 --- a/scripts/notification_manager.gd +++ b/scripts/notification_manager.gd @@ -8,7 +8,7 @@ func _ready() -> void: EventBus.weapon_changed.connect(_on_weapon_changed) -func _on_weapon_changed(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: float) -> void: +func _on_weapon_changed(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: Vector2) -> void: if notification_scene == null: return diff --git a/scripts/shoot_component.gd b/scripts/shoot_component.gd index 789970d..96a02ee 100644 --- a/scripts/shoot_component.gd +++ b/scripts/shoot_component.gd @@ -2,12 +2,14 @@ class_name ShootComponent extends Node @onready var weapon_component: Node = %WeaponComponent @onready var player = $".." +@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 - if player.travel > weapon_data.spacing: + if player.travel > weapon_data.projectile_vertical_spacing: _shoot_standard(weapon_data, current_time) _shoot_grouped(weapon_data, current_time) @@ -15,105 +17,61 @@ func shoot(): player.travel = 0.0 -# Standard projectile logic (backward compatible) +# Standard projectile logic (delegates to WeaponFireHelper) func _shoot_standard(weapon_data: WeaponShot, current_time: float): - var total_projectiles = weapon_data.projectiles - var center_index = (total_projectiles - 1) / 2.0 + var total_projectiles: int = weapon_data.projectiles if total_projectiles > 0: for b in range(total_projectiles): 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 (center-first, pairs outward) - var time_offset: float = abs(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 - - # Calculate vertical offset from center point (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(bullet_horizontal_offset, weapon_data.origin + (vertical_offset + weapon_data.origin - total_projectiles)) - - # Calculate angle for this bullet (only when projectiles >= 3) - var bullet_angle: float = 0.0 - if total_projectiles >= 3: - bullet_angle = (index_from_center / center_index) * (weapon_data.spread_angle / 2.0) - - # Set timing properties on the bullet - bullet.time_offset = time_offset - bullet.fire_time = current_time + time_offset - bullet.angle = bullet_angle + # Delegate math to the helper, with spawn position offset by sprite height and weapon origin + var spawn_position = ship.global_position + Vector2(0, ship.get_texture().get_height() / 2.0) + weapon_data.origin + var props = 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 + bullet.fire_time = props.fire_time # 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) + bullet.set_animation_offset(props.animation_offset) -# Grouped projectile logic (new functionality) +# Grouped projectile logic (delegates to WeaponFireHelper) func _shoot_grouped(weapon_data: WeaponShot, current_time: float): 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) - _fire_grouped_bullet(bullet, group, b, current_time, weapon_data, false) + # Apply computed properties for the original bullet + var spawn_position = ship.global_position + Vector2(0, ship.get_texture().get_height() / 2.0) + weapon_data.origin + var props = 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 + bullet.fire_time = props.fire_time + bullet.set_weapon_data(weapon_data.bullet_scene, weapon_data) + if weapon_data.stagger_animation: + bullet.set_animation_offset(props.animation_offset) # If mirroring is enabled, fire a mirrored copy if group.mirror: var mirror_bullet := weapon_data.bullet_scene.instantiate() as Area2D get_tree().root.add_child(mirror_bullet) - _fire_grouped_bullet(mirror_bullet, group, b, current_time, weapon_data, true) - -# Fire a single grouped bullet (original or mirrored) -func _fire_grouped_bullet(bullet: Area2D, group: WeaponProjectileGroup, b: int, - current_time: float, weapon_data: WeaponShot, mirror: bool): - # Calculate index relative to this group's center - var center_index: float = (group.bullet_count - 1) / 2.0 - var index_from_center: float = b - center_index - - # Horizontal offset: group offset + within-group spread - # Mirror: negate the horizontal offset contribution - var bullet_horizontal_offset: float = group.horizontal_offset + index_from_center * group.horizontal_spacing - if mirror: - bullet_horizontal_offset = -bullet_horizontal_offset - - # Base angle for the group, plus within-group spread - # Mirror: negate the angle and the spread contribution - var bullet_angle: float = group.angle_offset - if mirror: - bullet_angle = -group.angle_offset - if group.bullet_count >= 3: - var spread_contribution = (index_from_center / center_index) * (group.spread_angle / 2.0) - if mirror: - bullet_angle -= spread_contribution - else: - bullet_angle += spread_contribution - - # Position: apply horizontal offset and vertical origin from weapon data - bullet.position = player.position + Vector2(bullet_horizontal_offset, weapon_data.origin) - - # Timing: group delay + within-group stagger - var time_offset: float = group.group_delay + abs(index_from_center) * group.stagger_offset - - # Set timing properties on the bullet - bullet.time_offset = time_offset - bullet.fire_time = current_time + time_offset - bullet.angle = bullet_angle - - # 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) + # Apply computed properties for the mirrored bullet + var mirror_spawn = ship.global_position + Vector2(0, ship.get_texture().get_height() / 2.0) + weapon_data.origin + var mirror_props = 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 + mirror_bullet.fire_time = mirror_props.fire_time + mirror_bullet.set_weapon_data(weapon_data.bullet_scene, weapon_data) + if weapon_data.stagger_animation: + mirror_bullet.set_animation_offset(mirror_props.animation_offset) diff --git a/scripts/weapon_component.gd b/scripts/weapon_component.gd index 9e09f6e..3dd3497 100644 --- a/scripts/weapon_component.gd +++ b/scripts/weapon_component.gd @@ -21,7 +21,7 @@ func _ready() -> void: func _emit_weapon_changed() -> void: var ship: Sprite2D = get_parent().get_node("Ship") var sprite_size = ship.get_rect().size - var origin_offset: int = weapon_data.origin if weapon_data else 0 + var origin_offset: Vector2 = weapon_data.origin if weapon_data else Vector2.ZERO EventBus.weapon_changed.emit(weapon_data.shot_name, get_parent(), sprite_size, origin_offset) diff --git a/scripts/weapon_fire_helper.gd b/scripts/weapon_fire_helper.gd new file mode 100644 index 0000000..b5a080d --- /dev/null +++ b/scripts/weapon_fire_helper.gd @@ -0,0 +1,88 @@ +class_name WeaponFireHelper extends Node + + +## Compute bullet properties for a standard shot. +## Returns a Dictionary with: position, angle, fire_time, time_offset, index_from_center, animation_offset +func compute_standard_props(weapon_data: WeaponShot, projectile_index: int, spawn_position: Vector2, current_time: float) -> Dictionary: + var total_projectiles: int = weapon_data.projectiles + var center_index: float = (total_projectiles - 1) / 2.0 + + var index_from_center: float = projectile_index - center_index + + # Horizontal offset (symmetrical: left=-ve, right=+ve) + var bullet_horizontal_offset: float = index_from_center * weapon_data.horizontal_offset + + # Timing: center-first, pairs outward + var time_offset: float = abs(index_from_center) * weapon_data.stagger_offset + + # Vertical offset: outer projectiles are spaced relative to center, preserving the pattern geometry. + var vertical_offset: float = (abs(index_from_center) * weapon_data.projectile_vertical_spacing) / 2.0 + var position: Vector2 = spawn_position + Vector2(bullet_horizontal_offset, vertical_offset) + + # Angle (only when projectiles >= 3, division-by-zero guard) + var bullet_angle: float = 0.0 + if total_projectiles >= 3: + bullet_angle = (index_from_center / center_index) * (weapon_data.spread_angle / 2.0) + + # Fire time + var fire_time: float = current_time + time_offset + + # Animation offset (if staggered animation is enabled) + var animation_offset: float = index_from_center * weapon_data.stagger_offset + + return { + "position": position, + "angle": bullet_angle, + "fire_time": fire_time, + "time_offset": time_offset, + "index_from_center": index_from_center, + "animation_offset": animation_offset, + } + + +## Compute bullet properties for a grouped shot, with optional mirroring. +## Returns a Dictionary with: position, angle, fire_time, time_offset, index_from_center, animation_offset +func compute_grouped_props(group: WeaponProjectileGroup, weapon_data: WeaponShot, + bullet_index: int, spawn_position: Vector2, current_time: float, + mirror: bool = false) -> Dictionary: + var center_index: float = (group.bullet_count - 1) / 2.0 + var index_from_center: float = bullet_index - center_index + + # Horizontal offset: group offset + within-group spread + var bullet_horizontal_offset: float = group.horizontal_offset + index_from_center * group.horizontal_spacing + if mirror: + bullet_horizontal_offset = -bullet_horizontal_offset + + # Base angle: group angle (negated when mirrored) + within-group spread + var bullet_angle: float = group.angle_offset + if mirror: + bullet_angle = -group.angle_offset + + # Symmetrical spread (guard against < 3 bullets) + if group.bullet_count >= 3: + var spread_contribution = (index_from_center / center_index) * (group.spread_angle / 2.0) + if mirror: + bullet_angle -= spread_contribution + else: + bullet_angle += spread_contribution + + # Position: horizontal offset only (vertical position comes from spawn_position) + var position: Vector2 = spawn_position + Vector2(bullet_horizontal_offset, 0) + + # Timing: group delay + within-group stagger + var time_offset: float = group.group_delay + abs(index_from_center) * group.stagger_offset + + # Fire time + var fire_time: float = current_time + time_offset + + # Animation offset (if staggered animation is enabled) + var animation_offset: float = index_from_center * weapon_data.stagger_offset + + return { + "position": position, + "angle": bullet_angle, + "fire_time": fire_time, + "time_offset": time_offset, + "index_from_center": index_from_center, + "animation_offset": animation_offset, + } diff --git a/scripts/weapon_fire_helper.gd.uid b/scripts/weapon_fire_helper.gd.uid new file mode 100644 index 0000000..7261b18 --- /dev/null +++ b/scripts/weapon_fire_helper.gd.uid @@ -0,0 +1 @@ +uid://bpcv2ojtyityc diff --git a/scripts/weapon_projectile_group.gd b/scripts/weapon_projectile_group.gd index 89b511e..3e7f6a3 100644 --- a/scripts/weapon_projectile_group.gd +++ b/scripts/weapon_projectile_group.gd @@ -1,6 +1,8 @@ class_name WeaponProjectileGroup extends Resource +@export_category("Identification") +@export var pattern_name: String = "" @export_category("Group Settings") @export var bullet_count: int = 3 # Horizontal distance between bullets in this group diff --git a/scripts/weapon_shot.gd b/scripts/weapon_shot.gd index a85e798..1cc91ea 100644 --- a/scripts/weapon_shot.gd +++ b/scripts/weapon_shot.gd @@ -7,10 +7,10 @@ extends Resource @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 +# Vertical spacing between projectiles when firing continuously +@export var projectile_vertical_spacing: float = 35 +# Spawn offset from center of player (x is usually 0, y controls vertical fire position) +@export var origin: Vector2 = Vector2(0, -25) @export_category("Spread") # Horizontal distance between projectiles From 64e685a3c173552cb536e58c7adfcb2bdcc0b148 Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 28 Jun 2026 02:38:02 +0100 Subject: [PATCH 33/37] Still a lille buggy! But closer. --- scripts/shoot_component.gd | 8 ++++---- scripts/weapon_fire_helper.gd | 6 ++++-- scripts/weapon_shot.gd | 13 +++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/scripts/shoot_component.gd b/scripts/shoot_component.gd index 96a02ee..90b2344 100644 --- a/scripts/shoot_component.gd +++ b/scripts/shoot_component.gd @@ -26,8 +26,8 @@ func _shoot_standard(weapon_data: WeaponShot, current_time: float): var bullet := weapon_data.bullet_scene.instantiate() as Area2D get_tree().root.add_child(bullet) - # Delegate math to the helper, with spawn position offset by sprite height and weapon origin - var spawn_position = ship.global_position + Vector2(0, ship.get_texture().get_height() / 2.0) + weapon_data.origin + # Delegate math to the helper, with spawn position offset by weapon origin + var spawn_position = ship.global_position + weapon_data.origin var props = fire_helper.compute_standard_props(weapon_data, b, spawn_position, current_time) bullet.position = props.position bullet.angle = props.angle @@ -50,7 +50,7 @@ func _shoot_grouped(weapon_data: WeaponShot, current_time: float): get_tree().root.add_child(bullet) # Apply computed properties for the original bullet - var spawn_position = ship.global_position + Vector2(0, ship.get_texture().get_height() / 2.0) + weapon_data.origin + var spawn_position = ship.global_position + weapon_data.origin var props = fire_helper.compute_grouped_props(group, weapon_data, b, spawn_position, current_time, false) bullet.position = props.position bullet.angle = props.angle @@ -66,7 +66,7 @@ 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 = ship.global_position + Vector2(0, ship.get_texture().get_height() / 2.0) + weapon_data.origin + var mirror_spawn = ship.global_position + weapon_data.origin var mirror_props = 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 diff --git a/scripts/weapon_fire_helper.gd b/scripts/weapon_fire_helper.gd index b5a080d..5d7b788 100644 --- a/scripts/weapon_fire_helper.gd +++ b/scripts/weapon_fire_helper.gd @@ -15,9 +15,11 @@ func compute_standard_props(weapon_data: WeaponShot, projectile_index: int, spaw # Timing: center-first, pairs outward var time_offset: float = abs(index_from_center) * weapon_data.stagger_offset - # Vertical offset: outer projectiles are spaced relative to center, preserving the pattern geometry. + # Vertical spacing creates the ^ (inverted-V) geometry: outer projectiles fire higher + # than the center projectile. Negate the offset so outer bullets are pushed upward + # (lower y values in Godot), creating a ^ pattern relative to the origin. var vertical_offset: float = (abs(index_from_center) * weapon_data.projectile_vertical_spacing) / 2.0 - var position: Vector2 = spawn_position + Vector2(bullet_horizontal_offset, vertical_offset) + var position: Vector2 = spawn_position + Vector2(bullet_horizontal_offset, -vertical_offset) # Angle (only when projectiles >= 3, division-by-zero guard) var bullet_angle: float = 0.0 diff --git a/scripts/weapon_shot.gd b/scripts/weapon_shot.gd index 1cc91ea..66c946b 100644 --- a/scripts/weapon_shot.gd +++ b/scripts/weapon_shot.gd @@ -7,9 +7,18 @@ extends Resource @export var damage: int = 1 @export var speed: int = 135 @export var projectiles: int = 2 -# Vertical spacing between projectiles when firing continuously +# Vertical spacing between projectiles in a burst (used by WeaponFireHelper to compute the ^ pattern). +# This controls spatial burst geometry, NOT temporal spacing between continuous fire bursts. @export var projectile_vertical_spacing: float = 35 -# Spawn offset from center of player (x is usually 0, y controls vertical fire position) +# Spawn offset strictly relative to the ship node's global position (origin). +# This offset is measured from the ship node's center, not the sprite texture. +# x is usually 0 (horizontal centering), y controls vertical fire position. +# Negative Y moves bullets "above" the ship (in front of it); positive Y +# moves them "below" (behind it). The default of (0, -25) places the burst +# 25 pixels above (in front of) the ship center. +# All weapon resources in this project use the default. Custom weapons with +# explicit origin.y > 0 (positive) will have their burst pattern appear +# behind or below the ship -- verify visually if adjusting. @export var origin: Vector2 = Vector2(0, -25) @export_category("Spread") From 9554af183ce3f8ecfcd90334d198b10bc74d72e9 Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 28 Jun 2026 08:05:30 +0100 Subject: [PATCH 34/37] Updated the bullet spawning position to beging from the sprite height modified by the weapon's origin variable. --- scripts/event_bus.gd | 2 +- scripts/notification_display.gd | 8 ++++---- scripts/notification_manager.gd | 2 +- scripts/shoot_component.gd | 21 +++++++++++++++++---- scripts/weapon_component.gd | 2 +- scripts/weapon_fire_helper.gd | 15 +++++++++------ scripts/weapon_shot.gd | 15 +++++---------- 7 files changed, 38 insertions(+), 27 deletions(-) diff --git a/scripts/event_bus.gd b/scripts/event_bus.gd index 07bd2b5..fc12a05 100644 --- a/scripts/event_bus.gd +++ b/scripts/event_bus.gd @@ -2,6 +2,6 @@ extends Node @warning_ignore_start("unused_signal") # since otherwise Godot will throw a warning that the signal is unused in current scope -signal weapon_changed(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: Vector2) +signal weapon_changed(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: float) @warning_ignore_restore("unused_signal") diff --git a/scripts/notification_display.gd b/scripts/notification_display.gd index 38622e0..4dbbc48 100644 --- a/scripts/notification_display.gd +++ b/scripts/notification_display.gd @@ -6,7 +6,7 @@ class_name NotificationDisplay extends Control var _player: Node2D = null var _sprite_size: Vector2 = Vector2.ZERO -var _origin_offset: Vector2 = Vector2.ZERO +var _origin_offset: float = 0.0 var _follow_player: bool = false var _connector_line: Line2D = null @@ -23,7 +23,7 @@ func _ready() -> void: _container.add_theme_constant_override("margin_right", 4) -func show_notification(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: Vector2) -> void: +func show_notification(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: float) -> void: modulate.a = 0.0 label.add_theme_font_size_override("font_size", 8) @@ -107,7 +107,7 @@ func _update_position() -> void: var player_pos = _player.position # Y position uses the weapon origin offset from player center - var notif_y = player_pos.y + _origin_offset.y - (size.y / 2.0) + var notif_y = player_pos.y + _origin_offset - (size.y / 2.0) # X position is 10px to the right of player's sprite edge var right_edge = player_pos.x + (_sprite_size.x / 2.0) @@ -164,7 +164,7 @@ func _update_connector() -> void: # Point 2: player's origin + ENDPOINT_OFFSET, converted to notification's local space const ENDPOINT_OFFSET = Vector2(4, 7) # offset from player's origin to connector endpoint - var target = _player.position + Vector2(+ENDPOINT_OFFSET.x, _origin_offset.y + ENDPOINT_OFFSET.y) + var target = _player.position + Vector2(+ENDPOINT_OFFSET.x, _origin_offset + ENDPOINT_OFFSET.y) var point2 = target - position _connector_line.points = PackedVector2Array([point0, point1, point2]) diff --git a/scripts/notification_manager.gd b/scripts/notification_manager.gd index cc60141..eb8028e 100644 --- a/scripts/notification_manager.gd +++ b/scripts/notification_manager.gd @@ -8,7 +8,7 @@ func _ready() -> void: EventBus.weapon_changed.connect(_on_weapon_changed) -func _on_weapon_changed(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: Vector2) -> void: +func _on_weapon_changed(weapon_name: String, player_node: Node2D, player_sprite_size: Vector2, origin_offset: float) -> void: if notification_scene == null: return diff --git a/scripts/shoot_component.gd b/scripts/shoot_component.gd index 90b2344..bf783c1 100644 --- a/scripts/shoot_component.gd +++ b/scripts/shoot_component.gd @@ -17,6 +17,19 @@ func shoot(): player.travel = 0.0 +func _get_spawn_position(weapon_data: WeaponShot) -> Vector2: + # Determine sprite height with a region_rect → texture fallback. + var sprite_height: float = 0.0 + if ship.region_rect.has_area(): + sprite_height = ship.region_rect.size.y + else: + 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) + 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): var total_projectiles: int = weapon_data.projectiles @@ -26,8 +39,8 @@ func _shoot_standard(weapon_data: WeaponShot, current_time: float): var bullet := weapon_data.bullet_scene.instantiate() as Area2D get_tree().root.add_child(bullet) - # Delegate math to the helper, with spawn position offset by weapon origin - var spawn_position = ship.global_position + weapon_data.origin + # 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) bullet.position = props.position bullet.angle = props.angle @@ -50,7 +63,7 @@ func _shoot_grouped(weapon_data: WeaponShot, current_time: float): get_tree().root.add_child(bullet) # Apply computed properties for the original bullet - var spawn_position = ship.global_position + weapon_data.origin + var spawn_position = _get_spawn_position(weapon_data) var props = fire_helper.compute_grouped_props(group, weapon_data, b, spawn_position, current_time, false) bullet.position = props.position bullet.angle = props.angle @@ -66,7 +79,7 @@ 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 = ship.global_position + weapon_data.origin + 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) mirror_bullet.position = mirror_props.position mirror_bullet.angle = mirror_props.angle diff --git a/scripts/weapon_component.gd b/scripts/weapon_component.gd index 3dd3497..1442102 100644 --- a/scripts/weapon_component.gd +++ b/scripts/weapon_component.gd @@ -21,7 +21,7 @@ func _ready() -> void: func _emit_weapon_changed() -> void: var ship: Sprite2D = get_parent().get_node("Ship") var sprite_size = ship.get_rect().size - var origin_offset: Vector2 = weapon_data.origin if weapon_data else Vector2.ZERO + var origin_offset: float = weapon_data.origin if weapon_data else 0.0 EventBus.weapon_changed.emit(weapon_data.shot_name, get_parent(), sprite_size, origin_offset) diff --git a/scripts/weapon_fire_helper.gd b/scripts/weapon_fire_helper.gd index 5d7b788..8b6777a 100644 --- a/scripts/weapon_fire_helper.gd +++ b/scripts/weapon_fire_helper.gd @@ -15,11 +15,11 @@ func compute_standard_props(weapon_data: WeaponShot, projectile_index: int, spaw # Timing: center-first, pairs outward var time_offset: float = abs(index_from_center) * weapon_data.stagger_offset - # Vertical spacing creates the ^ (inverted-V) geometry: outer projectiles fire higher - # than the center projectile. Negate the offset so outer bullets are pushed upward - # (lower y values in Godot), creating a ^ pattern relative to the origin. + # Vertical spacing creates the ^ (inverted-V) geometry: outer projectiles fire lower + # (higher Y values, further from the player) than the center projectile, which sits + # higher on screen (lower Y values). This creates a ^ pattern relative to the origin. var vertical_offset: float = (abs(index_from_center) * weapon_data.projectile_vertical_spacing) / 2.0 - var position: Vector2 = spawn_position + Vector2(bullet_horizontal_offset, -vertical_offset) + var position: Vector2 = spawn_position + Vector2(bullet_horizontal_offset, +vertical_offset) # Angle (only when projectiles >= 3, division-by-zero guard) var bullet_angle: float = 0.0 @@ -68,8 +68,11 @@ func compute_grouped_props(group: WeaponProjectileGroup, weapon_data: WeaponShot else: bullet_angle += spread_contribution - # Position: horizontal offset only (vertical position comes from spawn_position) - var position: Vector2 = spawn_position + Vector2(bullet_horizontal_offset, 0) + # Vertical spacing creates the ^ (inverted-V) geometry: outer projectiles fire lower + # (higher Y values, further from the player) than the center projectile, which sits + # higher on screen (lower Y values). This creates a ^ pattern relative to the origin. + var vertical_offset: float = (abs(index_from_center) * weapon_data.projectile_vertical_spacing) / 2.0 + var position: Vector2 = spawn_position + Vector2(bullet_horizontal_offset, +vertical_offset) # Timing: group delay + within-group stagger var time_offset: float = group.group_delay + abs(index_from_center) * group.stagger_offset diff --git a/scripts/weapon_shot.gd b/scripts/weapon_shot.gd index 66c946b..04ed7a2 100644 --- a/scripts/weapon_shot.gd +++ b/scripts/weapon_shot.gd @@ -10,16 +10,11 @@ extends Resource # Vertical spacing between projectiles in a burst (used by WeaponFireHelper to compute the ^ pattern). # This controls spatial burst geometry, NOT temporal spacing between continuous fire bursts. @export var projectile_vertical_spacing: float = 35 -# Spawn offset strictly relative to the ship node's global position (origin). -# This offset is measured from the ship node's center, not the sprite texture. -# x is usually 0 (horizontal centering), y controls vertical fire position. -# Negative Y moves bullets "above" the ship (in front of it); positive Y -# moves them "below" (behind it). The default of (0, -25) places the burst -# 25 pixels above (in front of) the ship center. -# All weapon resources in this project use the default. Custom weapons with -# explicit origin.y > 0 (positive) will have their burst pattern appear -# behind or below the ship -- verify visually if adjusting. -@export var origin: Vector2 = Vector2(0, -25) +# Vertical offset from the top of the player's sprite where bullets spawn. +# Measured in pixels; negative values fire in front of (above) the ship, +# positive values fire behind (below) it. The default of -25 places the +# burst 25 pixels above the sprite's top edge. +@export var origin: float = -25.0 @export_category("Spread") # Horizontal distance between projectiles From a655f9332f0a0d5a2e5a11028e7a37fb5f507206 Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 28 Jun 2026 18:11:26 +0100 Subject: [PATCH 35/37] Further refinements in weapone fire helper logic. --- .../player_weapon_resources/vanguard+.tres | 1 + scripts/weapon_fire_helper.gd | 52 ++++++++++++++++--- scripts/weapon_shot.gd | 13 ++++- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/resources/player_weapon_resources/vanguard+.tres b/resources/player_weapon_resources/vanguard+.tres index 294d890..1e62887 100644 --- a/resources/player_weapon_resources/vanguard+.tres +++ b/resources/player_weapon_resources/vanguard+.tres @@ -14,6 +14,7 @@ speed = 500 projectiles = 5 horizontal_offset = 8.25 stagger_offset = 0.5 +compensate_spawn_geometry = true stagger_animation = true follow_angle = true groups = Array[ExtResource("2_qeb4b")]([ExtResource("3_qeb4b")]) diff --git a/scripts/weapon_fire_helper.gd b/scripts/weapon_fire_helper.gd index 8b6777a..6da3c5d 100644 --- a/scripts/weapon_fire_helper.gd +++ b/scripts/weapon_fire_helper.gd @@ -15,17 +15,34 @@ func compute_standard_props(weapon_data: WeaponShot, projectile_index: int, spaw # Timing: center-first, pairs outward var time_offset: float = abs(index_from_center) * weapon_data.stagger_offset - # Vertical spacing creates the ^ (inverted-V) geometry: outer projectiles fire lower - # (higher Y values, further from the player) than the center projectile, which sits - # higher on screen (lower Y values). This creates a ^ pattern relative to the origin. - var vertical_offset: float = (abs(index_from_center) * weapon_data.projectile_vertical_spacing) / 2.0 - var position: Vector2 = spawn_position + Vector2(bullet_horizontal_offset, +vertical_offset) - # Angle (only when projectiles >= 3, division-by-zero guard) + # Moved before vertical offset to support compensation var bullet_angle: float = 0.0 if total_projectiles >= 3: bullet_angle = (index_from_center / center_index) * (weapon_data.spread_angle / 2.0) + # Vertical spacing creates the ^ (inverted-V) geometry: outer projectiles fire lower + # (higher Y values, further from the player) than the center projectile, which sits + # higher on screen (lower Y values). This creates a ^ pattern relative to the origin. + # When compensate_spawn_geometry is enabled and spread_angle > 0, compute vertical + # offsets to align the geometric spread with velocity vectors. + var vertical_offset: float + if weapon_data.compensate_spawn_geometry and weapon_data.spread_angle > 0 and total_projectiles >= 3: + var velocity_angle_rad: float = abs(bullet_angle) * PI / 180.0 + if index_from_center == 0: + # Center bullet in compensated mode: use full projectile_vertical_spacing + # so the V-shape stays visually smooth (center = 35, outer ≈ 75) + # instead of a broken gap (center = 8.75, outer ≈ 75). + vertical_offset = weapon_data.projectile_vertical_spacing + elif velocity_angle_rad > 0.1: # Guard against division by zero for very small angles + vertical_offset = abs(bullet_horizontal_offset) / tan(velocity_angle_rad) + else: + # Very small angle: fall back to full spacing + vertical_offset = weapon_data.projectile_vertical_spacing + else: + vertical_offset = (abs(index_from_center) * weapon_data.projectile_vertical_spacing) / 2.0 + var position: Vector2 = spawn_position + Vector2(bullet_horizontal_offset, +vertical_offset) + # Fire time var fire_time: float = current_time + time_offset @@ -61,8 +78,9 @@ func compute_grouped_props(group: WeaponProjectileGroup, weapon_data: WeaponShot bullet_angle = -group.angle_offset # Symmetrical spread (guard against < 3 bullets) + var spread_contribution: float = 0.0 if group.bullet_count >= 3: - var spread_contribution = (index_from_center / center_index) * (group.spread_angle / 2.0) + spread_contribution = (index_from_center / center_index) * (group.spread_angle / 2.0) if mirror: bullet_angle -= spread_contribution else: @@ -71,7 +89,25 @@ func compute_grouped_props(group: WeaponProjectileGroup, weapon_data: WeaponShot # Vertical spacing creates the ^ (inverted-V) geometry: outer projectiles fire lower # (higher Y values, further from the player) than the center projectile, which sits # higher on screen (lower Y values). This creates a ^ pattern relative to the origin. - var vertical_offset: float = (abs(index_from_center) * weapon_data.projectile_vertical_spacing) / 2.0 + # When compensate_spawn_geometry is enabled and group.spread_angle > 0, compute + # vertical offsets to preserve the within-group V-shape independently of + # angle_offset, which handles global tilt. + # + # angle_offset tilts the entire group — mixing it into the compensation formula + # breaks the V-shape because the formula assumes velocity vectors converge at the + # origin, but with angle_offset > 0 they fan out from an offset line instead. + # Solution: calculate compensation using only within-group parameters. + var vertical_offset: float + if weapon_data.compensate_spawn_geometry and group.spread_angle > 0 and group.bullet_count >= 3 and index_from_center != 0: + var within_group_angle: float = abs(spread_contribution) # exclude angle_offset + var within_group_angle_rad: float = within_group_angle * PI / 180.0 + var within_group_horizontal: float = abs(index_from_center * group.horizontal_spacing) # exclude group.horizontal_offset + if within_group_angle_rad > 0.1: # Guard against division by zero for very small angles + vertical_offset = within_group_horizontal / tan(within_group_angle_rad) + else: + vertical_offset = (abs(index_from_center) * weapon_data.projectile_vertical_spacing) / 2.0 + else: + vertical_offset = (abs(index_from_center) * weapon_data.projectile_vertical_spacing) / 2.0 var position: Vector2 = spawn_position + Vector2(bullet_horizontal_offset, +vertical_offset) # Timing: group delay + within-group stagger diff --git a/scripts/weapon_shot.gd b/scripts/weapon_shot.gd index 04ed7a2..7d641f8 100644 --- a/scripts/weapon_shot.gd +++ b/scripts/weapon_shot.gd @@ -8,7 +8,10 @@ extends Resource @export var speed: int = 135 @export var projectiles: int = 2 # Vertical spacing between projectiles in a burst (used by WeaponFireHelper to compute the ^ pattern). -# This controls spatial burst geometry, NOT temporal spacing between continuous fire bursts. +# This parameter has a dual role: spatial (computing the ^ burst geometry) and temporal +# (serving as the burst-gating threshold in ShootComponent.shoot()). When compensate_spawn_geometry +# is enabled, this parameter is overridden by geometric compensation for spatial calculations; +# temporal behavior remains unchanged and continues to use this value. @export var projectile_vertical_spacing: float = 35 # Vertical offset from the top of the player's sprite where bullets spawn. # Measured in pixels; negative values fire in front of (above) the ship, @@ -23,6 +26,14 @@ extends Resource @export var spread_angle: float = 0.0 # Time delay per projectile index @export var stagger_offset: float = 0.25 +# When enabled, adjusts spawn vertical offsets so the geometric line +# from the center bullet to each outer bullet matches their velocity +# direction. Eliminates the optical illusion where the spread appears +# wider than the actual bullet trajectories (e.g. spread.tres flies at +# half the angle it visually appears to fan). + +## WARNING: This flag uses a trigonometric formula (horizontal_offset / tan(angle)) that evaluates independently-tuned horizontal and spread angles in grouped shots ONLY! +@export var compensate_spawn_geometry: bool = false @export_category("Effects") # Offset animation playback per projectile index From fa882502b468ea89e67c6bf69a31a5eaf790d242 Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 28 Jun 2026 18:27:47 +0100 Subject: [PATCH 36/37] Updated comments for clarity. --- scripts/weapon_shot.gd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/weapon_shot.gd b/scripts/weapon_shot.gd index 7d641f8..3bd9e3e 100644 --- a/scripts/weapon_shot.gd +++ b/scripts/weapon_shot.gd @@ -29,8 +29,8 @@ extends Resource # When enabled, adjusts spawn vertical offsets so the geometric line # from the center bullet to each outer bullet matches their velocity # direction. Eliminates the optical illusion where the spread appears -# wider than the actual bullet trajectories (e.g. spread.tres flies at -# half the angle it visually appears to fan). +# wider than the actual bullet trajectories (e.g. vanguard+). See the +# Debugging Checklist for the vertical offset pitfall on standard shots. ## WARNING: This flag uses a trigonometric formula (horizontal_offset / tan(angle)) that evaluates independently-tuned horizontal and spread angles in grouped shots ONLY! @export var compensate_spawn_geometry: bool = false From 1ac71cc104ff04ef23bcc5844fbc850edac89f81 Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 29 Jun 2026 14:59:40 +0100 Subject: [PATCH 37/37] Updated exported weapon variables for cleaner organization in the Godot inspector. --- scripts/weapon_shot.gd | 77 +++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 19 deletions(-) diff --git a/scripts/weapon_shot.gd b/scripts/weapon_shot.gd index 3bd9e3e..8abc83d 100644 --- a/scripts/weapon_shot.gd +++ b/scripts/weapon_shot.gd @@ -1,45 +1,84 @@ class_name WeaponShot extends Resource -@export_category("Parameters") + +@export_group("Weapon") + + +# Human-readable name for reference in UI and logs. @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 + +# PackedScene reference to the bullet / projectile scene instantiated on fire. +@export var bullet_scene: PackedScene + + +@export_subgroup("Launch") + + +# Damage dealt by a single projectile instance. +@export_range(1, 100, 1) var damage: int = 1 + +# Travel speed of projectiles in pixels per second. +@export_range(50, 2000, 10) var speed: int = 135 + +# Number of projectiles fired in a burst pattern. +@export_range(1, 20, 1) var projectiles: int = 2 + + +@export_subgroup("Spawn Geometry") + + # Vertical spacing between projectiles in a burst (used by WeaponFireHelper to compute the ^ pattern). # This parameter has a dual role: spatial (computing the ^ burst geometry) and temporal # (serving as the burst-gating threshold in ShootComponent.shoot()). When compensate_spawn_geometry # is enabled, this parameter is overridden by geometric compensation for spatial calculations; # temporal behavior remains unchanged and continues to use this value. -@export var projectile_vertical_spacing: float = 35 +@export_range(10, 200, 0.5) var projectile_vertical_spacing: float = 35 + # Vertical offset from the top of the player's sprite where bullets spawn. # Measured in pixels; negative values fire in front of (above) the ship, # positive values fire behind (below) it. The default of -25 places the # burst 25 pixels above the sprite's top edge. -@export var origin: float = -25.0 +@export_range(-200, 200, 0.5) var origin: float = -25.0 + + +@export_subgroup("Spread") + + +# Horizontal distance between adjacent projectiles in a burst. +@export_range(0, 100, 0.25) var horizontal_offset: float = 6.5 + +# Total spread angle in degrees (only applied when projectiles >= 3). +@export_range(0, 360, 0.5) var spread_angle: float = 0.0 + +# Time delay per projectile index in a burst. +@export_range(0.01, 5.0, 0.05) var stagger_offset: float = 0.25 -@export_category("Spread") -# Horizontal distance between projectiles -@export var horizontal_offset: float = 6.5 -# Total spread angle in degrees (only applied when projectiles >= 3) -@export var spread_angle: float = 0.0 -# Time delay per projectile index -@export var stagger_offset: float = 0.25 # When enabled, adjusts spawn vertical offsets so the geometric line # from the center bullet to each outer bullet matches their velocity # direction. Eliminates the optical illusion where the spread appears # wider than the actual bullet trajectories (e.g. vanguard+). See the # Debugging Checklist for the vertical offset pitfall on standard shots. - ## WARNING: This flag uses a trigonometric formula (horizontal_offset / tan(angle)) that evaluates independently-tuned horizontal and spread angles in grouped shots ONLY! @export var compensate_spawn_geometry: bool = false -@export_category("Effects") -# Offset animation playback per projectile index + +@export_subgroup("Timing") + + +# Offset animation playback per projectile index. @export var stagger_animation: bool = false -# Rotate projectiles to point along their travel direction (requires >2 projectiles and spread_angle > 0) + + +@export_subgroup("Effects") + + +# Rotate projectiles to point along their travel direction (requires >2 projectiles and spread_angle > 0). @export var follow_angle: bool = false -@export_category("Grouped Projectiles") + +@export_subgroup("Groups") + + +# Array of projectile groups defining layered, multi-directional fire patterns. @export var groups: Array[WeaponProjectileGroup] = []