From 30d7e84a465920c47a7f30fbb29e24d75c30f891 Mon Sep 17 00:00:00 2001 From: Hazel Snider Date: Sat, 21 Jan 2023 00:05:40 -0500 Subject: [PATCH] spark particles when an arrow collides with tiles or is blocked --- objects/player/arrow_projectile.gd | 11 ++++++++++ objects/player/arrow_projectile.tscn | 33 +++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/objects/player/arrow_projectile.gd b/objects/player/arrow_projectile.gd index 0d5e816..3198bbd 100644 --- a/objects/player/arrow_projectile.gd +++ b/objects/player/arrow_projectile.gd @@ -35,6 +35,7 @@ func _exit_tree(): #Wall Collision func _on_Hitbox_body_entered(body): if body is TileMap or body is StaticBody2D: + _make_sparks() queue_free() # kill entity if in target group @@ -46,6 +47,7 @@ func _on_Hitbox_area_entered(area): if area.is_in_group("blocks_arrow"): var pos = target.global_position Game.instance_node(Game.block_text, pos.x, pos.y, target.get_parent()) + _make_sparks() else: # kill targeted node target.die() @@ -53,3 +55,12 @@ func _on_Hitbox_area_entered(area): if target_group == "enemy_hitbox": Game.arrows = max(0, Game.arrows - 1) # clamp arrows above 0 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") diff --git a/objects/player/arrow_projectile.tscn b/objects/player/arrow_projectile.tscn index 694be18..c4535ab 100644 --- a/objects/player/arrow_projectile.tscn +++ b/objects/player/arrow_projectile.tscn @@ -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://graphics/player/arrow.png" type="Texture" id=2] @@ -35,6 +35,28 @@ scale_curve = SubResource( 4 ) [sub_resource type="RectangleShape2D" id=2] 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"] script = ExtResource( 3 ) @@ -59,5 +81,14 @@ collision_layer = 0 position = Vector2( -0.5, -0.5 ) 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="body_entered" from="Hitbox" to="." method="_on_Hitbox_body_entered"]