-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.gd
More file actions
180 lines (157 loc) · 3.87 KB
/
player.gd
File metadata and controls
180 lines (157 loc) · 3.87 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
extends KinematicBody2D
var sprite
var asprite = []
var lfoot
var rfoot
var left
var right
var hspeed = 0
var vspeed = 0
var onGround = false
export (int) var speed = 10
export (int) var jumpSpeed = -400
export (int) var gravity = 1000
var velocity = Vector2()
var speedOnJump = 0
var hurting = false
var hurtloop = 0
var hurtcount = 0
var jumping = true
export var max_speed = 100
func _ready():
asprite = [get_node("sprite"), get_node("sprite1"), get_node("sprite2"), get_node("sprite3")]
sprite = get_node("sprite")
lfoot = get_node("leftFoot")
rfoot = get_node("rightFoot")
right = get_node("right")
left = get_node("left")
lfoot.add_exception(self)
lfoot.add_exception(right)
lfoot.add_exception(left)
rfoot.add_exception(self)
rfoot.add_exception(right)
rfoot.add_exception(left)
right.add_exception(self)
right.add_exception(right)
right.add_exception(left)
left.add_exception(self)
left.add_exception(right)
left.add_exception(left)
set_fixed_process(true)
func get_input():
if (!global.talking || !global.stopntalk) && !global.dead:
var right = Input.is_action_pressed("ui_right")
var left = Input.is_action_pressed("ui_left")
var jump = Input.is_action_pressed("ui_up")
var drop = Input.is_action_pressed("ui_down")
if onGround:
if drop and (lfoot.get_collider().is_in_group("locker") || rfoot.get_collider().is_in_group("locker")):
set_pos(Vector2(get_pos().x, get_pos().y+1))
if jump && !jumping:
jumping = true
velocity.y = jumpSpeed
elif !jump:
jumping = false
if right and velocity.x < max_speed:
velocity.x += speed
if left and velocity.x > -max_speed:
velocity.x -= speed
if !left && !right:
velocity.x = 0
else:
if right and velocity.x < max_speed:
velocity.x += speed/1.5
if left and velocity.x > -max_speed:
velocity.x -= speed/1.5
else:
if onGround:
velocity.x = 0
func _fixed_process(delta):
if sprite.get_frame() == 16:
global.dead = false
sprite.set_animation("idle")
_hurt(0)
onGround = lfoot.is_colliding() || rfoot.is_colliding()
get_input()
velocity.y += gravity * delta
var motion = velocity*delta
if !onGround:
motion.x = motion.x * 1.5
move(motion)
if (is_colliding()):
var n = get_collision_normal()
motion = n.slide(motion)
velocity = n.slide(velocity)
move(motion)
check_health()
if !global.dead:
check_state()
if hurting == true:
if hurtloop < 8:
hurtcount += delta
if hurtcount > 0.12:
if is_visible():
hide()
else:
show()
hurtcount = 0
hurtloop += 1
else:
hurting = false
show()
func check_state():
if velocity.y > 0:
sprite.set_animation("fall")
elif velocity.y < 0:
sprite.set_animation("jump")
if lfoot.is_colliding() || rfoot.is_colliding():
if velocity.x == 0:
sprite.set_animation("idle")
elif velocity.x != 0:
sprite.set_animation("run")
if (left.is_colliding() || right.is_colliding()) && (!lfoot.is_colliding() || rfoot.is_colliding()):
sprite.set_animation("wall")
if velocity.x < 0:
if sprite.is_flipped_h():
sprite.set_flip_h(false)
elif velocity.x > 0:
if !sprite.is_flipped_h():
sprite.set_flip_h(true)
func check_health():
if global.health > 75:
sprite = asprite[0]
elif global.health > 50:
sprite = asprite[1]
elif global.health > 25:
sprite = asprite[2]
else:
sprite = asprite[3]
for i in asprite:
i.hide()
sprite.show()
func _hurt(h):
if !hurting && !global.dead:
global.health -= h
hurting = true
hurtloop = 0
global.sfx.play("Hurt")
check_health()
func _heal(h):
global.health += h
if global.health > 100:
global.health = 100
global.sfx.play("Heart")
check_health()
func _die():
check_health()
global.dead = true
sprite.set_animation("die")
hurting = false
if sprite.get_frame() == 12:
get_parent()._dieMenu()
func _rez():
check_health()
sprite.set_animation("rez")
sprite.set_frame(0)
func _gravity(grav):
set_gravity_scale(grav)