-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexobike.coffee
84 lines (62 loc) · 1.54 KB
/
exobike.coffee
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
KM=240 # Number of km per internal distance units
State = null
Pre = null
Splash = null
$(document).ready ->
initGlobals()
attractLoop()
initGlobals = ->
Pre = $("#ascii_art").get(0)
Splash = new FixedScreens(Pre)
setKey = (down, up) ->
$(document).off("keydown")
$(document).off("keyup")
$(document).on("keydown", null, null, down) if down
$(document).on("keyup", null, null, up) if up
attractLoop = ->
insert = 0
setKey(null, -> ++insert)
count = 0
loopFn = ->
if count % 2
Splash.showTitleAlt()
else
Splash.showTitle()
count++
if count < 1 or not insert
setTimeout(loopFn, 500)
insert = false
else if insert
helpLoop()
loopFn()
helpLoop = ->
Splash.showInstructions()
setTimeout(playGame, 4000)
playGame = ->
State = new Game(Pre, 500)
setKey(keyDownHandler, keyUpHandler)
mainLoop()
paused = false
x=0
keyDownHandler = (event) =>
switch String.fromCharCode(event.keyCode)
when 'A' then State.left()
when 'D' then State.right()
when 'S' then State.setWheelie(true)
when 'P' then paused = !paused
when 'N' then if paused then State.oneRound()
keyUpHandler = (event) ->
State.setWheelie(false) if String.fromCharCode(event.keyCode) == 'S'
mainLoop = () ->
if not State.oneRound()
endScreen()
return
delay = State.delayTime()
setTimeout(mainLoop, delay)
endScreen = () ->
setKey(null, null)
if State.crashed
Splash.showCrashed()
else
Splash.showWin(State.elapsedTimeFmt())
setTimeout(attractLoop, 4000)