-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.gd
99 lines (80 loc) · 2.2 KB
/
Player.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
extends KinematicBody2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
signal player_dead
export var speed = 20
export var fireball : PackedScene
onready var animator = $Sprite/AnimationPlayer
var facing_direction = constants.LEFT
var health = 100
var mana = 100
var score = 0
var type = constants.PLAYER
func reset():
health = 100
mana = 100
score = 0
update_health(0)
update_mana(0)
# Called when the node enters the scene tree for the first time.
func _ready():
$GUI/HP.value = health
$GUI/MP.value = mana
$GUI/Score.text = "Score : "+str(score)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func move(delta):
var movement = Vector2()
if Input.is_action_pressed("ui_down"):
movement.y = 1
animator.play("WalkDown")
facing_direction = constants.DOWN
elif Input.is_action_pressed("ui_left"):
movement.x = -1
animator.play("WalkLeft")
facing_direction = constants.LEFT
elif Input.is_action_pressed("ui_up"):
movement.y = -1
animator.play("WalkUp")
facing_direction = constants.UP
elif Input.is_action_pressed("ui_right"):
movement.x = 1
animator.play("WalkRight")
facing_direction = constants.RIGHT
else:
animator.stop(false)
movement = move_and_slide(movement*speed, Vector2(0, -1))
for i in get_slide_count():
var collision = get_slide_collision(i)
if collision:
print(collision)
func _physics_process(delta):
move(delta)
if Input.is_action_just_pressed("ui_select"):
if mana >= 5:
print("Fireball")
var new_fireball = fireball.instance()
new_fireball.launched_entity_type = type
new_fireball.global_position = $projectile_spawn_position.global_position
get_node("/root/Main").add_child(new_fireball)
new_fireball.init(facing_direction)
update_mana(-10)
func update_mana(value):
mana += value
$GUI/MP.value = mana
func update_score(value):
score += value
$GUI/Score.text = "Score : "+str(score)
func update_health(value):
health += value
$GUI/HP.value = health
if health <= 0:
emit_signal("player_dead")
func incur_damage(value):
print(health)
update_health(-value)
return false
func _on_Area2D_body_entered(body):
print(body)
func _on_ManaRegen_timeout():
update_mana(5)