From 6c41810add506469efcf1f252f5d980dca8d675d Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 20 Jun 2026 16:08:40 +0100 Subject: [PATCH] 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