From a65d08599f233c7f766d56faa4ab84c42fae941f Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Sat, 14 Dec 2024 13:37:36 -0700 Subject: [PATCH] Extracted ball collection particle lagic into HUDParticle type --- asset_dev/balls/ball_icons.xcf | Bin 16269 -> 16269 bytes assets/sprites/particles/ball.png | 3 + assets/sprites/particles/ball.png.import | 34 ++++++++++ src/items/extra_ball/extra_ball.gd | 2 +- src/items/item/item.gd | 8 --- .../hud_particles/hud_particles.gd | 22 +++++++ .../hud_particles/hud_particles.tscn | 50 +++++++++++++++ src/ui/shot_hud/shot_hud.gd | 9 +-- src/ui/shot_hud/shot_hud.tscn | 59 ++---------------- 9 files changed, 116 insertions(+), 71 deletions(-) create mode 100644 assets/sprites/particles/ball.png create mode 100644 assets/sprites/particles/ball.png.import create mode 100644 src/ui/decorations/hud_particles/hud_particles.gd create mode 100644 src/ui/decorations/hud_particles/hud_particles.tscn diff --git a/asset_dev/balls/ball_icons.xcf b/asset_dev/balls/ball_icons.xcf index d706fed2d82bf39c244765f1c9fc206c784564ea..1840d2282c5090af39d7e44b3ad6e7212d1d2d27 100644 GIT binary patch delta 21 ccmeCJ@2#KU#MrdaSw(pA592kPg+;2g0b{!ef&c&j delta 23 ecmeCJ@2#KU#8|M=Sw)zUadJP?>dnF;RoVb&JqOnS diff --git a/assets/sprites/particles/ball.png b/assets/sprites/particles/ball.png new file mode 100644 index 0000000..e9201a4 --- /dev/null +++ b/assets/sprites/particles/ball.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7148f37820cfc5e8a525aaa31a4167548a7357337289ef8cbad6935d27f9a957 +size 817 diff --git a/assets/sprites/particles/ball.png.import b/assets/sprites/particles/ball.png.import new file mode 100644 index 0000000..969df76 --- /dev/null +++ b/assets/sprites/particles/ball.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dtsdecae83ah3" +path="res://.godot/imported/ball.png-9141da4d584001e11280d9c246b59589.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/sprites/particles/ball.png" +dest_files=["res://.godot/imported/ball.png-9141da4d584001e11280d9c246b59589.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=true +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +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/src/items/extra_ball/extra_ball.gd b/src/items/extra_ball/extra_ball.gd index 72c7f82..8f92743 100644 --- a/src/items/extra_ball/extra_ball.gd +++ b/src/items/extra_ball/extra_ball.gd @@ -13,4 +13,4 @@ func _collect(player: WorldPlayer) -> void: player.mutate_balls(ball_type, amount) player.shot_setup.hud.peek_club_selector() - player.shot_setup.hud.emit_ball_particles(maxi(amount, 1), screen_location()) + player.shot_setup.hud.ball_particles.emit_spatial(maxi(amount, 1), global_position) diff --git a/src/items/item/item.gd b/src/items/item/item.gd index 1ab3376..890f551 100644 --- a/src/items/item/item.gd +++ b/src/items/item/item.gd @@ -10,14 +10,6 @@ signal on_collect(player: WorldPlayer) @onready var explosion_player: AnimationPlayer = %ExplosionPlayer -## Relative location of this item in screen coordinates. -## Useful for particle effects -func screen_location() -> Vector2: - var location := get_viewport().get_camera_3d().unproject_position(global_position) - # TODO: what if this is off-screen? - return location - - func collect(player: WorldPlayer) -> void: # Note that this animation will call `queue_free` in 5 seconds! explosion_player.play("explode") diff --git a/src/ui/decorations/hud_particles/hud_particles.gd b/src/ui/decorations/hud_particles/hud_particles.gd new file mode 100644 index 0000000..d6f2823 --- /dev/null +++ b/src/ui/decorations/hud_particles/hud_particles.gd @@ -0,0 +1,22 @@ +class_name HUDParticles extends GPUParticles2D +## 2D particle emitter with spatial logic, for emitting particles in the HUD. + + +## Emit the given number of particles in one shot. +func emit(_amount: int) -> void: + amount = _amount + emitting = true + + +## Emit the given number of particles from the given screen location. +func emit_at_location(_amount: int, source_location: Vector2) -> void: + var particle_mat: ParticleProcessMaterial = process_material + particle_mat.emission_shape_offset = Vector3(source_location.x, source_location.y, 0) + emit(_amount) + + +## Emit the given number of particles from the screen location of the given point in 3D space. +func emit_spatial(_amount: int, source_location: Vector3) -> void: + var screen_location := get_viewport().get_camera_3d().unproject_position(source_location) + # TODO: what to do if this is outside the viewport? + emit_at_location(_amount, screen_location) diff --git a/src/ui/decorations/hud_particles/hud_particles.tscn b/src/ui/decorations/hud_particles/hud_particles.tscn new file mode 100644 index 0000000..289de3d --- /dev/null +++ b/src/ui/decorations/hud_particles/hud_particles.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=9 format=3 uid="uid://dfh0bv7lwewj5"] + +[ext_resource type="Script" path="res://src/ui/decorations/hud_particles/hud_particles.gd" id="1_leh7k"] + +[sub_resource type="Curve" id="Curve_mp3bg"] +max_value = 100.0 +_data = [Vector2(0.0431211, 0), 0.0, 21.2919, 0, 0, Vector2(1, 100), 336.968, 0.0, 0, 0] +point_count = 2 + +[sub_resource type="CurveTexture" id="CurveTexture_satut"] +curve = SubResource("Curve_mp3bg") + +[sub_resource type="Curve" id="Curve_a5ydw"] +max_value = 200.0 +_data = [Vector2(0, 9.02831), 0.0, 0.618766, 0, 0, Vector2(1, 200), 450.985, 0.0, 0, 0] +point_count = 2 + +[sub_resource type="CurveTexture" id="CurveTexture_oynpa"] +curve = SubResource("Curve_a5ydw") + +[sub_resource type="Curve" id="Curve_53gso"] +_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.0616016, 1), 0.0, 0.0, 0, 0, Vector2(0.761807, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] +point_count = 4 + +[sub_resource type="CurveTexture" id="CurveTexture_a05qh"] +curve = SubResource("Curve_53gso") + +[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_besmx"] +particle_flag_disable_z = true +direction = Vector3(0, 0, 0) +spread = 180.0 +initial_velocity_min = 400.0 +initial_velocity_max = 600.0 +gravity = Vector3(0, 0, 0) +radial_accel_min = -100.0 +radial_accel_max = -100.0 +radial_accel_curve = SubResource("CurveTexture_oynpa") +damping_min = 200.0 +damping_max = 200.0 +damping_curve = SubResource("CurveTexture_satut") +scale_curve = SubResource("CurveTexture_a05qh") + +[node name="HUDParticles" type="GPUParticles2D"] +emitting = false +amount = 32 +process_material = SubResource("ParticleProcessMaterial_besmx") +lifetime = 1.4 +one_shot = true +explosiveness = 0.7 +script = ExtResource("1_leh7k") diff --git a/src/ui/shot_hud/shot_hud.gd b/src/ui/shot_hud/shot_hud.gd index c5edf8d..f9a4989 100644 --- a/src/ui/shot_hud/shot_hud.gd +++ b/src/ui/shot_hud/shot_hud.gd @@ -16,7 +16,7 @@ var player: WorldPlayer @onready var club_selector: ClubSelector = %ClubSelector @onready var ball_selector: BallSelector = %BallSelector -@onready var _ball_particles: GPUParticles2D = %BallParticles +@onready var ball_particles: HUDParticles = %BallParticles @onready var _curve_animation: AnimationPlayer = %CurveAnimation @onready var _power_animation: AnimationPlayer = %PowerAnimation @@ -110,13 +110,6 @@ func hide_reset_prompt() -> void: _reset_prompt_animation.play_backwards("show") -func emit_ball_particles(amount: int, location: Vector2) -> void: - var particle_mat: ParticleProcessMaterial = _ball_particles.process_material - particle_mat.emission_shape_offset = Vector3(location.x, location.y, 0) - _ball_particles.amount = amount - _ball_particles.emitting = true - - ## Set the value of the life bar, potentially playing some kind of effect in response. ## ## To set the life bar without triggering an effect, set it directly with `life_bar.value` diff --git a/src/ui/shot_hud/shot_hud.tscn b/src/ui/shot_hud/shot_hud.tscn index 79a2124..b0a8564 100644 --- a/src/ui/shot_hud/shot_hud.tscn +++ b/src/ui/shot_hud/shot_hud.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=49 format=3 uid="uid://c4ifdiohng830"] +[gd_scene load_steps=44 format=3 uid="uid://c4ifdiohng830"] [ext_resource type="Script" path="res://src/ui/shot_hud/shot_hud.gd" id="1_x5b4c"] [ext_resource type="Shader" path="res://src/shaders/canvas_retro.gdshader" id="1_ybxxp"] @@ -12,6 +12,8 @@ [ext_resource type="FontFile" uid="uid://dsa0oh7c0h4pu" path="res://assets/fonts/Racing_Sans_One/RacingSansOne-Regular.ttf" id="8_bejx4"] [ext_resource type="Texture2D" uid="uid://tancoet1lih5" path="res://assets/ui/ball_icons/basic_icon.png" id="8_tt8i3"] [ext_resource type="PackedScene" uid="uid://dmciuk3pbjsae" path="res://src/ui/shot_hud/life_bar/life_bar.tscn" id="9_w1fiw"] +[ext_resource type="PackedScene" uid="uid://dfh0bv7lwewj5" path="res://src/ui/decorations/hud_particles/hud_particles.tscn" id="11_ie5ih"] +[ext_resource type="Texture2D" uid="uid://dtsdecae83ah3" path="res://assets/sprites/particles/ball.png" id="12_fdbqt"] [ext_resource type="PackedScene" uid="uid://b47goj32i6sdh" path="res://src/ui/elements/input_prompt/input_prompt.tscn" id="14_ik4gg"] [sub_resource type="Animation" id="Animation_2gt87"] @@ -324,51 +326,6 @@ _data = { "show": SubResource("Animation_x6kyr") } -[sub_resource type="Curve" id="Curve_mp3bg"] -max_value = 100.0 -_data = [Vector2(0.0431211, 0), 0.0, 21.2919, 0, 0, Vector2(1, 100), 336.968, 0.0, 0, 0] -point_count = 2 - -[sub_resource type="CurveTexture" id="CurveTexture_satut"] -curve = SubResource("Curve_mp3bg") - -[sub_resource type="Curve" id="Curve_a5ydw"] -max_value = 200.0 -_data = [Vector2(0, 9.02831), 0.0, 0.618766, 0, 0, Vector2(1, 200), 450.985, 0.0, 0, 0] -point_count = 2 - -[sub_resource type="CurveTexture" id="CurveTexture_oynpa"] -curve = SubResource("Curve_a5ydw") - -[sub_resource type="Curve" id="Curve_53gso"] -_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.0616016, 1), 0.0, 0.0, 0, 0, Vector2(0.761807, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] -point_count = 4 - -[sub_resource type="CurveTexture" id="CurveTexture_a05qh"] -curve = SubResource("Curve_53gso") - -[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_besmx"] -particle_flag_disable_z = true -emission_shape_offset = Vector3(800, 600, 0) -angle_min = -720.0 -angle_max = 720.0 -direction = Vector3(0, 0, 0) -spread = 180.0 -initial_velocity_min = 400.0 -initial_velocity_max = 600.0 -angular_velocity_min = -100.0 -angular_velocity_max = 100.0 -gravity = Vector3(0, 0, 0) -radial_accel_min = -100.0 -radial_accel_max = -100.0 -radial_accel_curve = SubResource("CurveTexture_oynpa") -damping_min = 200.0 -damping_max = 200.0 -damping_curve = SubResource("CurveTexture_satut") -scale_min = 0.4 -scale_max = 0.4 -scale_curve = SubResource("CurveTexture_a05qh") - [sub_resource type="Animation" id="Animation_3cn2c"] resource_name = "RESET" length = 0.001 @@ -787,15 +744,9 @@ anchor_bottom = 0.5 grow_horizontal = 2 grow_vertical = 2 -[node name="BallParticles" type="GPUParticles2D" parent="ClubSelector/TextureRect/BallParticleContainer"] +[node name="BallParticles" parent="ClubSelector/TextureRect/BallParticleContainer" instance=ExtResource("11_ie5ih")] unique_name_in_owner = true -emitting = false -amount = 32 -process_material = SubResource("ParticleProcessMaterial_besmx") -texture = ExtResource("8_tt8i3") -lifetime = 1.4 -one_shot = true -explosiveness = 0.7 +texture = ExtResource("12_fdbqt") [node name="SouthWest" type="MarginContainer" parent="."] layout_mode = 1