forked from mvasilkov/roads2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainloop.ts
47 lines (37 loc) · 948 Bytes
/
mainloop.ts
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
/// <reference path="roads.d.ts" />
let colOffset = -HALF_COLUMN_WIDTH
let scrollSpeed = 20
let scrollAccel = 0
let newHeight = STARTING_HEIGHT
function update() {
if ((colOffset += (scrollSpeed + scrollAccel)) >= COLUMN_WIDTH) {
colOffset -= COLUMN_WIDTH
colEnd = colBegin
colBegin = colBegin.next!
// colEnd.height = newHeight
colEnd.danger = doDanger ? nextDanger : NO_DANGER
}
if (pointer.dragging) {
const col = getColumn(pointer.x)
col.height = newHeight
}
updatePlayer()
}
let then = -1
let t = 0
function mainloop(now: number) {
requestAnimationFrame(mainloop)
if (pointer.dragging) {
newHeight = clamp(CANVAS_HEIGTH - pointer.y, 20, CANVAS_HEIGTH - 60)
}
if (then == -1) {
then = now
}
t += (now - then) * 0.001
then = now
while (t > 0) {
t -= T
update()
}
paint(now, t / T + 1)
}