Jelajahi Sumber

:tada: Create a brick impact particle effect

DricomDragon 2 tahun lalu
induk
melakukan
a842f6701c

+ 3 - 0
godot/component/entity/brick/Brick.gd

@@ -5,6 +5,7 @@ extends StaticBody2D
 signal kace_broken
 signal kace_damaged
 signal life_changed
+signal impact
 
 
 const MAX_LIFE := 1999
@@ -37,3 +38,5 @@ func blow_up() -> void:
 
 func impact(pos: Vector2) -> void:
 	damage()
+	var local_pos = to_local(pos)
+	emit_signal("impact", local_pos)

+ 6 - 2
godot/component/entity/brick/Brick.tscn

@@ -1,10 +1,11 @@
-[gd_scene load_steps=7 format=2]
+[gd_scene load_steps=8 format=2]
 
 [ext_resource path="res://component/entity/brick/color_brik.png" type="Texture" id=1]
 [ext_resource path="res://component/entity/brick/Brick.gd" type="Script" id=2]
 [ext_resource path="res://component/entity/brick/BrickMainColor.gd" type="Script" id=3]
 [ext_resource path="res://component/entity/brick/BrickLifeDisplay.gd" type="Script" id=4]
 [ext_resource path="res://component/entity/brick/common_brick.png" type="Texture" id=5]
+[ext_resource path="res://effect/particle/impact/Impact.tscn" type="PackedScene" id=6]
 
 [sub_resource type="RectangleShape2D" id=1]
 extents = Vector2( 20, 10 )
@@ -25,11 +26,14 @@ script = ExtResource( 3 )
 texture = ExtResource( 1 )
 centered = false
 
+[node name="ImpactSplash" parent="MainColor" instance=ExtResource( 6 )]
+
 [node name="Shape" type="CollisionShape2D" parent="."]
 position = Vector2( 20, 10 )
 shape = SubResource( 1 )
 
 [node name="LifeDisplay" type="Node2D" parent="."]
 script = ExtResource( 4 )
-[connection signal="life_changed" from="." to="MainColor" method="_on_Brick_life_changed"]
+[connection signal="impact" from="." to="MainColor/ImpactSplash" method="splash_at"]
 [connection signal="life_changed" from="." to="LifeDisplay" method="_on_Brick_life_changed"]
+[connection signal="life_changed" from="." to="MainColor" method="_on_Brick_life_changed"]

+ 7 - 0
godot/effect/particle/impact/Impact.gd

@@ -0,0 +1,7 @@
+class_name ImpactSplash
+extends Particles2D
+
+
+func splash_at(pos: Vector2):
+	position = pos
+	restart()

+ 15 - 0
godot/effect/particle/impact/Impact.tscn

@@ -0,0 +1,15 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://effect/particle/impact/impact_particle.png" type="Texture" id=1]
+[ext_resource path="res://effect/particle/impact/ImpactMaterial.tres" type="Material" id=2]
+[ext_resource path="res://effect/particle/impact/Impact.gd" type="Script" id=3]
+
+[node name="ImpactSplash" type="Particles2D"]
+emitting = false
+lifetime = 0.5
+one_shot = true
+explosiveness = 1.0
+local_coords = false
+process_material = ExtResource( 2 )
+texture = ExtResource( 1 )
+script = ExtResource( 3 )

+ 23 - 0
godot/effect/particle/impact/ImpactMaterial.tres

@@ -0,0 +1,23 @@
+[gd_resource type="ParticlesMaterial" load_steps=3 format=2]
+
+[sub_resource type="Curve" id=1]
+_data = [ Vector2( 0, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), -2.90747, 0.0, 0, 0 ]
+
+[sub_resource type="CurveTexture" id=2]
+curve = SubResource( 1 )
+
+[resource]
+flag_disable_z = true
+spread = 180.0
+gravity = Vector3( 0, 0, 0 )
+initial_velocity = 50.0
+initial_velocity_random = 0.11
+angular_velocity = 100.0
+angular_velocity_random = 1.0
+orbit_velocity = 0.0
+orbit_velocity_random = 0.0
+damping = 54.21
+damping_random = 0.38
+angle = 90.0
+angle_random = 1.0
+scale_curve = SubResource( 2 )

TEMPAT SAMPAH
godot/effect/particle/impact/impact_particle.png


+ 34 - 0
godot/effect/particle/impact/impact_particle.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/impact_particle.png-6a9f5858e3cddca10fa5d37432ca578f.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://effect/particle/impact/impact_particle.png"
+dest_files=[ "res://.import/impact_particle.png-6a9f5858e3cddca10fa5d37432ca578f.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=true
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+stream=false
+size_limit=0
+detect_3d=true
+svg/scale=1.0

+ 6 - 0
godot/project.godot

@@ -49,6 +49,11 @@ _global_script_classes=[ {
 "language": "GDScript",
 "path": "res://component/entity/brick/Grid.gd"
 }, {
+"base": "Particles2D",
+"class": "ImpactSplash",
+"language": "GDScript",
+"path": "res://effect/particle/impact/Impact.gd"
+}, {
 "base": "Node2D",
 "class": "Launcher",
 "language": "GDScript",
@@ -83,6 +88,7 @@ _global_script_class_icons={
 "ColorUtil": "",
 "DeadLine": "",
 "Grid": "",
+"ImpactSplash": "",
 "Launcher": "",
 "MessagePanel": "",
 "NumberPanel": "",