spark particles when an arrow collides with tiles or is blocked

This commit is contained in:
Haze Weathers 2023-01-21 00:05:40 -05:00
parent 7abd3fbb42
commit 30d7e84a46
2 changed files with 43 additions and 1 deletions

View file

@ -35,6 +35,7 @@ func _exit_tree():
#Wall Collision #Wall Collision
func _on_Hitbox_body_entered(body): func _on_Hitbox_body_entered(body):
if body is TileMap or body is StaticBody2D: if body is TileMap or body is StaticBody2D:
_make_sparks()
queue_free() queue_free()
# kill entity if in target group # kill entity if in target group
@ -46,6 +47,7 @@ func _on_Hitbox_area_entered(area):
if area.is_in_group("blocks_arrow"): if area.is_in_group("blocks_arrow"):
var pos = target.global_position var pos = target.global_position
Game.instance_node(Game.block_text, pos.x, pos.y, target.get_parent()) Game.instance_node(Game.block_text, pos.x, pos.y, target.get_parent())
_make_sparks()
else: else:
# kill targeted node # kill targeted node
target.die() target.die()
@ -53,3 +55,12 @@ func _on_Hitbox_area_entered(area):
if target_group == "enemy_hitbox": if target_group == "enemy_hitbox":
Game.arrows = max(0, Game.arrows - 1) # clamp arrows above 0 Game.arrows = max(0, Game.arrows - 1) # clamp arrows above 0
queue_free() queue_free()
func _make_sparks():
var particles = $SparkParticles
remove_child(particles)
particles.global_position = global_position + particles.position * scale.x
particles.emitting = true
get_parent().add_child(particles)
var timer = get_tree().create_timer(particles.lifetime, false)
timer.connect("timeout", particles, "queue_free")

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=2] [gd_scene load_steps=13 format=2]
[ext_resource path="res://scripts/1px_border.gdshader" type="Shader" id=1] [ext_resource path="res://scripts/1px_border.gdshader" type="Shader" id=1]
[ext_resource path="res://graphics/player/arrow.png" type="Texture" id=2] [ext_resource path="res://graphics/player/arrow.png" type="Texture" id=2]
@ -35,6 +35,28 @@ scale_curve = SubResource( 4 )
[sub_resource type="RectangleShape2D" id=2] [sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 5.5, 3.5 ) extents = Vector2( 5.5, 3.5 )
[sub_resource type="Curve" id=6]
_data = [ Vector2( 0, 1 ), 0.0, -1.45746, 0, 0, Vector2( 1, 0 ), 0.00323196, 0.0, 0, 0 ]
[sub_resource type="CurveTexture" id=7]
width = 32
curve = SubResource( 6 )
[sub_resource type="ParticlesMaterial" id=8]
flag_disable_z = true
spread = 180.0
gravity = Vector3( 0, 0, 0 )
initial_velocity = 30.0
initial_velocity_random = 0.5
orbit_velocity = 0.0
orbit_velocity_random = 0.0
damping = 50.0
angle = 720.0
angle_random = 1.0
scale = 0.3
scale_curve = SubResource( 7 )
color = Color( 1, 1, 0.290196, 1 )
[node name="ArrowProjectile" type="Node2D"] [node name="ArrowProjectile" type="Node2D"]
script = ExtResource( 3 ) script = ExtResource( 3 )
@ -59,5 +81,14 @@ collision_layer = 0
position = Vector2( -0.5, -0.5 ) position = Vector2( -0.5, -0.5 )
shape = SubResource( 2 ) shape = SubResource( 2 )
[node name="SparkParticles" type="Particles2D" parent="."]
position = Vector2( 4, 0 )
emitting = false
amount = 16
lifetime = 0.5
explosiveness = 1.0
process_material = SubResource( 8 )
texture = ExtResource( 4 )
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"] [connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]
[connection signal="body_entered" from="Hitbox" to="." method="_on_Hitbox_body_entered"] [connection signal="body_entered" from="Hitbox" to="." method="_on_Hitbox_body_entered"]