From 8c9afeee27b29fe10cc0040484116966edec5f9a Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 1 May 2025 21:06:26 +0200 Subject: [PATCH] Add explosion effect to explosive component and implement cleanup functionality --- objects/exploding_brick.tscn | 7 ++- objects/explosion_fx.tscn | 52 +++++++++++++++++++++++ objects/fire_fx.tscn | 2 +- scripts/components/cleanup_component.gd | 8 ++++ scripts/components/explosive_component.gd | 7 +-- shaders/shine_shader.tres | 2 +- 6 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 objects/explosion_fx.tscn create mode 100644 scripts/components/cleanup_component.gd diff --git a/objects/exploding_brick.tscn b/objects/exploding_brick.tscn index 7e07589..38ee7e0 100644 --- a/objects/exploding_brick.tscn +++ b/objects/exploding_brick.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=7 format=3 uid="uid://5surx230gfw3"] +[gd_scene load_steps=8 format=3 uid="uid://5surx230gfw3"] [ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_rcgxf"] [ext_resource type="Script" path="res://scripts/components/bullet.gd" id="2_1i2y5"] [ext_resource type="Script" path="res://scripts/components/damage_component.gd" id="3_y0uai"] [ext_resource type="Script" path="res://scripts/components/explosive_component.gd" id="4_8lw0n"] +[ext_resource type="PackedScene" uid="uid://dyp4i4ru2j2jh" path="res://objects/explosion_fx.tscn" id="5_6oopj"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ar0xf"] size = Vector2(16, 10) @@ -50,6 +51,7 @@ root = NodePath("..") damage = NodePath("../DamageComponent") area2d = NodePath("..") explosion_area2d = NodePath("../Explosion area") +explosion_effect = ExtResource("5_6oopj") [node name="Explosion area" type="Area2D" parent="."] collision_layer = 0 @@ -57,3 +59,6 @@ collision_mask = 9 [node name="CollisionShape2D" type="CollisionShape2D" parent="Explosion area"] shape = SubResource("CircleShape2D_e6vaq") + +[node name="ExplosionFX" parent="." instance=ExtResource("5_6oopj")] +randomness = 0.24 diff --git a/objects/explosion_fx.tscn b/objects/explosion_fx.tscn new file mode 100644 index 0000000..6103db1 --- /dev/null +++ b/objects/explosion_fx.tscn @@ -0,0 +1,52 @@ +[gd_scene load_steps=9 format=3 uid="uid://dyp4i4ru2j2jh"] + +[ext_resource type="Script" path="res://scripts/components/cleanup_component.gd" id="1_8uvxg"] + +[sub_resource type="Curve" id="Curve_8umf8"] +_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0.4), 0.0, 0.0, 0, 0] +point_count = 2 + +[sub_resource type="CurveTexture" id="CurveTexture_w18ti"] +curve = SubResource("Curve_8umf8") + +[sub_resource type="Gradient" id="Gradient_5woy1"] +offsets = PackedFloat32Array(0, 0.173759, 0.521277, 0.687943, 0.886525, 1) +colors = PackedColorArray(0.635294, 0.188235, 0, 1, 0.890196, 0.317647, 0, 1, 1, 0.470588, 0.188235, 1, 1, 0.635294, 0, 1, 1, 0.858824, 0.635294, 1, 1, 1, 1, 0.501961) + +[sub_resource type="GradientTexture1D" id="GradientTexture1D_f0o3s"] +gradient = SubResource("Gradient_5woy1") + +[sub_resource type="Curve" id="Curve_0bqc3"] +_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0.1), 0.0, 0.0, 0, 0] +point_count = 2 + +[sub_resource type="CurveTexture" id="CurveTexture_w0m05"] +curve = SubResource("Curve_0bqc3") + +[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_1ujje"] +particle_flag_disable_z = true +emission_shape_scale = Vector3(0.5, 0.5, 0.5) +spread = 180.0 +initial_velocity_min = 32.0 +initial_velocity_max = 32.0 +angular_velocity_min = 41.62 +angular_velocity_max = 41.62 +gravity = Vector3(0, 0, 0) +scale_curve = SubResource("CurveTexture_w0m05") +color_ramp = SubResource("GradientTexture1D_f0o3s") +alpha_curve = SubResource("CurveTexture_w18ti") + +[node name="ExplosionFX" type="GPUParticles2D"] +emitting = false +amount = 2048 +process_material = SubResource("ParticleProcessMaterial_1ujje") +lifetime = 0.5 +one_shot = true +explosiveness = 1.0 +fixed_fps = 24 + +[node name="CleanUpComponent" type="Node" parent="." node_paths=PackedStringArray("root")] +script = ExtResource("1_8uvxg") +root = NodePath("..") + +[connection signal="finished" from="." to="CleanUpComponent" method="clean_up"] diff --git a/objects/fire_fx.tscn b/objects/fire_fx.tscn index 639932b..ecedb95 100644 --- a/objects/fire_fx.tscn +++ b/objects/fire_fx.tscn @@ -2,7 +2,7 @@ [sub_resource type="Gradient" id="Gradient_5woy1"] offsets = PackedFloat32Array(0, 0.173759, 0.521277, 0.687943, 0.886525, 1) -colors = PackedColorArray(0.635294, 0.188235, 0, 1, 0.890196, 0.317647, 0, 1, 1, 0.470588, 0.188235, 1, 1, 0.635294, 0, 1, 1, 0.858824, 0.635294, 1, 1, 1, 1, 1) +colors = PackedColorArray(0.635294, 0.188235, 0, 1, 0.890196, 0.317647, 0, 1, 1, 0.470588, 0.188235, 1, 1, 0.635294, 0, 1, 1, 0.858824, 0.635294, 1, 1, 1, 1, 0.501961) [sub_resource type="GradientTexture1D" id="GradientTexture1D_mar4t"] gradient = SubResource("Gradient_5woy1") diff --git a/scripts/components/cleanup_component.gd b/scripts/components/cleanup_component.gd new file mode 100644 index 0000000..29ce3da --- /dev/null +++ b/scripts/components/cleanup_component.gd @@ -0,0 +1,8 @@ +class_name CleanUpComponent +extends Node + +@export var root: Node + + +func clean_up() -> void: + root.queue_free() \ No newline at end of file diff --git a/scripts/components/explosive_component.gd b/scripts/components/explosive_component.gd index 9a411b5..ecc5c60 100644 --- a/scripts/components/explosive_component.gd +++ b/scripts/components/explosive_component.gd @@ -39,9 +39,10 @@ func explode() -> void: timer.stop() if explosion_effect: - var effect: Node2D = explosion_effect.instantiate() - root.get_parent().add_child(effect) - effect.global_position = root.global_position + var explosion_instance: GPUParticles2D = explosion_effect.instantiate() + explosion_instance.global_position = root.global_position + get_tree().current_scene.add_child(explosion_instance) + explosion_instance.emitting = true var bodies: Array = explosion_area2d.get_overlapping_bodies() for body in bodies: diff --git a/shaders/shine_shader.tres b/shaders/shine_shader.tres index 6599468..243f80b 100644 --- a/shaders/shine_shader.tres +++ b/shaders/shine_shader.tres @@ -7,5 +7,5 @@ shader = ExtResource("1_a47lf") shader_parameter/shine_color = Color(1, 1, 1, 1) shader_parameter/shine_speed = -1.0 shader_parameter/shine_size = 0.011 -shader_parameter/shine_frequency = 3.0 +shader_parameter/shine_frequency = 1.0 shader_parameter/shine_angle_deg = 45.0