blob: 33a1e989f0611cda44a662f79da5556c409f0c9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
|