Add explosion effect to explosive component and implement cleanup functionality

This commit is contained in:
2025-05-01 21:06:26 +02:00
parent ebfd5f0e60
commit 8c9afeee27
6 changed files with 72 additions and 6 deletions

View File

@@ -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="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/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/damage_component.gd" id="3_y0uai"]
[ext_resource type="Script" path="res://scripts/components/explosive_component.gd" id="4_8lw0n"] [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"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ar0xf"]
size = Vector2(16, 10) size = Vector2(16, 10)
@@ -50,6 +51,7 @@ root = NodePath("..")
damage = NodePath("../DamageComponent") damage = NodePath("../DamageComponent")
area2d = NodePath("..") area2d = NodePath("..")
explosion_area2d = NodePath("../Explosion area") explosion_area2d = NodePath("../Explosion area")
explosion_effect = ExtResource("5_6oopj")
[node name="Explosion area" type="Area2D" parent="."] [node name="Explosion area" type="Area2D" parent="."]
collision_layer = 0 collision_layer = 0
@@ -57,3 +59,6 @@ collision_mask = 9
[node name="CollisionShape2D" type="CollisionShape2D" parent="Explosion area"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Explosion area"]
shape = SubResource("CircleShape2D_e6vaq") shape = SubResource("CircleShape2D_e6vaq")
[node name="ExplosionFX" parent="." instance=ExtResource("5_6oopj")]
randomness = 0.24

52
objects/explosion_fx.tscn Normal file
View File

@@ -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"]

View File

@@ -2,7 +2,7 @@
[sub_resource type="Gradient" id="Gradient_5woy1"] [sub_resource type="Gradient" id="Gradient_5woy1"]
offsets = PackedFloat32Array(0, 0.173759, 0.521277, 0.687943, 0.886525, 1) 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"] [sub_resource type="GradientTexture1D" id="GradientTexture1D_mar4t"]
gradient = SubResource("Gradient_5woy1") gradient = SubResource("Gradient_5woy1")

View File

@@ -0,0 +1,8 @@
class_name CleanUpComponent
extends Node
@export var root: Node
func clean_up() -> void:
root.queue_free()

View File

@@ -39,9 +39,10 @@ func explode() -> void:
timer.stop() timer.stop()
if explosion_effect: if explosion_effect:
var effect: Node2D = explosion_effect.instantiate() var explosion_instance: GPUParticles2D = explosion_effect.instantiate()
root.get_parent().add_child(effect) explosion_instance.global_position = root.global_position
effect.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() var bodies: Array = explosion_area2d.get_overlapping_bodies()
for body in bodies: for body in bodies:

View File

@@ -7,5 +7,5 @@ shader = ExtResource("1_a47lf")
shader_parameter/shine_color = Color(1, 1, 1, 1) shader_parameter/shine_color = Color(1, 1, 1, 1)
shader_parameter/shine_speed = -1.0 shader_parameter/shine_speed = -1.0
shader_parameter/shine_size = 0.011 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 shader_parameter/shine_angle_deg = 45.0