-
Notifications
You must be signed in to change notification settings - Fork 2
/
player_state.gd
74 lines (53 loc) · 1.89 KB
/
player_state.gd
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
extends Node
@onready var player_node = null
@onready var player_max_health = 100
@onready var player_health = 100
@onready var player_position = Vector2.ZERO
@onready var player_hurtbox : Hurtbox
signal change_health(value)
var knockbackTween
var engagedEnemies : Array = []
var iframe = false # true if iframe on
# Called when the node enters the scene tree for the first time.
func _ready():
#add_user_signal("hurt", [{"name": "damage", "type": TYPE_INT}])
add_user_signal("increase_special", [])
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if player_node:
player_position = player_node.position
func set_player_node(res_path):
player_node = get_node(res_path)
player_hurtbox = player_node.find_child("Hurtbox")
func set_iframe(iframe_sent):
iframe = iframe_sent
func take_damage(damage):
if iframe:
return
print_debug("Player takes " + str(damage) + " points of damage")
knockbackTween = get_tree().create_tween()
knockbackTween.parallel().tween_property(player_node, "knockback", Vector2(0,0), 0.25)
player_node.modulate = Color(1,0,0,1)
knockbackTween.parallel().tween_property(player_node, "modulate", Color(1,1,1,1), 0.25)
player_health -= damage
# signals the bars.gd script to change the health bar value
change_health.emit(player_health)
if player_health <= 0:
game_over()
func gain_health(points):
if player_health + points > player_max_health:
player_health = player_max_health
else:
player_health += points
change_health.emit(player_health)
func engage_enemy(rid):
engagedEnemies.append(rid)
func disengage_enemy(rid):
var enemy_rid = engagedEnemies.find(rid)
engagedEnemies.remove_at(enemy_rid)
# causes the bars.gd script to add special points to the bar
func increase_special():
emit_signal("increase_special")
func game_over():
get_tree().paused = true
SceneSwitch.switch_scene("res://ui/dead.tscn")