-
Notifications
You must be signed in to change notification settings - Fork 4
/
penguin.gd
174 lines (164 loc) · 4.32 KB
/
penguin.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
extends KinematicBody
# Member variables
var g = -9.8
var vel = Vector3()
var MAX_SPEED =25
const JUMP_SPEED = 7
const ACCEL= 2
const DEACCEL= 4
const MAX_SLOPE_ANGLE = 30
var werstarted = 0
var speeding = 0
var score_file = "user://sledhighscore.txt"
var highscore = 0
var werover = 0
var accum=0
func _physics_process(delta):
set_process_input(true)
accum += delta
#print(accum)
werstarted = 1
var dir = Vector3()
var cam_xform = $target/camera.get_global_transform()
var pauselabel = get_node('/root/world/pauselabel')
var rightbutton = get_node('/root/world/right')
var leftbutton = get_node('/root/world/left')
# mobile input
if rightbutton.is_pressed() ==true:
dir += cam_xform.basis[0]
if leftbutton.is_pressed() ==true:
dir += -cam_xform.basis[0]
# PC input
if Input.is_action_pressed("move_left"):
dir += -cam_xform.basis[0]
if Input.is_action_pressed("move_right"):
dir += cam_xform.basis[0]
if Input.is_action_pressed("pause"):
get_tree().paused = true
pauselabel.show()
dir += -cam_xform.basis[2]
dir.y = 0
dir = dir.normalized()
vel.y += delta * g
var hvel = vel
hvel.y = 0
var sfxpop = get_node('/root/world/wind')
sfxpop.set_volume_db(vel.x * 0.3)
var target = dir * MAX_SPEED
var accel
if dir.dot(hvel) > 0:
accel = ACCEL
else:
accel = DEACCEL
hvel = hvel.linear_interpolate(target, accel * delta)
vel.x = hvel.x
vel.z = hvel.z
#print(vel.x)
# prevents player from turning around
var vell = vel.x
if vel.x < 0.5:
vel.x = 1
if vel.x < 10.5:
if werover == 0:
vel.x = vell + 5
#print(vel.x)
vel = move_and_slide(vel, Vector3(0,1,0))
# var hih = vel.y - 0.05
# vel.y = hih
# this code prevents the player from floating really far
if is_on_floor():
print("")
else:
var hih = vel.y - 0.5
vel.y = hih
# the longer the player has been playing, the faster it gets
var MAX_SPEED1 = MAX_SPEED
MAX_SPEED =MAX_SPEED1 +0.002
#print(MAX_SPEED)
#if is_on_floor() and Input.is_action_pressed("jump"):
# vel.y = JUMP_SPEED
func _on_tcube_body_enter(body):
if body == self:
print("hi")
func load_score():
var f = File.new()
if f.file_exists(score_file):
f.open(score_file, File.READ)
var content = f.get_as_text()
highscore = int(content)
f.close()
func save_score():
var labelscore = get_node('/root/world/Label')
var inthelabel = labelscore.get_text()
#print(inthelabel)
var timeDict = OS.get_time();
var dateDict= OS.get_date()
var hour = timeDict.hour;
var minute = timeDict.minute;
var seconds = timeDict.second;
#var thetime = OS.get_datetime()
var thedate = str(dateDict.year) + str(dateDict.month) + str(dateDict.day)
var thetime = str(timeDict.hour) + str(timeDict.minute) + str(timeDict.second)
var datetimefinal = thedate + thetime
#print(accum)
var HTTPRequest = get_node('/root/world/HTTPRequest')
HTTPRequest.request("https://www.dreamlo.com/lb/(your super secret very long code)/add/Penguin" + datetimefinal + "/" + inthelabel + "/" + str(round(accum)))
load_score()
if highscore < int(inthelabel):
var f = File.new()
f.open(score_file, File.WRITE)
f.store_string(str(inthelabel))
f.close()
func _on_HTTPRequest_request_completed( result, response_code, headers, body ):
var json = JSON.parse(body.get_string_from_utf8())
print(json.result)
func _on_tcube_body_entered(body):
if body == self:
var themusic = get_node('/root/world/mainsong')
var sled = get_node('/root/world/cubio/sled')
var deflate = get_node('/root/world/cubio/deflate')
sled.hide()
deflate.show()
var sfxpop = get_node('/root/world/cubio/pop')
themusic.stop()
#sfxpop.loop = false
if werover == 0:
sfxpop.play(0)
werover = 1
MAX_SPEED = 0
vel.x = 0
var t = Timer.new()
t.set_wait_time(2)
t.set_one_shot(true)
self.add_child(t)
t.start()
yield(t, "timeout")
t.queue_free()
save_score()
set_physics_process(false)
var golabel = get_node('/root/world/go')
golabel.show()
MAX_SPEED =0
func _on_speed_body_entered(body):
var MAX_SPEED1 = MAX_SPEED
if speeding == 0:
speeding = 1
if MAX_SPEED1 > 35:
MAX_SPEED =95
if MAX_SPEED1 < 35:
MAX_SPEED = 65
if MAX_SPEED1 > 65:
MAX_SPEED = 125
#print(MAX_SPEED)
var t = Timer.new()
t.set_wait_time(1)
t.set_one_shot(false)
self.add_child(t)
t.start()
yield(t, "timeout")
t.queue_free()
MAX_SPEED=MAX_SPEED1
speeding = 0
if werover == 1:
MAX_SPEED =0
#if werover == 0: