@@ -2,15 +2,20 @@ class_name Player
2
2
extends Actor
3
3
4
4
@export var chestModifierSpeed : float = 0.7
5
+ @export var maxHealth = 100
6
+ var lifePoint = maxHealth
5
7
6
8
@onready var attackTimer = $ AttackTimer
9
+ @onready var healthbar = $ HealthBar
7
10
8
11
@export var weapon : Weapon
9
12
var hasChest = false
10
13
11
14
func _ready () -> void :
12
15
if weapon == null :
13
16
weapon = StoreManager .player_weapon
17
+ healthbar .max_value = maxHealth
18
+ healthbar .value = maxHealth
14
19
attackTimer .wait_time = weapon .attack_speed
15
20
16
21
func _input (event ):
@@ -22,7 +27,15 @@ func _input(event):
22
27
attack ()
23
28
24
29
func apply_attack (force : int ) -> void :
25
- prints ("Attacked with force" , force )
30
+ if lifePoint == 0 :
31
+ return
32
+
33
+ lifePoint -= force
34
+ $ AnimationPlayer .play ('Hit' )
35
+ healthbar .value = lifePoint
36
+
37
+ if (lifePoint == 0 ):
38
+ $ AnimationPlayer .play ("Death" )
26
39
27
40
func get_speed ():
28
41
if hasChest : return _speed * chestModifierSpeed
@@ -38,7 +51,7 @@ func attack():
38
51
var direction = global_position .direction_to (mouseCoords )
39
52
40
53
var attack_scene = weapon .attackTo (direction )
41
-
54
+
42
55
if weapon .attack_type == Weapon .ATTACK_TYPES .projectile :
43
56
attack_scene .global_position = global_position
44
57
get_tree ().current_scene .add_child (attack_scene )
@@ -54,6 +67,6 @@ func _on_collecting(element):
54
67
if hasChest :
55
68
element .can_enter = true
56
69
$ AnimationPlayer .play ("fade_away" )
57
-
70
+
58
71
if element .can_enter : $ AnimationPlayer .play ("fade_away" )
59
-
72
+
0 commit comments