-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplayer.gd
249 lines (150 loc) · 4.72 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
extends KinematicBody2D
'''defining var and const'''
var UP = Vector2(0, -1)
var motion = Vector2()
onready var score = scorescore.score1
var health = 4
var timer : float = 0
var fly = false
var jump = 0
'''function for the game'''
func _ready():
set_physics_process(true)
set_process(true)
func _process(delta):
var labelnode = get_parent().get_node("scorecard/CanvasLayer/Control/Label")
labelnode.text = str(score)
func _physics_process(delta):
if(timer > 0): timer -= delta
if(timer <= 0): timer = 0
motion.y += 50
var friction = false
if Input.is_action_pressed("ui_down"):
if Input.is_action_pressed("ui_right"):
motion.x = min(motion.x+20, 500)
$Sprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
motion.x = max(motion.x-20, -500)
$Sprite.flip_h = true
else:
friction = true
elif Input.is_action_pressed("ui_right"):
$Sprite.play("fly")
motion.x = min(motion.x+20, 500)
$Sprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
$Sprite.play("fly")
motion.x = max(motion.x-20, -500)
$Sprite.flip_h = true
else:
friction = true
if motion.y < 0:
$Sprite.play("fly2")
if is_on_floor():
###
#sky walk
if Input.is_action_just_pressed("ui_up"):
var jump = get_parent().get_node("sounds/jump")
jump.play()
var sound = get_parent().get_node("sounds/jump2")
sound.start()
fly = true
$fly.start()
motion.y = -1000
##
if friction == true:
motion.x = lerp(motion.x, 0, 0.2)
elif Input.is_action_just_pressed("ui_up") and fly == true:
var jump = get_parent().get_node("sounds/jump")
jump.play()
var sound = get_parent().get_node("sounds/jump2")
sound.start()
motion.y = -600
$Sprite.play("fly2")
if friction == true:
motion.x = lerp(motion.x, 0, 0.2)
motion = move_and_slide(motion, UP)
#
func TakeDamage(amount):
if(timer == 0):
health-=amount
#
if (health == 3):
var heart1 = get_parent().get_node("health/CanvasLayer/Control/heart1")
heart1.hide()
var player = get_parent().get_node("player/Camera2D/ScreenShake")
player.start()
$CanvasModulate.show()
$redshock.start()
death()
#
#
elif (health == 2):
var heart2 = get_parent().get_node("health/CanvasLayer/Control/heart2")
heart2.hide()
var playe = get_parent().get_node("player/Camera2D/ScreenShake")
playe.start()
$CanvasModulate.show()
$redshock.start()
death()
elif (health == 1):
var heart3 = get_parent().get_node("health/CanvasLayer/Control/heart3")
heart3.hide()
var timer = get_parent().get_node("health/Timer")
timer.start()
var play = get_parent().get_node("player/Camera2D/ScreenShake")
play.start()
$CanvasModulate.show()
$redshock.start()
$Particles2D.show()
death()
timer = 1 #how long you want the time between hits to be in seconds
#
func _on_Timer_timeout():
get_tree().change_scene("losenote.tscn")
func _on_fly_timeout():
fly = false
func _on_Area2D_body_entered(body):
if body.get_name() == get_name():
TakeDamage(1)
pass # Replace with function body.
func _on_redshock_timeout():
$CanvasModulate.hide()
pass # Replace with function body.
func _on_dial_body_entered(body):
if body.get_name() == get_name():
var dial = get_parent().get_node("dialouge/CanvasLayer/NinePatchRect")
dial.show_text("intro" ,"MAX")
func _on_blue_egg_body_entered(body):
score += 100
scorescore.score1 += 100
var sound = get_parent().get_node("sounds/pickup")
sound.play()
var soundt = get_parent().get_node("sounds/pickupsound")
soundt.start()
pass # Replace with function body.
func _on_redegg_body_entered(body):
score += 10
scorescore.score1 += 10
var sound = get_parent().get_node("sounds/pickup")
sound.play()
var soundt = get_parent().get_node("sounds/pickupsound")
soundt.start()
pass # Replace with function body.
func death():
var death = get_parent().get_node("sounds/death")
death.play()
var sound = get_parent().get_node("sounds/death2")
sound.start()
func _on_death2_timeout():
var death = get_parent().get_node("sounds/death")
death.stop()
pass # Replace with function body.
func _on_jump2_timeout():
var cake = get_parent().get_node("sounds/jump")
cake.stop()
pass # Replace with function body.
func _on_pickupsound_timeout():
var sound = get_parent().get_node("sounds/pickup")
sound.stop()
pass # Replace with function body.