From 06647b11ee163bc40daf454d87e1fcae563c3ced Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 23 May 2024 14:11:43 +0200 Subject: update --- Scenes/Entities/Enemies/Components/Health.gd | 5 ++++- Scenes/Entities/Enemies/Projectile.gd | 2 +- Scenes/Entities/Enemies/Tree.gd | 5 +++++ Scenes/Entities/Enemies/Tree.tscn | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) (limited to 'Scenes/Entities/Enemies') diff --git a/Scenes/Entities/Enemies/Components/Health.gd b/Scenes/Entities/Enemies/Components/Health.gd index 6f65e79..2bd2447 100644 --- a/Scenes/Entities/Enemies/Components/Health.gd +++ b/Scenes/Entities/Enemies/Components/Health.gd @@ -21,6 +21,8 @@ var drop_items = [ preload("res://Scenes/Entities/Objects/Coin.tscn"), ] +var is_dying = false + func _ready(): if component_movement_path: @@ -30,11 +32,12 @@ func _ready(): func take_damage(): health -= 1 - if health <= 0: + if health <= 0 and not is_dying: death() func death(): + is_dying = true emit_signal("died") if component_movement: # stop all movement diff --git a/Scenes/Entities/Enemies/Projectile.gd b/Scenes/Entities/Enemies/Projectile.gd index af283b4..02a1470 100644 --- a/Scenes/Entities/Enemies/Projectile.gd +++ b/Scenes/Entities/Enemies/Projectile.gd @@ -13,7 +13,7 @@ func _ready(): velocity = position.direction_to(target) * speed -func _physics_process(delta): +func _physics_process(_delta): $AnimatedSprite2D.play("default") move_and_slide() diff --git a/Scenes/Entities/Enemies/Tree.gd b/Scenes/Entities/Enemies/Tree.gd index 5572e02..bbd02a9 100644 --- a/Scenes/Entities/Enemies/Tree.gd +++ b/Scenes/Entities/Enemies/Tree.gd @@ -3,6 +3,7 @@ extends CharacterBody2D @onready var component_collision: ComponentCollision = $Collision @onready var component_movement: ComponentMovement = $Movement +@onready var component_health: ComponentHealth = $Health func _ready(): @@ -16,6 +17,10 @@ func _ready(): $AnimatedSprite2D.play("spawn") $AnimatedSprite2D.stop() $AnimatedSprite2D.set_frame_and_progress(0, 0) + + $Health.connect("died", func(): + $Detection.set_collision_mask_value(Utilities.Collision.Layer.PLAYER, false) + ) func _physics_process(delta): diff --git a/Scenes/Entities/Enemies/Tree.tscn b/Scenes/Entities/Enemies/Tree.tscn index 3a0de4a..f216159 100644 --- a/Scenes/Entities/Enemies/Tree.tscn +++ b/Scenes/Entities/Enemies/Tree.tscn @@ -141,7 +141,7 @@ script = ExtResource("1_ktvfx") texture_filter = 1 position = Vector2(0, -8) sprite_frames = SubResource("SpriteFrames_c5ryj") -animation = &"spawn" +animation = &"death_post" [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, -8) -- cgit v1.2.3