-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·703 lines (632 loc) · 34.9 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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--
Based on https://github.com/headjump/pico8_html_template
You are free to remove this comment or leave it here so others may find and use the repo as well :)
-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="Icy's Adventure by Isla"> <!-- <= WEBAPP TITLE -->
<link rel="apple-touch-icon" href="icon.png"> <!-- <= YOUR ICON -->
<link rel="icon" href="icon.png"> <!-- <= YOUR ICON -->
<!--
Icon info:
----------
There are many different resolutions for different devices supported or recommended,
but I wanted this template to be easy to use "manually" and for me it works fine
to have a single PNG icon at 200x200. (200x200 is the minimum for facebok-sharing to use the og:image as thumbnail)
-->
<title>Icy's Adventure by Isla</title> <!-- <= WEBSITE TITLE -->
<meta name="description" content="Game description"> <!-- <= SITE DESCRIPTION as seen by web-search-engines -->
<!-- Info as seen by sharing apps like WhatsApp or Facebook, so they can show a preview-image and description when you share the URL -->
<meta property="og:type" content="game" />
<meta property="og:title" content="Icy's Adventure by Isla" /> <!-- <= GAME TITLE -->
<meta property="og:image" content="https://mmalex.github.io/icon.png" /> <!-- <= GAME IMAGE (you can also use a screenshot instead of the icon, but be sure to use the FULL URL here!) -->
<meta property="og:description" content="Icy's Adventure by Isla" /> <!-- <= GAME DESCRIPTION -->
<style TYPE="text/css">
/* ------- DEFINE BUTTON COLORS ------- */
:root {
--btn: #1288D1;
--btn--pressed: #29ADFF;
--btnIcon: #222222;
--btnIcon--pressed: #111111;
--btn__analogBg: #232f37;
}
body { font-family: Verdana, Arial, sans-serif; padding: 0; margin: 0; outline: none; background: #222; overflow: hidden; }
/* ------ POSITION GAME-CANVAS ------ */
canvas#canvas {
width: 512px; height: 512px; /* max game size: 512px */
image-rendering: optimizeSpeed;
image-rendering: -moz-crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: optimize-contrast;
image-rendering: pixelated;
-ms-interpolation-mode: nearest-neighbor;
border: 0;
}
@media screen and (max-width: 512px) { /* game shrinks to fit screen on smaller screens */
canvas#canvas { width: 100%; height: auto; } }
.canvas-wrapper { text-align: center; }
.canvas-wrapper canvas { margin: 0 auto; } /* center game */
@media screen and (min-height: 700px) { /* game has top-margin on high screens */
.canvas-wrapper { margin-top: 80px; } }
@media screen and (min-height: 880px) { /* game has more top-margin on higher screens */
.canvas-wrapper { margin-top: 180px; } }
/* ------ pico8 control buttons [reset] [pause] [mute] ------ */
.pico8_btns { text-align: center; }
.pico8_el { width:82px; display:inline-block; margin: 1px; padding: 4px; text-align: center; color:#fff; background-color:#777; font-size: 9pt; cursor: pointer; }
.pico8_el a{ text-decoration: none; color:#fff; }
.pico8_el:hover{ background-color:#aaa; }
.pico8_el:link{ background-color:#aaa; }
/* ------ HELPER CLASSES FOR TOUCH ELEMENTS ------ */
.touch-not-supported .show-if-touch { display: none; }
.touch-supported .show-if-not-touch { display: none; }
/* ------ HELPER CLASSES FOR STANDALONE ELEMENTS ------ */
.not-standalone .show-if-standalone { display: none; }
.is-standalone .show-if-not-standalone { display: none; }
</style>
</head>
<body>
<script type="text/javascript">
// ----------------- DISPLAY TOUCH CONTROLS? ----------------- %>
if(
window.location.href.indexOf("?touch") !== -1 // to test on not-touch devices: add "?touch" to the URL
||window.location.href.indexOf("&touch") !== -1
|| navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
) {
document.body.className += " touch-supported";
window.TOUCH = true;
} else {
document.body.className += " touch-not-supported";
}
// ----------------- IS STANDALONE WEBAPP? ----------------- %>
if(
window.location.href.indexOf("?standalone") !== -1 // to test on not-standalone devices: add "?standalone" to the URL
|| window.location.href.indexOf("&standalone") !== -1
|| navigator.standalone
) {
document.body.className += " is-standalone";
window.TOUCH = true;
} else {
document.body.className += " not-standalone";
}
// To test both TOUCH and STANDALONE, add "?touch&standalone" to the URL
</script>
<div class="canvas-wrapper">
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
</div>
<div>
<script type="text/javascript">
// ------ SETUP USED FOR PICO8 CART ------
var
canvas = document.getElementById("canvas"),
Module = {canvas: canvas};
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// ------ BLOCK CURSOR-KEYS FROM SCROLLING ------
var onKeyDown_blocker= function(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);
</script>
<script async type="text/javascript" src="game.js"></script> <!-- <= INCLUDES YOUR cart.js FILE -->
<!-- PICO8 CONTROL BUTTONS [reset] [pause] [fullscreen - not visible when using touch-control] [mute] -->
<div class="pico8_btns">
<span 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</span>
<span 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</span>
<span class="pico8_el show-if-not-touch" onclick="Module.requestFullScreen(true, false);">
<img
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAaklEQVR4Ae2dsQ1AIQhExfze1v2ns3UCrfgFhmgUUAoGgHscp21wX9BqaZoDojbB96OkDJKNcTN2BHTyYNYmoT2BlPL7BKgcPfHjAVXKKadkHOn9K1r16N0czN6a95N8mnA7Aq2fTZ3Af3UKmCSMazL8HwAAABB0RVh0TG9kZVBORwAyMDExMDIyMeNZtsEAAAAASUVORK5CYII="
alt="Fullscreen" width=12 height=12/> Fullscreen</span>
<span 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</span>
</div>
</div>
<!-- ASK USER TO SET THE SITE AS A STANDALONE-WEBAPP -->
<style>
.addToHomescreen__hint {
font-size: .75em;
margin: .5em 2em;
text-align: center;
color: white;
}
.sourceLink{
font-size: .75em;
margin: .5em 2em;
text-align: center;
color: white;
font-weight: bold;}
.sourceLink a{
color: var(--btn);
text-decoration: underline;
}
</style>
<style>
/* toggle between different buttonsets: */
.buttonset { display: none; }
.buttonset-use-1 .buttonset-1,
.buttonset-use-2 .buttonset-2,
.buttonset-use-3 .buttonset-3,
.buttonset-use-4 .buttonset-4,
.buttonset-use-5 .buttonset-5 { display: block; } /* Add more as you need them */
/* actual buttons: */
.btns { position: fixed; bottom: 0; width: 100%; direction:ltr; height: 90px; } /* wrapper for buttons - docks to bottom */
.btn { /* generic button style: prevent text selection on touch */
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently supported by Chrome and Opera */
height: 100%;
font-size: 35px;
font-weight: bold;
color: var(--btnIcon);
text-align: center;
width: 24%;
max-width: 180px;
}
.btn svg path {
fill: var(--btnIcon) !important;
}
@media screen and (max-height: 640px) and (min-width: 500px) { /* make canvas smaller for small screen-height to make room for touch-buttons */
canvas#canvas { max-width: 420px; height: auto; }
.btns { height: 65px; } }
@media screen and (max-height: 520px) { /* less height on low screens */
.btns { height: 50px; } }
.btn--wide { width: 35%; max-width: 200px; }
.btn--extra-wide { width: 48%; max-width: 280px; }
.pull-left { float:left; }
.pull-right { float:right; }
.axis-leftRight { position: relative; background: var(--btn);}
.axis-upDown { position: relative; background: var(--btn); height: 130%; top: -30%; }
.axis-upDownLeftRight { position: relative; height: 140%; top: -40%; }
.axis-analog { position: relative; height: 140%; top: -40%; background-color: var(--btn__analogBg); }
.btn__stick {
position: absolute; left: 50%; top: 50%;
}
.btn__stick__inner {
width: 50px; height: 50px; position: absolute; background-color: var(--btn); border-radius: 25px;
margin-left: -25px; margin-top: -25px;
}
.axis-leftRight .btn__leftArrowStyle { position: absolute; width: 50%; height: 100%; }
.axis-leftRight .btn__rightArrowStyle { position: absolute; width: 50%; height: 100%; right: 0; }
.axis-upDown .btn__upArrowStyle { position: absolute; width: 100%; height: 50%; }
.axis-upDown .btn__downArrowStyle { position: absolute; width: 100%; height: 50%; bottom: 0; }
.btn__horAxisBg {
position: absolute;
background-color: var(--btn);
top: 30%;
height: 40%;
width: 90%;
left: 5%;
}
.btn__vertAxisBg {
position: absolute;
background-color: var(--btn);
left: 35%;
width: 30%;
height: 100%;
}
.axis-upDownLeftRight .btn__leftArrowStyle {
position: absolute;
width: 30%;
left: 5%;
height: 40%;
top: 30%;
}
.axis-upDownLeftRight .btn__rightArrowStyle {
position: absolute;
width: 30%;
height: 40%;
top: 30%;
right: 5%;
}
.axis-upDownLeftRight .btn__upArrowStyle {
position: absolute;
width: 30%;
left: 35%;
height: 30%;
top: 0
}
.axis-upDownLeftRight .btn__downArrowStyle {
position: absolute;
width: 30%;
left: 35%;
height: 30%;
bottom: 0;
}
.axis-upDownLeftRight.axis-upDownLeftRight--upDownAtFullWidth .btn__upArrowStyle,
.axis-upDownLeftRight.axis-upDownLeftRight--upDownAtFullWidth .btn__downArrowStyle {
width: 100%;
left: 0;
}
.btn svg { /* center SVGs in buttons */
position: absolute;
left: 50%; top: 50%;
margin-left: -15px; margin-top: -15px;
}
.axis-upDownLeftRight.btn svg { /* D-PAD icons smaller */
width: 20px;
height: 20px;
margin-left: -10px; margin-top: -10px;
}
.btn .btn__stick__inner svg{
margin-left: -23px; margin-top: -23px;
}
.btn-fire-x, .btn-fire-o { background-color: var(--btn); position: relative; }
.pressed_X .btn-fire-x,
.pressed_O .btn-fire-o,
.pressed_U .btn__upArrowStyle--bg,
.pressed_D .btn__downArrowStyle--bg,
.pressed_L .btn__leftArrowStyle--bg,
.pressed_R .btn__rightArrowStyle--bg,
.pressed_L .axis-leftRight .btn__leftArrowStyle,
.pressed_R .axis-leftRight .btn__rightArrowStyle {
background-color: var(--btn--pressed); /* change color when pressed */
}
.pressed_X .btn-fire-x svg path,
.pressed_O .btn-fire-o svg path,
.pressed_U .btn__upArrowStyle--bg svg path,
.pressed_D .btn__downArrowStyle--bg svg path,
.pressed_L .btn__leftArrowStyle--bg svg path,
.pressed_R .btn__rightArrowStyle--bg svg path,
.pressed_L .axis-leftRight .btn__leftArrowStyle svg path,
.pressed_R .axis-leftRight .btn__rightArrowStyle svg path {
fill: var(--btnIcon--pressed) !important; /* change color when pressed */
}
.clear{ clear:both; }
</style>
<div id="btns-wrapper" class="show-if-touch clear">
<div id="btns-markUsedButtonset"><!-- Gets class for used buttonset
(don't add other classes here, they'll get overridden! -->
<div id="btns-markPressed"> <!-- Gets classes for all pressed buttons:
'pressed_L', 'pressed_R', 'pressed_U', 'pressed_D', 'pressed_X', 'pressed_O'
(don't add other classes here, they'll get overridden! -->
<!------- BUTTONSET 1 - Up, Down, Left and Right ----------
↑
← → O X
↓
(If you just want a single touch-controller, simply remove the classes "buttonset" and "buttonset-1" below and remove the other touch-controller)
-------------------------------->
<div class="btns buttonset buttonset-1">
<div class="axis-upDownLeftRight btn btn--extra-wide pull-left">
<!-- Axis background -->
<div class="btn__horAxisBg"></div>
<div class="btn__vertAxisBg"></div>
<!-- Separate divs for btn-backgrounds and icons, so highlighted backgrounds don't overlap icons of other buttons-->
<div class="btn__leftArrowStyle btn__leftArrowStyle--bg"></div>
<div class="btn__rightArrowStyle btn__rightArrowStyle--bg"></div>
<div class="btn__upArrowStyle btn__upArrowStyle--bg"></div>
<div class="btn__downArrowStyle btn__downArrowStyle--bg"></div>
<div class="btn__leftArrowStyle"><svg width="30" height="30" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path d="M22.536,0.47L3.207,15L22.536,29.53L22.536,0.47Z" style="fill:#222;"/></svg></div>
<div class="btn__upArrowStyle"><svg width="30" height="30" viewBox="0 0 8 8" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path id="UP" d="M0.113,5.409l3.487,-4.639l3.487,4.639l-6.974,0Z" style="fill:#222;"/></svg></div>
<div class="btn__downArrowStyle"><svg width="30" height="30" viewBox="0 0 8 8" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path id="DOWN" d="M7.087,1.791l-3.487,4.639l-3.487,-4.639l6.974,0Z" style="fill:#222;"/></svg></div>
<div class="btn__rightArrowStyle"><svg width="30" height="30" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path d="M7.464,0.47L26.793,15L7.464,29.53L7.464,0.47Z" style="fill:#222;"/></svg></div>
</div>
<div class="btn-fire-x btn pull-right"><svg width="30" height="30" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path d="M9.05,3.207L15,9.157L20.95,3.207L26.793,9.05L20.843,15L26.793,20.95L20.95,26.793L15,20.843L9.05,26.793L3.207,20.95L9.157,15L3.207,9.05L9.05,3.207Z" style="fill:#222;"/></svg></div>
<div class="btn-fire-o btn pull-right"><svg width="30" height="30" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><circle cx="15" cy="15" r="11.253" style="fill:#222;"/></svg></div>
<div class="clear"></div>
</div>
<!------- BUTTONSET 2 - Left and Right ----------
← → X
-------------------------------->
<div class="btns buttonset buttonset-2">
<div class="axis-leftRight btn btn--extra-wide pull-left">
<div class="btn__leftArrowStyle"><svg width="30" height="30" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path d="M22.536,0.47L3.207,15L22.536,29.53L22.536,0.47Z" style="fill:#222;"/></svg></div>
<div class="btn__rightArrowStyle"><svg width="30" height="30" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path d="M7.464,0.47L26.793,15L7.464,29.53L7.464,0.47Z" style="fill:#222;"/></svg></div>
</div>
<div class="btn-fire-x btn btn--wide pull-right"><svg width="30" height="30" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path d="M9.05,3.207L15,9.157L20.95,3.207L26.793,9.05L20.843,15L26.793,20.95L20.95,26.793L15,20.843L9.05,26.793L3.207,20.95L9.157,15L3.207,9.05L9.05,3.207Z" style="fill:#222;"/></svg></div>
<div class="clear"></div>
</div>
<!------- BUTTONSET 3 - Up and Down ----------
↑
X
↓
-------------------------------->
<div class="btns buttonset buttonset-3">
<div class="axis-upDown btn btn--wide pull-left">
<!-- Separate divs for btn-backgrounds and icons, so highlighted backgrounds don't overlap icons of other buttons-->
<div class="btn__upArrowStyle btn__upArrowStyle--bg"></div>
<div class="btn__downArrowStyle btn__downArrowStyle--bg"></div>
<div class="btn__upArrowStyle"><svg width="30" height="30" viewBox="0 0 8 8" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path id="UP" d="M0.113,5.409l3.487,-4.639l3.487,4.639l-6.974,0Z" style="fill:#222;"/></svg></div>
<div class="btn__downArrowStyle"><svg width="30" height="30" viewBox="0 0 8 8" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path id="DOWN" d="M7.087,1.791l-3.487,4.639l-3.487,-4.639l6.974,0Z" style="fill:#222;"/></svg></div>
</div>
<div class="btn-fire-x btn btn--wide pull-right"><svg width="30" height="30" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path d="M9.05,3.207L15,9.157L20.95,3.207L26.793,9.05L20.843,15L26.793,20.95L20.95,26.793L15,20.843L9.05,26.793L3.207,20.95L9.157,15L3.207,9.05L9.05,3.207Z" style="fill:#222;"/></svg></div>
<div class="clear"></div>
</div>
<!------- BUTTONSET 4 - Analog Stick ----------
↑
←O→ X
↓
gives values to GPIO from [50..150,50..150]
[100,100] is center, so to get the real value you have to subtract 100 for each axix,
which gives you a range of [-50..50] for each axis. (This is because PICO8-GPIO only supports vals from 0..255)
Example PICO8 code to get the axis:
function analog_x() if(peek(0x5f81)==0)then return 0 else return peek(0x5f81)-100 end end
function analog_y() if(peek(0x5f82)==0)then return 0 else return peek(0x5f82)-100 end end
To also support normal buttons, you can so sth like this inside PICO8:
speed_x = analog_x() / 5 -- gives values from -10 to 10 because input ranges from -50 to 50
if(btn(0))then speed_x = -10 end -- overrides speed if button is pressed
if(btn(1))then speed_x = 10 end -- .. this also ensures that the game can still be controlled via keyboard
-------------------------------->
<div class="btns buttonset buttonset-4">
<div class="axis-analog btn btn--wide pull-left">
<div class="btn__stick">
<div class="btn__stick__inner">
<svg width="46" height="46" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;">
<g id="Layer1" transform="matrix(0.536751,0,0,0.536751,6.94874,6.94874)">
<g id="RIGHT" transform="matrix(-0.878534,0,0,0.660394,49.8793,5.69665)">
<path d="M24.254,1.958L12.124,14.088L24.254,26.217L24.254,1.958Z" style="fill:rgb(34,34,34);"/>
</g>
<g id="UP" transform="matrix(-3.06037e-17,0.878534,0.660394,0,5.69665,-19.8793)">
<path d="M24.254,1.958L12.124,14.088L24.254,26.217L24.254,1.958Z" style="fill:rgb(34,34,34);"/>
</g>
<g id="DOWN" transform="matrix(-7.69858e-17,-0.878534,-0.660394,8.08749e-17,24.3034,49.8793)">
<path d="M24.254,1.958L12.124,14.088L24.254,26.217L24.254,1.958Z" style="fill:rgb(34,34,34);"/>
</g>
<g id="LEFT" transform="matrix(0.878534,0,0,0.660394,-19.8793,5.69665)">
<path d="M24.254,1.958L12.124,14.088L24.254,26.217L24.254,1.958Z" style="fill:rgb(34,34,34);"/>
</g>
</g>
</svg>
</div>
</div>
</div>
<div class="btn-fire-x btn pull-right"><svg width="30" height="30" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><path d="M9.05,3.207L15,9.157L20.95,3.207L26.793,9.05L20.843,15L26.793,20.95L20.95,26.793L15,20.843L9.05,26.793L3.207,20.95L9.157,15L3.207,9.05L9.05,3.207Z" style="fill:#222;"/></svg></div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
// --------- HANDLE TOUCH-EVENTS ON BUTTONS ---------
//
// IMPORTANT FOR TESTING:
// The buttons ONLY work with touch-events, so you can't test them
// on a regular browser with your mouse.
// Chrome allows for simulating touch-events in the developer-tools:
// -> https://developers.google.com/web/tools/chrome-devtools/device-mode/
if(window.TOUCH) {
var
GPIO_BUTTONSET_INDEX=0,
GPIO_ANALOG_X_INDEX=1,
GPIO_ANALOG_Y_INDEX=2,
pico8_buttons = [0, 0, 0, 0, 0, 0, 0, 0], // <= the first element in this array will be updated by the touch-buttons
pico8_gpio = new Array(128), // <= used to let pico8-cart change buttonset
changeButtonset; // usage: changeButtonset(2) to activates .buttonset-2
(function(){ // locally scoped
var
allAnalogSticks=document.querySelectorAll(".axis-analog .btn__stick");
var setAnalogAxis=function(x,y){
pico8_gpio[GPIO_ANALOG_X_INDEX]=x;
pico8_gpio[GPIO_ANALOG_Y_INDEX]=y;
};
var resetAnalogSticks = function(sticks_or_null) {
setAnalogAxis(100,100);
sticks_or_null || (sticks_or_null=allAnalogSticks);
var st;
for(var i=0; i<sticks_or_null.length; i++){
st=allAnalogSticks[i];
st.style.left="50%"; st.style.top="50%";
}
};
resetAnalogSticks();
changeButtonset=(function(){
classHolder=document.getElementById("btns-markUsedButtonset");
var current=-1;
// poll for pico8_gpio to check if PICO8-game wants a buttonset-change
window.setInterval(function(){
var from_pico8 = pico8_gpio[GPIO_BUTTONSET_INDEX];
if(!!from_pico8) changeButtonset(from_pico8);
},100);
return function(buttonset_number){
if(current!==buttonset_number) {
pico8_buttons[0] = 0; // reset pico btns
if(pico8_gpio[GPIO_BUTTONSET_INDEX]!==buttonset_number){
pico8_gpio[GPIO_BUTTONSET_INDEX]=buttonset_number;
}
analogs=[0,0]; // reset analog stick
classHolder.className = "buttonset-use-" + buttonset_number;
resetAnalogSticks();
current=buttonset_number;
}
};
}());
changeButtonset(1); // set starting buttonset!
var
updatePressedClasses = (function() {
var target = document.getElementById("btns-markPressed");
return function() {
var classes="",pressed=pico8_buttons[0];
for(var key_string in KEY) {
if(KEY.hasOwnProperty(key_string) && ((pressed & KEY[key_string]) > 0)) classes+= " pressed_" + key_string;
}
target.className = classes;
};
}()),
KEY = { L: 1, R: 2, U: 4, D: 8, O: 16, X: 32 },
btnDown = function(key) { pico8_buttons[0] |= key; updatePressedClasses(); },
btnUp = function(key) { pico8_buttons[0] &= ~key; updatePressedClasses(); },
btnAxis = function(active_keys) {
pico8_buttons[0] &= ~(KEY.U | KEY.D | KEY.L | KEY.R); // clear all axes
for(var i=0; i<active_keys.length;i++) { pico8_buttons[0] |= active_keys[i]; }
updatePressedClasses();
},
relTouchPosInEl = function(el, touch) {
var rect = el.getBoundingClientRect();
if(rect.width === 0 || rect.height === 0) return {x: 0, y: 0};
return {
x: Math.min(1, Math.max(0, (touch.clientX - rect.left) / rect.width)),
y: Math.min(1, Math.max(0, (touch.clientY - rect.top) / rect.height))
};
},
xAxisUpdate = function(el, touch) {
if(!touch) return; // can occur when switching buttonsets
var
pos = relTouchPosInEl(el, touch),
x_axis = 0, y_axis = 0;
if(pos.x < .4) x_axis = KEY.L;
if(pos.x > .6) x_axis = KEY.R;
btnAxis([x_axis, y_axis]);
},
yAxisUpdate = function(el, touch) {
if(!touch) return; // can occur when switching buttonsets
var
pos = relTouchPosInEl(el, touch),
x_axis = 0, y_axis = 0;
if(pos.y < .4) y_axis = KEY.U;
if(pos.y > .6) y_axis = KEY.D;
btnAxis([x_axis, y_axis]);
},
xyAxisUpdate = function(el, touch) {
if(!touch) return; // can occur when switching buttonsets
var
pos = relTouchPosInEl(el, touch),
x_axis = 0, y_axis = 0,
x_range = .3, y_range = .3;
if(pos.x < x_range) x_axis = KEY.L;
if(pos.x > 1-x_range) x_axis = KEY.R;
if(pos.y < y_range) y_axis = KEY.U;
if(pos.y > 1-y_range) y_axis = KEY.D;
btnAxis([x_axis, y_axis]);
},
analogAxisUpdate = function(el, stick, touch) {
if(!touch) return; // can occur when switching buttonsets
var
pos = relTouchPosInEl(el, touch),
x_border=.15, y_border=.15,
x_val=pos.x-.5,y_val=pos.y-.5, // both for axis-value calculation
x_stick=pos.x,y_stick=pos.y; // both for Stick-graphic placement
if(x_val<-.5+x_border)x_val=-.5+x_border;
if(x_val>.5-x_border)x_val=.5-x_border;
if(y_val<-.5+y_border)y_val=-.5+y_border;
if(y_val>.5-y_border)y_val=.5-y_border;
if(x_stick<x_border)x_stick=x_border;
if(x_stick>1-x_border)x_stick=1-x_border;
if(y_stick<y_border)y_stick=y_border;
if(y_stick>1-y_border)y_stick=1-y_border;
stick.style.left=""+Math.round(x_stick*100)+"%";
stick.style.top=""+Math.round(y_stick*100)+"%";
setAnalogAxis(Math.floor(x_val/(.5-x_border)*50+100) , Math.floor(y_val/(.5-y_border)*50+100));
},
axisEnd = function() { btnAxis([]); },
killEvt = function(evt) { evt.preventDefault(); evt.stopPropagation(); },
touchfinder=function(){
var touchid=null;
return {
fillFromTouchStart:function(evt,el){
var
touches, touch,
toucharea = el.getBoundingClientRect();
console.log(toucharea.left, toucharea.right);
if(touches = evt.changedTouches){
for(var i=0; i<touches.length; i++){
touch=touches[i];
console.log(touch.clientX);
if( // is correct touchpoint?
(touch.clientX > toucharea.left - 10) &&
(touch.clientX < toucharea.right + 10) &&
(touch.clientY > toucharea.top - 10) &&
(touch.clientY < toucharea.bottom + 10)
) {
touchid=touch.identifier;
return touch;
}
}
}
touchid=null;
return null;
},
findFromTouchMove:function(evt){
if(touchid === null) return null;
var touches,touch;
if(touches=evt.changedTouches) {
for(var i=0; i<touches.length; i++){
touch=touches[i];
if(touch.identifier===touchid) { return touch; }
}
}
return null;
},
clear:function(){ touchid = null; }
};
},
addAnalogAxis = function(el) {
var
stick=el.querySelector('.btn__stick'),
find_my_touch=touchfinder();
el.addEventListener("touchstart", function(evt){ killEvt(evt); analogAxisUpdate(el, stick, find_my_touch.fillFromTouchStart(evt,el)); }, false);
el.addEventListener("touchmove", function(evt){ killEvt(evt); analogAxisUpdate(el, stick, find_my_touch.findFromTouchMove(evt)); }, false);
el.addEventListener("touchend", function(evt){ find_my_touch.clear(); killEvt(evt); resetAnalogSticks([stick]); }, false);
el.addEventListener("touchcancel", function(evt){ find_my_touch.clear(); killEvt(evt); resetAnalogSticks([stick]); }, false);
},
addXAxis = function(el) {
var find_my_touch=touchfinder();
el.addEventListener("touchstart", function(evt){ killEvt(evt); xAxisUpdate(el, find_my_touch.fillFromTouchStart(evt,el)); }, false);
el.addEventListener("touchmove", function(evt){ killEvt(evt); xAxisUpdate(el, find_my_touch.findFromTouchMove(evt)); }, false);
el.addEventListener("touchend", function(evt){ find_my_touch.clear(); killEvt(evt); axisEnd(); }, false);
el.addEventListener("touchcancel", function(evt){ find_my_touch.clear(); killEvt(evt); axisEnd(); }, false);
},
addYAxis = function(el) {
var find_my_touch=touchfinder();
el.addEventListener("touchstart", function(evt){ killEvt(evt); yAxisUpdate(el, find_my_touch.fillFromTouchStart(evt,el)); }, false);
el.addEventListener("touchmove", function(evt){ killEvt(evt); yAxisUpdate(el, find_my_touch.findFromTouchMove(evt)); }, false);
el.addEventListener("touchend", function(evt){ find_my_touch.clear(); killEvt(evt); axisEnd(); }, false);
el.addEventListener("touchcancel", function(evt){ find_my_touch.clear(); killEvt(evt); axisEnd(); }, false);
},
addXYAxis = function(el) {
var find_my_touch=touchfinder();
el.addEventListener("touchstart", function(evt){ killEvt(evt); xyAxisUpdate(el, find_my_touch.fillFromTouchStart(evt,el)); }, false);
el.addEventListener("touchmove", function(evt){ killEvt(evt); xyAxisUpdate(el, find_my_touch.findFromTouchMove(evt)); }, false);
el.addEventListener("touchend", function(evt){ find_my_touch.clear(); killEvt(evt); axisEnd(); }, false);
el.addEventListener("touchcancel", function(evt){ find_my_touch.clear(); killEvt(evt); axisEnd(); }, false);
},
addButton = function(el, key) {
el.addEventListener("touchstart", function(evt){ killEvt(evt); btnDown(key); }, false);
el.addEventListener("touchmove", killEvt, false);
el.addEventListener("touchend", function(evt){ killEvt(evt); btnUp(key); }, false);
el.addEventListener("touchcancel", function(evt){ killEvt(evt); btnUp(key); }, false);
};
var
axisXs=document.getElementsByClassName("axis-leftRight"),
axisXYs=document.getElementsByClassName("axis-upDownLeftRight"),
axisYs=document.getElementsByClassName("axis-upDown"),
axisAnalogs=document.getElementsByClassName("axis-analog"),
xBtns=document.getElementsByClassName("btn-fire-x"),
oBtns=document.getElementsByClassName("btn-fire-o"),
i;
for(i=0; i<axisXs.length; i++){ addXAxis(axisXs[i]); }
for(i=0; i<axisXYs.length; i++){ addXYAxis(axisXYs[i]); }
for(i=0; i<axisYs.length; i++){ addYAxis(axisYs[i]); }
for(i=0; i<axisAnalogs.length; i++){ addAnalogAxis(axisAnalogs[i]); }
for(i=0; i<xBtns.length; i++){ addButton(xBtns[i], KEY.X); }
for(i=0; i<oBtns.length; i++){ addButton(oBtns[i], KEY.O); }
// prevent "tilt-zooming" when accidentally touching between the buttons
document.getElementById("btns-wrapper").addEventListener("touchstart", function(evt){ evt.preventDefault(); }, false);
})();
}
</script>
</body></html>