-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
426 lines (387 loc) · 12.6 KB
/
index.html
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>STRUNG OUT in heaven's high PICO-8 Cartridge</title>
<meta name="description" content="">
<style type="text/css">
<!--
html,body{
padding:0;
margin:0;
width:100%;
height:100%;
background:transparent;
}
center{
text-align:center;
width:512px;
height:537px;
position:absolute;
display:block;
top:0;
bottom:0;
right:0;
left:0;
margin:auto;
}
canvas#canvas{
width: 512px;
height: 512px;
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
-ms-interpolation-mode: nearest-neighbor;
image-rendering: pixelated;
}
.pico8_el{
width:92px;
height:16px;
display:inline-block;
margin: 1px;
margin-bottom:0;
padding: 4px;
text-align: center;
color:rgb(255, 241, 232);
background-color:rgb(41, 173, 255);
font-family : verdana, sans-serif;
font-size: 9pt;
cursor: pointer;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
.pico8_el img{
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
-ms-interpolation-mode: nearest-neighbor;
image-rendering: pixelated;
}
.pico8_el a{
text-decoration: none;
color:rgb(255, 241, 232);
}
.pico8_el:hover,
.pico8_el:link{
background-color:rgb(0, 0, 0);
}
-->
</style>
</head>
<body style="background:rgb(0, 0, 0)">
<center>
<div style="width:512px;">
<!-- CANVAS -->
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<!-- SCRIPTS -->
<script type="text/javascript">
var require = null; // fix for node.js issue (prevents game from running when opened in something like NW.js)
// if using NW.js, let ESC exit fullscreen (no way to get out of it otherwise)
if (typeof nw !== 'undefined' && nw !== null) {
nw.App.registerGlobalHotKey(new nw.Shortcut({
key: "Escape",
active: function() {
nw.Window.get().leaveFullscreen();
}
}));
}
var canvas = document.getElementById("canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// show Emscripten environment where the canvas is
// arguments are passed to PICO-8
var Module = {
arguments: ["-width","512","-height","512"],
};
Module.canvas = canvas;
/*
// When pico8_buttons is defined, PICO-8 takes each int to be a live bitfield
// representing the state of each player's buttons
var pico8_buttons = [0, 0, 0, 0, 0, 0, 0, 0]; // max 8 players
pico8_buttons[0] = 2 | 16; // example: player 0, RIGHT and Z held down
*/
</script>
<script>
var gamepads={
players:[],
available:false,
pollEveryFrame:false,
connected:false,
deadZone:0.25,
snapZone:0.25,
down:[],
justDown:[],
justUp:[],
init:function(){
if(navigator.getGamepads){
this.available=true;
}else if(navigator.webkitGetGamepads){
navigator.getGamepads=navigator.webkitGetGamepads;
this.available=true;
}
if(this.available){
console.log("Gamepad API available");
if(navigator.userAgent.indexOf('Firefox/') != -1){
// listen to connection events for firefox
$(window).on("gamepadconnected gamepaddisconnected", function(event) {
console.log("gamepad connection event");
this.pollconnections(event);
}.bind(this));
}else{
this.pollEveryFrame=true;
}
}else{
console.error("Gamepad API not available");
}
},
pollconnections:function(event){
this.connected=false;
var gps=navigator.getGamepads();
for(var i=0; i < gps.length; ++i){
var gp=gps[i];
if(gp){
if(gp.connected){
if(this.players[gp.index]==null){
// new player
this.players[gp.index]=gp;
this.players[gp.index].down=[];
this.players[gp.index].justDown=[];
this.players[gp.index].justUp=[];
}else{
// returning player, copy old button states before replacing
gp.down = this.players[gp.index].down;
gp.justDown = this.players[gp.index].justDown;
gp.justUp = this.players[gp.index].justUp;
this.players[gp.index]=gp;
}
this.connected=true;
}else{
this.players[gps[i].index]=null;
}
}
}
},
update:function(){
// poll connections and update gamepad states every frame because chrome's a lazy bum
if(this.pollEveryFrame){
this.pollconnections();
}
for(var i=0; i < this.players.length; ++i){
var p=this.getPlayer(i);
if(p && p!=null){
for(var i=0; i < p.buttons.length; ++i){
if(p.buttons[i].pressed){
p.justDown[i]=!(p.down[i]===true);
p.down[i]=true;
p.justUp[i]=false;
}else{
p.justUp[i]=p.down[i]===true;
p.down[i]=false;
p.justDown[i]=false;
}
}
}
}
},
// returns _player's gamepad
// if one doesn't exist, returns an object with gamepad properties reflecting a null state
getPlayer:function(_player){
return this.players[_player]||{connected:false,down:[],justDown:[],justUp:[],axes:[],buttons:[]};
},
// returns [x,y] representing the two axes for _player at _offset
// if abs(an axis value) is < deadZone, returns 0 instead
// if abs(1-an axis value) is < snapZone, returns 1 instead
// if _offset isn't set, sets to 0
// if _length isn't set, sets to 2
// if _player isn't set (or -1), returns the sum of everyone's axes
getAxes: function(_offset,_length,_player){
if(arguments.length < 3){
_player=-1;
if(arguments.length < 2){
_length=2;
if(arguments.length < 1){
_offset=0;
}
}
}
var axes=[];
for(var i=0;i<_length;++i){
axes[i]=0;
}
if(_player == -1){
for(var i=0; i < this.players.length; ++i){
var a=this.getAxes(_offset,_length,i);
for(var j=0;j<a.length;++j){
axes[j]+=a[j];
}
}
}else{
var a=this.getPlayer(_player).axes.slice(_offset,_length);
for(var i=0;i<a.length;++i){
if(Math.abs(a[i]) < this.deadZone){
axes[i]+=0;
}else if(Math.abs(1.0-a[i]) < this.snapZone){
axes[i]+=1;
}else if(Math.abs(-1.0-a[i]) < this.snapZone){
axes[i]-=1;
}else{
axes[i]+=a[i];
}
}
}
return axes;
},
// returns [x,y] representing the dpad for _player
// if _player isn't set (or -1), returns the sum of everyone's dpads
getDpad: function(_player){
if(arguments.length < 1){
_player=-1;
}
var dpad=[0,0];
if(_player == -1){
for(var i=0; i < this.players.length; ++i){
var d=this.getDpad(i);
dpad[0]+=d[0];
dpad[1]+=d[1];
}
}else{
if(this.isDown(15,_player)){
dpad[0]+=1;
}if(this.isDown(14,_player)){
dpad[0]-=1;
}
if(this.isDown(13,_player)){
dpad[1]+=1;
}if(this.isDown(12,_player)){
dpad[1]-=1;
}
}
return dpad;
},
// returns true if _player's _btn is currently down
// if _player isn't set (or -1), returns true for any player
isDown:function(_btn,_player){
if(arguments.length < 2){
_player=-1;
if(arguments.length < 1){
console.error("must specify a button");
}
}
if(_player == -1){
for(var i=0; i < this.players.length; ++i){
if(this.isDown(_btn,i)){
return true;
}
}
return false;
}else{
return this.getPlayer(_player).down[_btn]===true;
}
},
// returns true if _player's _btn is not currently down
// if _player isn't set (or -1), returns true for any player
isUp:function(_btn,_player){
return !this.isDown(_btn,_player);
},
// returns true if _player's _btn is currently down and WAS NOT down in previous update
// if _player isn't set (or -1), returns true for any player
isJustDown:function(_btn,_player){
if(arguments.length < 2){
_player=-1;
if(arguments.length < 1){
console.error("must specify a button");
}
}
if(_player == -1){
for(var i=0; i < this.players.length; ++i){
if(this.isJustDown(_btn,i)){
return true;
}
}
return false;
}else{
return this.getPlayer(_player).justDown[_btn]===true;
}
},
// returns true if _player's _btn is currently NOT down and WAS down in previous update
// if _player isn't set (or -1), returns true for any player
isJustUp:function(_btn,_player){
if(arguments.length < 2){
_player=-1;
if(arguments.length < 1){
console.error("must specify a button");
}
}
if(_player == -1){
for(var i=0; i < this.players.length; ++i){
if(this.isJustUp(_btn,i)){
return true;
}
}
return false;
}else{
return this.getPlayer(_player).justUp[_btn]===true
};
}
}; </script>
<script>
var pico8_buttons = [0, 0, 0, 0, 0, 0, 0, 0];
gamepads.init();
if(gamepads.available){
var thresh=(gamepads.deadZone+gamepads.snapZone)/2;
function pushGamepadToButtons(){
gamepads.update();
var stick=gamepads.getAxes(0,2);
var dpad=gamepads.getDpad();
var btns=[
stick[0] < -thresh || dpad[0] < -thresh,
stick[0] > thresh || dpad[0] > thresh,
stick[1] < -thresh || dpad[1] < -thresh,
stick[1] > thresh || dpad[1] > thresh,
gamepads.isDown(0) || gamepads.isDown(3),
gamepads.isDown(2) || gamepads.isDown(1)
];
var input=0;
for(var i=0; i<btns.length;++i){
if(btns[i]){
input|=Math.pow(2,i);
}
}
pico8_buttons[0]=input;
requestAnimationFrame(pushGamepadToButtons);
}
pushGamepadToButtons();
}
</script>
<script async type="text/javascript" src="STRUNG OUT in heaven's high.js"></script>
<script>
// key blocker. prevent cursor keys from scrolling page while playing cart.
function onKeyDown_blocker(event) {
event = event || window.event;
var o = document.activeElement;
if(!o || o == document.body || o.tagName == "canvas"){
if ([32, 37, 38, 39, 40].indexOf(event.keyCode) > -1){
if(event.preventDefault){
event.preventDefault();
}
}
}
}
document.addEventListener('keydown', onKeyDown_blocker, false);
// sometimes iframes have issues getting focus, so
// attempt to auto-focus right now and also when we get clicked
window.focus();
document.addEventListener('mousedown',function(event){
window.focus();
});
</script>
<!-- BUTTONS -->
<div class=pico8_el onclick="Module.pico8Reset();"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAaklEQVR4Ae2dOwoAMQhE15A+rfc/3bZ7AlMnQfywCkKsfcgMM9ZP+QHtIn0vLeBAFduiFdQ/0DmvtR5LXJ6CPSXe2ZXcFNlTxFbemKrbZPs35XogeS9xeQr+anT6LzoOwEDwZJ7jwhXUnwkTTiDQ2Ja34AAAABB0RVh0TG9kZVBORwAyMDExMDIyMeNZtsEAAAAASUVORK5CYII=" alt="Reset" width=12 height=12/> Reset</div><div class=pico8_el onclick="Module.pico8TogglePaused();"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAPUlEQVR4Ae3doQ0AIAxEUWABLPtPh2WCq26DwFSU/JPNT166QSu/Hg86W9dwLte+diP7AwAAAAAAgD+A+jM2ZAgo84I0PgAAABB0RVh0TG9kZVBORwAyMDExMDIyMeNZtsEAAAAASUVORK5CYII=" alt="Pause" width=12 height=12/> Pause</div><div class=pico8_el onclick="Module.requestFullScreen(true, false);"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAaklEQVR4Ae2dsQ1AIQhExfze1v2ns3UCrfgFhmgUUAoGgHscp21wX9BqaZoDojbB96OkDJKNcTN2BHTyYNYmoT2BlPL7BKgcPfHjAVXKKadkHOn9K1r16N0czN6a95N8mnA7Aq2fTZ3Af3UKmCSMazL8HwAAABB0RVh0TG9kZVBORwAyMDExMDIyMeNZtsEAAAAASUVORK5CYII=" alt="Fullscreen" width=12 height=12/> Fullscreen</div><div class=pico8_el onclick="Module.pico8ToggleSound();"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAXklEQVR4Ae2doQ4AIQxD4YLH8v9fh+ULhjpxxSwLg2uyapr1JRu1iV5Z+1BGl4+xNpX38SYo2uRvYiT5LwEmt+ocgXVLrhPEgBiw8Q5w7/kueSkK+D2tJO4E/I3GrwkqQCBabEj/4QAAABB0RVh0TG9kZVBORwAyMDExMDIyMeNZtsEAAAAASUVORK5CYII=" alt="Toggle Sound" width=12 height=12/> Sound</div><div class=pico8_el ><a target="_new" href="http://www.lexaloffle.com/bbs/?cat=7&sub=2" style="width:100%; display:inline-block;"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAlElEQVR4Ae2dMQ5FQBCGh6jcwAkkateg3DiAa+iQUGqVKi95FQfAJRQOoHeBUf8JyQqKjZ1uMzuz2e/LTE3KhyF7kSlgLOykas23f6D+A9Yp84aAOYU15pcJnfji0Il2ID8HzC4y38ZrnfIBGxeRoR3c3EWrACdsV5BOsx7OSRnrOXh4F5HzA6bevwUn8wlz7eCDsQM99B3ks0s/4QAAABB0RVh0TG9kZVBORwAyMDExMDIyMeNZtsEAAAAASUVORK5CYII=" alt="Carts" width=12 height=12/> Carts</a></div> </div>
</center>
</body>
</html>