From 937578ef33f98b3b2fa5f18314467bba3807559d Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Wed, 17 Mar 2021 00:27:02 +0000 Subject: [PATCH] Add the bat's death effect --- Effects/EnemyDeathEffect.tscn | 58 +++++++++++++++++++++++++++++++++++ Enemies/Bat.gd | 5 +++ Enemies/Bat.tscn | 2 +- Player/player.tscn | 2 +- World/Grass.gd | 12 +++++--- world.tscn | 26 ++++++++-------- 6 files changed, 85 insertions(+), 20 deletions(-) create mode 100644 Effects/EnemyDeathEffect.tscn diff --git a/Effects/EnemyDeathEffect.tscn b/Effects/EnemyDeathEffect.tscn new file mode 100644 index 0000000..31afe28 --- /dev/null +++ b/Effects/EnemyDeathEffect.tscn @@ -0,0 +1,58 @@ +[gd_scene load_steps=14 format=2] + +[ext_resource path="res://Effects/EnemyDeathEffect.png" type="Texture" id=1] +[ext_resource path="res://Effects/Effects.gd" type="Script" id=2] + +[sub_resource type="AtlasTexture" id=1] +atlas = ExtResource( 1 ) +region = Rect2( 0, 0, 32, 32 ) + +[sub_resource type="AtlasTexture" id=2] +atlas = ExtResource( 1 ) +region = Rect2( 32, 0, 32, 32 ) + +[sub_resource type="AtlasTexture" id=3] +atlas = ExtResource( 1 ) +region = Rect2( 64, 0, 32, 32 ) + +[sub_resource type="AtlasTexture" id=4] +atlas = ExtResource( 1 ) +region = Rect2( 96, 0, 32, 32 ) + +[sub_resource type="AtlasTexture" id=5] +atlas = ExtResource( 1 ) +region = Rect2( 128, 0, 32, 32 ) + +[sub_resource type="AtlasTexture" id=6] +atlas = ExtResource( 1 ) +region = Rect2( 160, 0, 32, 32 ) + +[sub_resource type="AtlasTexture" id=7] +atlas = ExtResource( 1 ) +region = Rect2( 192, 0, 32, 32 ) + +[sub_resource type="AtlasTexture" id=8] +atlas = ExtResource( 1 ) +region = Rect2( 224, 0, 32, 32 ) + +[sub_resource type="AtlasTexture" id=9] +atlas = ExtResource( 1 ) +region = Rect2( 256, 0, 32, 32 ) + +[sub_resource type="AtlasTexture" id=10] +atlas = ExtResource( 1 ) +region = Rect2( 288, 0, 32, 32 ) + +[sub_resource type="SpriteFrames" id=11] +animations = [ { +"frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 6 ), SubResource( 7 ), SubResource( 8 ), SubResource( 9 ), SubResource( 10 ) ], +"loop": false, +"name": "animate", +"speed": 15.0 +} ] + +[node name="EnemyDeathEffect" type="AnimatedSprite"] +frames = SubResource( 11 ) +animation = "animate" +offset = Vector2( 0, -8 ) +script = ExtResource( 2 ) diff --git a/Enemies/Bat.gd b/Enemies/Bat.gd index b8fb7d0..19fcce7 100644 --- a/Enemies/Bat.gd +++ b/Enemies/Bat.gd @@ -1,5 +1,7 @@ extends KinematicBody2D +const DeathEffect = preload("res://Effects/EnemyDeathEffect.tscn") + var knockback = Vector2.ZERO onready var stats = $Stats @@ -14,3 +16,6 @@ func _on_HurtBox_area_entered(area): func _on_Stats_no_health(): queue_free() + var effect = DeathEffect.instance() + get_parent().add_child(effect) + effect.global_position = global_position diff --git a/Enemies/Bat.tscn b/Enemies/Bat.tscn index 4815a97..3063258 100644 --- a/Enemies/Bat.tscn +++ b/Enemies/Bat.tscn @@ -48,7 +48,7 @@ script = ExtResource( 4 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="."] frames = SubResource( 6 ) animation = "Fly" -frame = 2 +frame = 1 playing = true offset = Vector2( 0, -12 ) diff --git a/Player/player.tscn b/Player/player.tscn index 6327fd3..802dc0f 100644 --- a/Player/player.tscn +++ b/Player/player.tscn @@ -649,7 +649,7 @@ position = Vector2( 16, 0 ) collision_layer = 0 collision_mask = 8 script = ExtResource( 4 ) -damage = 2 +damage = 1 [node name="CollisionShape2D" parent="HitBoxPosition/SwordHitBox" index="0"] shape = SubResource( 46 ) diff --git a/World/Grass.gd b/World/Grass.gd index 584dc84..03c5696 100644 --- a/World/Grass.gd +++ b/World/Grass.gd @@ -5,15 +5,17 @@ const GrassEffect = preload("res://Effects/GrassEffect.tscn") func destroy_effect(): var grass_effect = GrassEffect.instance() - var world_node = get_tree().current_scene - # We add the effect to the world and not to the grass itself since + # We add the effect to the parent and not to the grass itself since # we're going to free the current node later. - # The better way to do it is to add the animated sprite in the same seen - # as the grass statically and just play the animation here and disable the it's + # The better way to do it is to add the animated sprite in the same scense + # as the grass statically and just play the animation here and disable its # interaction with the world such as hurt box - world_node.add_child(grass_effect) + + # The parent in this case is a YSort node which makes the effect follow the + # ysort rules + get_parent().add_child(grass_effect) # set the position of the effect to the global_position of the current grass grass_effect.global_position = global_position diff --git a/world.tscn b/world.tscn index 0d576fd..af10b05 100644 --- a/world.tscn +++ b/world.tscn @@ -506,11 +506,22 @@ tile_data = PoolIntArray( 196614, 0, 131077, 327679, 0, 131074, 262144, 0, 13107 [node name="Ground" type="YSort" parent="."] -[node name="Tree" parent="Ground" instance=ExtResource( 4 )] -position = Vector2( 248, 104 ) +[node name="player" parent="Ground" instance=ExtResource( 2 )] +position = Vector2( 32, 88 ) + +[node name="Enemies" type="YSort" parent="Ground"] + +[node name="Bat" parent="Ground/Enemies" instance=ExtResource( 8 )] +position = Vector2( 112, 88 ) + +[node name="Bat2" parent="Ground/Enemies" instance=ExtResource( 8 )] +position = Vector2( 272, 120 ) [node name="Bushes" type="YSort" parent="Ground"] +[node name="Tree" parent="Ground/Bushes" instance=ExtResource( 4 )] +position = Vector2( 248, 104 ) + [node name="Bush" parent="Ground/Bushes" instance=ExtResource( 1 )] position = Vector2( 48, 56 ) @@ -551,14 +562,3 @@ position = Vector2( 32, 128 ) [node name="Grass3" parent="Ground/Grass" instance=ExtResource( 7 )] position = Vector2( 16, 144 ) - -[node name="Enemies" type="YSort" parent="."] - -[node name="player" parent="Enemies" instance=ExtResource( 2 )] -position = Vector2( 32, 88 ) - -[node name="Bat" parent="Enemies" instance=ExtResource( 8 )] -position = Vector2( 112, 88 ) - -[node name="Bat2" parent="Enemies" instance=ExtResource( 8 )] -position = Vector2( 272, 120 )