Repository navigation
Expand file tree
/
Copy pathdefs.js
More file actions
224 lines (181 loc) · 5.31 KB
/
Copy pathdefs.js
File metadata and controls
224 lines (181 loc) · 5.31 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
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
OSI = setInterval; //Wrapper for setInterval
OCI = clearInterval; //Wrapper for clearInterval
IC = 0; //Interval counter
setInterval = function (func, delay)
{
if(func && delay)
IC++;
return OSI(func, delay);
};
clearInterval = function (id)
{
if(id !== true) //JQuery sometimes hands in true which doesn't count
IC--;
return OCI(id);
};
var game = false; //The game object, it will be assigned later.
ni = false; //No input, used by input.js.
var LU = function(id, t, pi)
{
$("#" + id).animate({"borderColor":"#8E3900", "padding": pi+"px"}, t);
}
var LD = function(id, t)
{
$("#" + id).animate({"borderColor":"#111", "padding":"0px"}, t);
}
var AU = function(ut, nt, pi) //all up
{
LU("f", ut, pi);
setTimeout(function(){LU("t", ut, pi)}, nt);
setTimeout(function(){LU("g", ut, pi)}, nt*2);
}
var AD = function(dt, nt) //all down
{
LD("f", dt);
setTimeout(function(){LD("t", dt)}, nt);
setTimeout(function(){LD("g", dt)}, nt*2);
}
var shine = function(ut, nt, st, pi) //up time (how long does it take for an element to light up), next time (how long before we switch to the next one), switch time (how long before they start shutting down)
{
AU(ut, nt, pi);
setTimeout(function(){AD(ut, nt)}, st)
}
var init = function()
{
var canvas = document.getElementById("c");
fps = 60;
game = new Game(canvas);
game.FFPS = fps; //Forced FPS
sload(function()
{
game.LSA = 0
game.run = setInterval(game.update, 1000/game.FFPS);
game.draw(); //This requests an animationFrame for itself, so the browser handles calling it.
game.focus = function(e)
{
game.draw();
};
window.addEventListener('focus', game.focus);
game.blur = function(e)
{
if (!game.paused)
{
game.pause();
p.setAttribute("class", "clicked");
for (var i = 0; i < game.sensors.length; i ++)
clearTimeout(game.sensors[i].sd);
}
};
window.addEventListener('blur', game.blur);
});
game.LSA = 1; //loading screen alpha
game.loading = setInterval(function()
{
game.context.save();
game.context.globalAlpha = game.LSA;
game.context.fillStyle = "#111";
game.context.fillRect(0, 0, canvas.width, canvas.height);
game.context.font="24pt Helvetica";
game.context.fillStyle = "#CCC";
game.context.fillText("Loading...", 40, 40);
game.context.fillStyle = "#EEE";
game.context.fillRect(60, 60, 400, 10);
game.context.fillStyle = "#111";
game.context.fillRect(61, 61, 398, 8);
w = 396 * (nl/np);
game.context.fillStyle = "#EEE";
game.context.fillRect(62, 62, w, 6);
game.context.restore();
}, 1000/game.FFPS);
}
var pause = function()
{
if (game.player.alive)
{
var p = document.getElementById("p");
if (!game.paused)
{
game.pause(true);
p.setAttribute("class", "clicked");
}
else
{
game.unpause(true);
p.setAttribute("class", "topMenu");
}
}
}
var noinput = function()
{
ni = true;
}
var doinput = function()
{
ni = false;
}
var fff = function(i)
{
game.loadLevel(game.levels[levelCodes[i].l]);
game.unpause();
}
var ll = function()
{
var toLoad = document.getElementById("lc").value;
for (var itt = 0; itt < levelCodes.length; itt++)
if (levelCodes[itt].code == toLoad)
{
game.pause();
(function(i)
{
setTimeout(function(){fff(i);}, 1000);
})(itt);
}
document.getElementById("lc").value = "";
}
var reload = function()
{
if (game.player.alive)
{
clearInterval(game.level.preping);
game.level.score = 0;
game.level.gp = [];
game.pause(false);
setTimeout(function()
{
game.unpause(false);
game.loadLevel(game.levels[game.level.id[0]][game.level.id[1]]);
}, game.pauseL);
}
}
var reset = function()
{
if (game.reset)
{
if (game.player.alive)
{
clearC();
game.messages = [];
game.level = undefined;
game.pause(false);
setTimeout(function()
{
game.unpause();
game.loadLevel(game.levels[0][0]);
}, game.pauseL);
}
}
else
{
document.getElementById("res").innerHTML = "Sure?";
document.getElementById("res").setAttribute("class", "clicked");
game.reset = true;
}
}
var beta = function()
{
$("#b").replaceWith("<div id='b' onmouseover='beta();' onmouseout='beta2();'>- beta just like you</div>");
}
var beta2 = function()
{
$("#b").replaceWith("<div id='b' onmouseover='beta();' onmouseout='beta2();'>- beta</div>");
}