summaryrefslogtreecommitdiff
path: root/Scenes/Entities/Enemies/Components/Health.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Scenes/Entities/Enemies/Components/Health.gd')
-rw-r--r--Scenes/Entities/Enemies/Components/Health.gd37
1 files changed, 27 insertions, 10 deletions
diff --git a/Scenes/Entities/Enemies/Components/Health.gd b/Scenes/Entities/Enemies/Components/Health.gd
index 2bd2447..00bf9e0 100644
--- a/Scenes/Entities/Enemies/Components/Health.gd
+++ b/Scenes/Entities/Enemies/Components/Health.gd
@@ -2,6 +2,7 @@ class_name ComponentHealth
extends Node
+signal hit
signal died
@export_node_path("CharacterBody2D") var entityPath: NodePath
@@ -21,7 +22,8 @@ var drop_items = [
preload("res://Scenes/Entities/Objects/Coin.tscn"),
]
-var is_dying = false
+@export var invincibility_timeout: float = 1.0
+var is_invincible = false
func _ready():
@@ -30,23 +32,38 @@ func _ready():
func take_damage():
+ if is_invincible:
+ return
+
+ emit_signal("hit")
+
health -= 1
- if health <= 0 and not is_dying:
+ is_invincible = true
+ if component_movement: # stop all movement
+ component_movement.pause()
+
+ sprite.play("death")
+ await sprite.animation_finished
+
+ if health <= 0:
death()
+ else:
+ if component_movement: # resume all movement
+ component_movement.unpause()
+
+ #var flicker_speed = 0.2
+ #var tween = create_tween().set_loops(invincibility_timeout / (flicker_speed*2))
+ #tween.tween_property(sprite, "modulate", Color(1, 1, 1, 0.5), flicker_speed)
+ #tween.tween_property(sprite, "modulate", Color(1, 1, 1, 1), flicker_speed)
+ #
+ #await get_tree().create_timer(invincibility_timeout).timeout
+ is_invincible = false
func death():
- is_dying = true
emit_signal("died")
- if component_movement: # stop all movement
- component_movement.process_mode = Node.PROCESS_MODE_DISABLED
- entity.set_physics_process(false)
-
- sprite.play("death")
- await sprite.animation_finished
-
assert(sprite.sprite_frames.has_animation("death_post"))
sprite.play("death_post")