summaryrefslogtreecommitdiff
path: root/Scripts/Entity.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts/Entity.gd')
-rw-r--r--Scripts/Entity.gd56
1 files changed, 56 insertions, 0 deletions
diff --git a/Scripts/Entity.gd b/Scripts/Entity.gd
new file mode 100644
index 0000000..33a1e98
--- /dev/null
+++ b/Scripts/Entity.gd
@@ -0,0 +1,56 @@
+extends PhysicsBody2D
+class_name Entity
+
+@export var is_player : bool = false
+@export var is_player_dead : bool = false
+@export var max_health : int = 10
+var health : int = 1
+
+var timer : Timer
+
+var knockback : Vector2
+
+func _ready() -> void:
+ timer = Timer.new()
+ add_child(timer)
+ timer.wait_time = 0.15
+ timer.one_shot = true
+ timer.timeout.connect(_on_dmg_visual_timer_timeout)
+ health = max_health
+
+signal entity_death
+
+func _process(_delta: float) -> void:
+ if health <= 0:
+ entity_death.emit()
+ if !is_player:
+ queue_free()
+ else:
+ is_player_dead = true
+
+func _physics_process(_delta: float) -> void:
+ if is_player && knockback != Vector2.ZERO:
+ $"PlayerMovement".knockback = knockback
+ knockback = Vector2.ZERO
+
+func damage(n : int):
+ health -= n
+ modulate = Color.RED
+ timer.start()
+
+ if is_player: UIConnector.display_health(health)
+
+func _on_dmg_visual_timer_timeout() -> void:
+ modulate = Color.WHITE
+
+# this is bad
+
+func make_tools_invisible():
+ $"HandPivot".visible = false
+
+func make_mask_invisible():
+ $"MaskNode".visible = false
+
+func make_invisisble():
+ $"Player".visible = false
+ $"Sprite2D".visible = false