littlejsengine 1.11.9 → 1.11.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/littlejs.d.ts +485 -492
- package/dist/littlejs.esm.js +548 -529
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +546 -525
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +502 -484
- package/examples/htmlMenu/game.js +11 -1
- package/examples/htmlMenu/index.html +1 -10
- package/examples/module/game.js +2 -2
- package/examples/shorts/base.html +1 -1
- package/examples/starter/build/index.html +2 -0
- package/examples/starter/build/index.js +1 -0
- package/examples/starter/build/tiles.png +0 -0
- package/examples/starter/build.js +13 -3
- package/examples/starter/game.js +8 -1
- package/examples/starter/game.zip +0 -0
- package/examples/typescript/build/dist/littlejs.esm.js +4834 -0
- package/examples/typescript/build/examples/typescript/build.js +24 -0
- package/examples/typescript/build/examples/typescript/game.js +102 -0
- package/examples/typescript/build.bat +5 -0
- package/examples/typescript/build.js +33 -0
- package/examples/typescript/game.js +102 -0
- package/examples/typescript/game.ts +134 -0
- package/examples/typescript/index.html +10 -0
- package/examples/typescript/tiles.png +0 -0
- package/examples/typescript/tsconfig.json +8 -0
- package/package.json +1 -1
- package/plugins/newgrounds.js +44 -35
- package/plugins/postProcess.js +18 -4
- package/plugins/uiSystem.js +196 -30
- package/src/engine.js +21 -20
- package/src/engineAudio.js +59 -59
- package/src/engineDebug.js +44 -41
- package/src/engineDraw.js +58 -58
- package/src/engineExport.js +2 -4
- package/src/engineInput.js +40 -35
- package/src/engineMedals.js +21 -11
- package/src/engineObject.js +42 -35
- package/src/engineParticles.js +10 -10
- package/src/engineSettings.js +77 -82
- package/src/engineTileLayer.js +21 -21
- package/src/engineUtilities.js +150 -150
- package/src/engineWebGL.js +3 -3
|
@@ -14,6 +14,16 @@ setShowSplashScreen(true);
|
|
|
14
14
|
// sound effects
|
|
15
15
|
const sound_click = new Sound([1,.5]);
|
|
16
16
|
|
|
17
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
18
|
+
|
|
19
|
+
// html menu system
|
|
20
|
+
const getMenuVisible = ()=> menu.style.visibility != 'hidden';
|
|
21
|
+
function setMenuVisible(visible)
|
|
22
|
+
{
|
|
23
|
+
menu.style.visibility = visible ? 'visible' : 'hidden';
|
|
24
|
+
setInputPreventDefault(!visible); // don't prevent default when menu is visible
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
///////////////////////////////////////////////////////////////////////////////
|
|
18
28
|
function gameInit()
|
|
19
29
|
{
|
|
@@ -38,7 +48,7 @@ function gameUpdatePost()
|
|
|
38
48
|
|
|
39
49
|
// toggle menu visibility
|
|
40
50
|
if (keyWasPressed('KeyM'))
|
|
41
|
-
setMenuVisible(
|
|
51
|
+
setMenuVisible(true);
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
flex-direction: column;
|
|
25
25
|
border: 3px solid black;
|
|
26
26
|
background-color: white;
|
|
27
|
+
visibility: hidden;
|
|
27
28
|
}
|
|
28
29
|
</style>
|
|
29
30
|
|
|
@@ -40,16 +41,6 @@ This is an example menu using html elements.
|
|
|
40
41
|
<button onclick="setMenuVisible(false)">Exit Menu</button>
|
|
41
42
|
</div>
|
|
42
43
|
</div>
|
|
43
|
-
<script>
|
|
44
|
-
|
|
45
|
-
// html menu system
|
|
46
|
-
const getMenuVisible =()=> menu.style.visibility != 'hidden';
|
|
47
|
-
const setMenuVisible =(visible)=> menu.style.visibility = visible ? '' : 'hidden';
|
|
48
|
-
|
|
49
|
-
// hide menu at start
|
|
50
|
-
setMenuVisible(false);
|
|
51
|
-
|
|
52
|
-
</script>
|
|
53
44
|
|
|
54
45
|
<!-- Add your game scripts here -->
|
|
55
46
|
<script src=../../dist/littlejs.js?1117></script>
|
package/examples/module/game.js
CHANGED
|
@@ -63,7 +63,7 @@ function gameInit()
|
|
|
63
63
|
|
|
64
64
|
// move camera to center of collision
|
|
65
65
|
LittleJS.setCameraPos(tileCollisionSize.scale(.5));
|
|
66
|
-
LittleJS.setCameraScale(
|
|
66
|
+
LittleJS.setCameraScale(32);
|
|
67
67
|
|
|
68
68
|
// enable gravity
|
|
69
69
|
LittleJS.setGravity(-.01);
|
|
@@ -126,7 +126,7 @@ function gameRender()
|
|
|
126
126
|
function gameRenderPost()
|
|
127
127
|
{
|
|
128
128
|
// draw to overlay canvas for hud rendering
|
|
129
|
-
LittleJS.
|
|
129
|
+
LittleJS.drawTextScreen('LittleJS with Modules', vec2(LittleJS.mainCanvasSize.x/2, 80), 80);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
<!DOCTYPE html><head><title>Little JS Starter Project</title></head><body><script>const h=Math.PI;function aa(t,i=1){return(t%i+i)%i}function k(t,i=0,e=1){return t<i?i:e<t?e:t}function r(t,i,e){return(e-=i)?k((t-i)/e):0}function ba(t,i,e,a=u()){return 2*Math.abs(t.x-e.x)<i.x+a.x&&2*Math.abs(t.y-e.y)<i.y+a.y}function ha(t=ia){return.5*(1-Math.cos(2*t*h))}function v(t=1,i=0){return i+Math.random()*(t-i)}function ja(t=1){return ma(new w,v(2*h),t)}function na(t=1){return 0<t?ja(t*v(0/t,1)**.5):new w}function oa(t=new x,i=new x(0,0,0,1),e=!1){return e?t.la(i,v()):new x(v(t.r,i.r),v(t.j,i.j),v(t.b,i.b),v(t.a,i.a))}function u(t=0,i){return"number"==typeof t?new w(t,null==i?t:i):new w(t.x,t.y)}function ma(t,i=0,e=1){return t.x=e*Math.sin(i),t.y=e*Math.cos(i),t}function pa(t){return t.x**2+t.y**2}function qa(t){var i=t.length();return 1<i?t.scale(1/i):t}function ra(t,i){return 0<=t.x&&0<=t.y&&t.x<i.x&&t.y<i.y}class w{constructor(t=0,i=0){this.x=t,this.y=i}set(t=0,i=0){return this.x=t,this.y=i,this}v(){return new w(this.x,this.y)}add(t){return new w(this.x+t.x,this.y+t.y)}u(t){return new w(this.x-t.x,this.y-t.y)}multiply(t){return new w(this.x*t.x,this.y*t.y)}U(t){return new w(this.x/t.x,this.y/t.y)}scale(t){return new w(this.x*t,this.y*t)}length(){return pa(this)**.5}normalize(t=1){var i=this.length();return i?this.scale(t/i):new w(0,t)}angle(){return Math.atan2(this.x,this.y)}rotate(t){var i=Math.cos(-t);return t=Math.sin(-t),new w(this.x*i-this.y*t,this.x*t+this.y*i)}setDirection(t,i=1){return u((t=aa(t,4))%2?t-1?-i:i:0,t%2?0:t?-i:i)}direction(){return Math.abs(this.x)>Math.abs(this.y)?this.x<0?3:1:this.y<0?2:0}floor(){return new w(Math.floor(this.x),Math.floor(this.y))}la(t,i){return this.add(t.u(this).scale(k(i)))}toString(){}}function y(t=0,i=0,e=1,a=1){var s=new x,h=(t=aa(t,1),i=k(i),e=k(e),(t,i,e)=>6*(e=aa(e,1))<1?t+6*(i-t)*e:2*e<1?i:3*e<2?t+(i-t)*(4-6*e):t);return s.r=h(e=2*e-(i=e<.5?e*(1+i):e+i-e*i),i,t+1/3),s.j=h(e,i,t),s.b=h(e,i,t-1/3),s.a=a,s}function sa(t){return(255*k(t.r)|0)+(255*k(t.j)<<8)+(255*k(t.b)<<16)+(255*k(t.a)<<24)}class x{constructor(t=1,i=1,e=1,a=1){this.r=t,this.j=i,this.b=e,this.a=a}set(t=1,i=1,e=1,a=1){return this.r=t,this.j=i,this.b=e,this.a=a,this}v(){return new x(this.r,this.j,this.b,this.a)}add(t){return new x(this.r+t.r,this.j+t.j,this.b+t.b,this.a+t.a)}u(t){return new x(this.r-t.r,this.j-t.j,this.b-t.b,this.a-t.a)}multiply(t){return new x(this.r*t.r,this.j*t.j,this.b*t.b,this.a*t.a)}U(t){return new x(this.r/t.r,this.j/t.j,this.b/t.b,this.a/t.a)}scale(t,i=t){return new x(this.r*t,this.j*t,this.b*t,this.a*i)}la(t,i){return this.add(t.u(this).scale(k(i)))}toString(t=!0){var i=t=>((t=255*k(t)|0)<16?"0":"")+t.toString(16);return"#"+i(this.r)+i(this.j)+i(this.b)+(t?i(this.a):"")}}let A=u(),B=32,ta=u(1920,1080),ua=u(),va=!1,za=u(16),Aa=0,Ba=0,Ca=u(640,80);function Da(t){var i,e=t.parent;e&&(i=e.o?-1:1,t.i=t.ya.multiply(u(i,1)).rotate(e.angle).add(e.i),t.angle=i*t.xa+e.angle);for(const a of t.children)Da(a)}function Ea(t){if(!t.A){t.A=1,t.parent&&t.parent.removeChild(t);for(const i of t.children)Ea(i,i.parent=0)}}class Fa{constructor(t=u(),i=u(1),e,a=0,s=new x,h=0){this.i=t.v(),this.size=i,this.ua=void 0,this.l=e,this.angle=a,this.color=s,this.sa=void 0,this.o=!1,this.J=this.D=this.h=1,this.s=0,this.W=.8,this.N=1,this.P=h,this.g=u(),this.R=0,this.ra=ia,this.children=[],this.ba=!0,this.parent=this.m=void 0,this.ya=u(),this.xa=0,this.ka=this.ca=this.K=!1,C.push(this)}update(){var t;if(!this.parent&&(this.ba?(this.g.x=k(this.g.x,-1,1),this.g.y=k(this.g.y,-1,1)):1<(t=pa(this.g))&&(this.g.x*=t=1/t**.5,this.g.y*=t),t=this.i.v(),this.g.x*=this.D,this.g.y*=this.D,this.h&&(this.g.y+=Ba*this.N),this.i.x+=this.g.x,this.i.y+=this.g.y,this.angle+=this.R*=this.J,this.h)){var i,e,a,s,h,n,r=this.g.y<0;if(this.m&&(i=this.m.g?this.m.g.x:0,this.g.x=i+(this.g.x-i)*this.W,this.m=void 0),this.ca)for(var o of Ga)!this.ka&&!o.ka||o.A||o.parent||o==this||ba(this.i,this.size,o.i,o.size)&&(ba(t,this.size,o.i,o.size)?(i=(e=(i=t.u(o.i)).length())<.01?ja(.001):i.scale(.001/e),this.g=this.g.add(i),o.h&&(o.g=o.g.u(i))):(e=this.size.add(o.size),a=2*(t.y-o.i.y)>e.y+Ba,s=2*Math.abs(t.y-o.i.y)<e.y,h=2*Math.abs(t.x-o.i.x)<e.x,i=Math.max(this.s,o.s),!a&&!h&&s||(this.i.y=o.i.y+(e.y/2+.001)*Math.sign(t.y-o.i.y),o.m&&r||!o.h?(r&&(this.m=o),this.g.y*=-i):o.h&&(h=(this.h*this.g.y+o.h*o.g.y)/(this.h+o.h),n=o.g.y*(o.h-this.h)/(this.h+o.h)+2*this.g.y*this.h/(this.h+o.h),this.g.y=h+k(i)*(this.g.y*(this.h-o.h)/(this.h+o.h)+2*o.g.y*o.h/(this.h+o.h)-h),o.g.y=h+k(i)*(n-h))),!a&&s&&(this.i.x=o.i.x+(e.x/2+.001)*Math.sign(t.x-o.i.x),o.h?(e=(this.h*this.g.x+o.h*o.g.x)/(this.h+o.h),a=o.g.x*(o.h-this.h)/(this.h+o.h)+2*this.g.x*this.h/(this.h+o.h),this.g.x=e+k(i)*(this.g.x*(this.h-o.h)/(this.h+o.h)+2*o.g.x*o.h/(this.h+o.h)-e),o.g.x=e+k(i)*(a-e)):this.g.x*=-i)));this.K&&Ha(this.i,this.size,this)&&!Ha(t,this.size,this)&&(o=Ha(u(this.i.x,t.y),this.size,this),!Ha(u(t.x,this.i.y),this.size,this)&&o||(this.g.y*=-this.s,r?(this.i.y=(t.y-this.size.y/2|0)+this.size.y/2+1e-4,this.m=this):(this.i.y=t.y,this.m=void 0)),o)&&(this.i.x=t.x,this.g.x*=-this.s)}}C(){Ia(this.i,this.ua||this.size,this.l,this.color,this.angle,this.o,this.sa)}removeChild(t){t.parent==this&&this.children.includes(t),this.children.splice(this.children.indexOf(t),1),t.parent=0}toString(){}}let D,E,G,I,J=u(),K=[];function Ja(t=u(),i=za,e=0,a=0){"number"==typeof i&&(i=u(i));var s=K[e],h=i.add(u(2*a));return"number"==typeof t&&(t=0<(s=s.size.x/h.x|0)?u(t%s,t/s|0):u()),t=u(t.x*h.x+a,t.y*h.y+a),new Ka(t,i,e,a)}class Ka{constructor(t=u(),i=za,e=0,a=0){this.i=t.v(),this.size=i.v(),this.Z=e,this.padding=a}offset(t){return new Ka(this.i.add(t),this.size,this.Z)}frame(t){return this.offset(u(t*(this.size.x+2*this.padding),0))}}class La{constructor(t){this.image=t,this.size=u(t.width,t.height);var i=L.createTexture();L.bindTexture(L.TEXTURE_2D,i),t&&t.width?L.texImage2D(L.TEXTURE_2D,0,L.RGBA,L.RGBA,L.UNSIGNED_BYTE,t):(t=new Uint8Array([255,255,255,255]),L.texImage2D(L.TEXTURE_2D,0,L.RGBA,1,1,0,L.RGBA,L.UNSIGNED_BYTE,t)),t=L.NEAREST,L.texParameteri(L.TEXTURE_2D,L.TEXTURE_MIN_FILTER,t),L.texParameteri(L.TEXTURE_2D,L.TEXTURE_MAG_FILTER,t),this.ja=i}}function Ma(){var t=Pa;return new w((t.x-J.x/2+.5)/B+A.x,(t.y-J.y/2+.5)/-B+A.y)}function Qa(t){return new w((t.x-A.x)*B+J.x/2-.5,(t.y-A.y)*-B+J.y/2-.5)}function Ia(t,i=u(1),h,n=new x,e=0,a,s=new x(0,0,0,0),r=!0){const o=h&&K[h.Z];var l,c,b,d;r?o?(d=u(1).U(o.size),r=h.i.x*d.x,l=h.i.y*d.y,c=h.size.x*d.x,b=h.size.y*d.y,d=d.scale(Aa),Ra(o.ja),Sa(t.x,t.y,a?-i.x:i.x,i.y,e,r+d.x,l+d.y,r-d.x+c,l-d.y+b,sa(n),sa(s))):Sa(t.x,t.y,i.x,i.y,e,0,0,0,0,0,sa(n)):Ta(t,i=u(i.x,-i.y),e,a,t=>{var i,e,a,s;o?(i=h.i.x+Aa,e=h.i.y+Aa,a=h.size.x-2*Aa,s=h.size.y-2*Aa,t.globalAlpha=n.a,t.drawImage(o.image,i,e,a,s,-.5,-.5,1,1),t.globalAlpha=1):(t.fillStyle=n.toString(),t.fillRect(-.5,-.5,1,1))})}function Ta(t,i,e,a,s){var h=E;t=Qa(t),i=i.scale(B),h.save(),h.translate(t.x+.5,t.y+.5),h.rotate(e),h.scale(a?-i.x:i.x,-i.y),s(h),h.restore()}function Ua(t,i,e=1,a=new x,s=0,h=new x(0,0,0),n="center"){var r=I;r.fillStyle=a.toString(),r.lineWidth=s,r.strokeStyle=h.toString(),r.textAlign=n,r.font=e+"px arial",r.textBaseline="middle",r.lineJoin="round",i=i.v(),t=(t+"").split("\n"),i.y-=(t.length-1)*e/2,t.forEach(t=>{s&&r.strokeText(t,i.x,i.y,void 0),r.fillText(t,i.x,i.y,void 0),i.y+=e})}function Va(t,i=0){return O[i]&&!!(1&O[i][t])}let Wa=u(),Pa=u(),Xa=0,Ya=!1;function Za(t,i=0){return Va(t,i+1)}let O=[[]];function $a(){for(const t of O)for(const i in t)t[i]&=1;Xa=0}function ab(){function i(t){return"KeyW"==t?"ArrowUp":"KeyS"==t?"ArrowDown":"KeyA"==t?"ArrowLeft":"KeyD"==t?"ArrowRight":t}onkeydown=t=>{t.repeat||(Ya=!1,O[0][t.code]=3,O[0][i(t.code)]=3)},onkeyup=t=>{O[0][t.code]=4,O[0][i(t.code)]=4},onmousedown=t=>{P&&"running"!=P.state&&P.resume(),Ya=!1,O[0][t.button]=3,Pa=bb(t),t.button&&t.preventDefault()},onmouseup=t=>O[0][t.button]=2&O[0][t.button]|4,onmousemove=t=>Pa=bb(t),onwheel=t=>Xa=t.ctrlKey?0:Math.sign(t.deltaY),oncontextmenu=()=>!1,onblur=()=>{O=[[]]},cb&&db()}function bb(t){var i=D.getBoundingClientRect();return u(r(t.x,i.left,i.right)*D.width,r(t.y,i.top,i.bottom)*D.height)}const eb=[];function fb(){var i,e;if(navigator&&navigator.getGamepads&&document.hasFocus()){var a=navigator.getGamepads();for(let t=a.length;t--;){var s=a[t],h=O[t+1]||(O[t+1]=[]),n=eb[t]||(eb[t]=[]);if(s){for(var o=0;o<s.axes.length-1;o+=2)n[o>>1]=(i=u(s.axes[o],s.axes[o+1]),void 0,qa(u((e=t=>.3<t?r(t,.3,.8):t<-.3?-r(-t,.3,.8):0)(i.x),e(-i.y))));for(o=s.buttons.length;o--;){var l=s.buttons[o],c=Za(o,t);h[o]=l.pressed?c?1:3:c?4:0,Ya||=!t&&l.pressed}pa(s=u((Za(15,t)&&1)-(Za(14,t)&&1),(Za(12,t)&&1)-(Za(13,t)&&1)))&&(n[0]=qa(s))}}}}const cb=void 0!==window.ontouchstart;function db(){function i(t){P&&"running"!=P.state&&P.resume();var i=t.touches.length;return i?(Pa=bb(u(t.touches[0].clientX,t.touches[0].clientY)),e?Ya=!1:O[0][0]=3):e&&(O[0][0]=2&O[0][0]|4),e=i,document.hasFocus()&&t.preventDefault(),!0}document.addEventListener("touchstart",t=>i(t),{passive:!1}),document.addEventListener("touchmove",t=>i(t),{passive:!1}),document.addEventListener("touchend",t=>i(t),{passive:!1}),onmousedown=onmouseup=()=>0;let e}let P=new AudioContext,gb;class hb{constructor(){var t=[1,.5];this.Ba=40,this.Fa=.7,this.O=0,t&&(this.O=null!=t[1]?t[1]:.05,t[1]=0,this.qa=[ib(...t)],this.sampleRate=44100)}play(t,i=1,e=1,a=1,s=!1){if(this.qa){var h;if(t){if(h=this.Ba){var n=A;if(h*h<(n=(A.x-t.x)**2+(n.y-t.y)**2))return;i*=r(n**.5,h,h*this.Fa)}h=2*Qa(t).x/D.width-1}return t=e+e*this.O*a*v(-1,1),this.va=P.createGain(),this.source=jb(this.qa,i,t,h,s,this.sampleRate,this.va)}}stop(){this.source&&this.source.stop(),this.source=void 0}}function jb(t,i=1,e=1,a=0,s=!1,h=44100,n){const r=P.createBuffer(t.length,t[0].length,h),o=P.createBufferSource();return t.forEach((t,i)=>r.getChannelData(i).set(t)),o.buffer=r,o.playbackRate.value=e,o.loop=s,(n=n||P.createGain()).gain.value=i,n.connect(gb),t=new StereoPannerNode(P,{pan:k(a,-1,1)}),o.connect(t).connect(n),"running"!=P.state?P.resume().then(()=>o.start()):o.start(),o}function ib(t=1,i=.05,e=220,a=0,s=0,n=.1,r=0,o=1,u=0,l=0,c=0,b=0,x=0,d=0,y=0,g=0,f=0,m=1,w=0,p=0,L=0){var A=2*h,G=u*=500*A/44100/44100;i=e*=v(1+i,1-i)*A/44100;let E=[],D=0,J=0,R=0,T=1,W=0,_=0,M=0;var S=A*Math.abs(L)*2/44100,B=Math.cos(S),P=1+(z=Math.sin(S)/2/2),S=-2*B/P,z=(1-z)/P;let U=(1+Math.sign(L)*B)/2/P,j=-(Math.sign(L)+B)/P,I=0,C=0,F=0,O=0;for(l*=500*A/44100**3,y*=A/44100,c*=A/44100,b*=44100,x=44100*x|0,P=(a=44100*a+9)+(w*=44100)+(s*=44100)+(n*=44100)+(f*=44100)|0;R<P;E[R++]=M*t)++_%(100*g|0)||(M=r?1<r?2<r?3<r?Math.sin(D**3):k(Math.tan(D),1,-1):1-(2*D/A%2+2)%2:1-4*Math.abs(Math.round(D/A)-D/A):Math.sin(D),M=(x?1-p+p*Math.sin(A*R/x):1)*Math.sign(M)*Math.abs(M)**o*(R<a?R/a:R<a+w?1-(R-a)/w*(1-m):R<a+w+s?m:R<P-f?(P-R-f)/n*m:0),M=f?M/2+(f>R?0:(R<P-f?1:(P-R)/f)*E[R-f|0]/2/t):M,L&&(M=O=U*I+j*(I=C)+U*(C=M)-z*F-S*(F=O))),B=(e+=u+=l)*Math.cos(y*J++),D+=B+B*d*Math.sin(R**5),T&&++T>b&&(e+=c,i+=c,T=0),!x||++W%x||(e=i,u=G,T=T||1);return E}let pb=[],Q=u();function Ha(t,i=u(),e){var a=Math.max(t.x-i.x/2|0,0),s=Math.max(t.y-i.y/2|0,0),h=Math.min(t.x+i.x/2,Q.x);for(t=Math.min(t.y+i.y/2,Q.y);s<t;++s)for(i=a;i<h;++i){var n=pb[s*Q.x+i];if(n&&(!e||0<n))return!0}return!1}class qb{constructor(t,i=0,e=!1,a=new x){this.$=t,this.direction=i,this.o=e,this.color=a}clear(){this.$=this.direction=0,this.o=!1,this.color=new x}}function rb(t,i,e=!0){var a=t.l.size;e&&(e=i.multiply(a),t.context.clearRect(e.x,t.canvas.height-e.y,a.x,-a.y)),null!=(e=t.getData(i)).$&&(i=i.add(u(.5)),t=Ja(e.$,a,t.l.Z,t.l.padding),Ia(i,u(1),t,e.color,e.direction*h/2,e.o))}class sb extends Fa{constructor(t,i=Q){var e=Ja(),a=u(1);for(super(t,i,e,0,void 0,0),this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.scale=a,this.wa=!1,this.data=[],t=this.size,t=Math.abs(t.x*t.y);t--;)this.data.push(new qb)}setData(t,i,e=!1){ra(t,this.size)&&(this.data[(0|t.y)*this.size.x+t.x|0]=i,e)&&rb(this,t)}getData(t){return ra(t,this.size)&&this.data[(0|t.y)*this.size.x+t.x|0]}update(){}C(){let t=Qa(this.i.add(u(0,this.size.y*this.scale.y)));t=t.floor(),(this.wa?I:E).drawImage(this.canvas,t.x,t.y,B*this.size.x*this.scale.x,B*this.size.y*this.scale.y)}}function tb(t){var i="number"==typeof t.V?na(t.V/2):u(v(-.5,.5),v(-.5,.5)).multiply(t.V).rotate(t.angle);let e=v(t.na,-t.na);t.X||(i=t.i.add(i),e+=t.angle);const a=t.O;var s=(o=t=>t+t*v(a,-a))(t.Aa),h=o(t.Y),n=o(t.Da),r=o(t.speed),o=o(t.ta)*(2*Math.floor(v(2,0))-1),l=v(t.ga,-t.ga),c=oa(t.S,t.T,t.pa),b=oa(t.da,t.ea,t.pa),l=t.X?l:t.angle+l;(i=new ub(i,t.l,e,c,b,s,h,n,t.G,t.I,t.H,t.X&&t,t.za)).g=ma(u(),l,r),i.R=o,i.G=t.G,i.D=t.D,i.J=t.J,i.s=t.s,i.W=t.W,i.N=t.N,i.K=t.K,i.P=t.P,i.o=!!Math.floor(v(2,0)),t.oa&&t.oa(i)}class vb extends Fa{constructor(t,i,e=0,a=0,s=100,n=h,r,o=new x,l=new x,c=new x(1,1,1,0),b=new x(1,1,1,0),d=.5,y=.1,g=1,f=.1,v=.05,m=1,w=1,p=0,L=h,A=.1,E=.2,D=!1,R=!1,T=!0,M=R?1e9:0,S=!1){super(t,u(),r,i,void 0,M),this.V=e,this.ia=a,this.ha=s,this.ga=n,this.S=o,this.T=l,this.da=c,this.ea=b,this.pa=T,this.Aa=d,this.Y=y,this.Da=g,this.speed=f,this.ta=v,this.D=m,this.J=w,this.N=p,this.na=L,this.G=A,this.O=E,this.K=D,this.I=R,this.X=S,this.H=0,this.oa=this.za=void 0,this.F=0}update(){if(this.parent&&super.update(),!this.ia||ia-this.ra<=this.ia){if(+this.ha){var t=1/this.ha;for(this.F+=wb;0<this.F;this.F-=t)tb(this)}}else Ea(this)}C(){}}class ub extends Fa{constructor(t,i,e,a,s,h,n,r,o,l,c,b,x){super(t,u(),i,e),this.M=a,this.L=s.u(a),this.ma=h,this.Y=n,this.Ea=r-n,this.G=o,this.I=l,this.H=c,this.B=b,this.fa=x,this.ba=!1}C(){var t=0<this.ma?Math.min((ia-this.ra)/this.ma,1):1,i=u(this.Y+t*this.Ea),e=this.G/2,e=new x(this.M.r+t*this.L.r,this.M.j+t*this.L.j,this.M.b+t*this.L.b,(this.M.a+t*this.L.a)*(t<e?t/e:1-e<t?(1-t)/e:1));this.I&&(xb=!0);let a=this.i;var s,h,n=this.angle;this.B&&(a=this.B.i.add(a.rotate(-this.B.angle)),n+=this.B.angle),this.H?(s=this.g,(n=(s=this.B?s.rotate(-this.B.angle):s).length())&&(s=s.scale(1/n),h=n*this.H,i.y=Math.max(i.x,h),n=s.angle(),Ia(a.add(s.multiply(u(0,-h/2))),i,this.l,e,n,this.o))):Ia(a,i,this.l,e,n,this.o),this.I&&(xb=void 0),1==t&&(this.color=e,this.size=i,this.fa&&this.fa(this),this.A=1)}}const yb={};let zb=[],Ab,Bb;function Cb(i){Object.values(yb).forEach(t=>i(t))}class Db{constructor(){this.id=0,this.name="Example Medal",this.description="Welcome to LittleJS!",this.icon="🏆",this.aa=!1,yb[0]=this}unlock(){this.aa||(localStorage[Ab+"_"+this.id]=this.aa=!0,zb.push(this))}C(t=0){var i=I,e=Math.min(Ca.x,D.width),a=G.width-e;t*=-Ca.y,i.save(),i.beginPath(),i.fillStyle=new x(.9,.9,.9).toString(),i.strokeStyle=new x(0,0,0).toString(),i.lineWidth=3,i.rect(a,t,e,Ca.y),i.fill(),i.stroke(),i.clip(),e=u(a+15+25,t+Ca.y/2),this.image?I.drawImage(this.image,e.x-25,e.y-25,50,50):Ua(this.icon,e,35,new x(0,0,0)),a=u(a+50+30,t+28),Ua(this.name,a,38,new x(0,0,0),0,void 0,"left"),a.y+=32,Ua(this.description,a,24,new x(0,0,0),0,void 0,"left"),i.restore()}}let R,L,Eb,Fb,Gb,Hb,U,Ib,V,xb,Jb;function Kb(){R=document.createElement("canvas"),L=R.getContext("webgl2",{antialias:!0}),D.parentElement.appendChild(R);var t=L.createProgram();L.attachShader(t,Ob("#version 300 es\nprecision highp float;uniform mat4 m;in vec2 g;in vec4 p,u,c,a;in float r;out vec2 v;out vec4 d,e;void main(){vec2 s=(g-.5)*p.zw;gl_Position=m*vec4(p.xy+s*cos(r)-vec2(-s.y,s)*sin(r),1,1);v=mix(u.xw,u.zy,g);d=c;e=a;}",L.VERTEX_SHADER)),L.attachShader(t,Ob("#version 300 es\nprecision highp float;uniform sampler2D s;in vec2 v;in vec4 d,e;out vec4 c;void main(){c=texture(s,v)*d+e;}",L.FRAGMENT_SHADER)),L.linkProgram(t),Eb=t,t=new ArrayBuffer(44e4),U=new Float32Array(t),Ib=new Uint32Array(t),Gb=L.createBuffer(),Hb=L.createBuffer(),t=new Float32Array([V=0,0,1,0,0,1,1,1]),L.bindBuffer(L.ARRAY_BUFFER,Hb),L.bufferData(L.ARRAY_BUFFER,t,L.STATIC_DRAW)}function Pb(){L.viewport(0,0,R.width=D.width,R.height=D.height),L.clear(L.COLOR_BUFFER_BIT),L.useProgram(Eb),L.activeTexture(L.TEXTURE0),K[0]&&L.bindTexture(L.TEXTURE_2D,Fb=K[0].ja);let r=xb=Jb=0;var t=(t,i,e,a)=>{t=L.getAttribLocation(Eb,t);var s=e&&44,h=e&&1,n=1==e;L.enableVertexAttribArray(t),L.vertexAttribPointer(t,a,i,n,s,r),L.vertexAttribDivisor(t,h),r+=a*e},i=(L.bindBuffer(L.ARRAY_BUFFER,Hb),t("g",L.FLOAT,0,2),L.bindBuffer(L.ARRAY_BUFFER,Gb),L.bufferData(L.ARRAY_BUFFER,44e4,L.DYNAMIC_DRAW),t("p",L.FLOAT,4,4),t("u",L.FLOAT,4,4),t("c",L.UNSIGNED_BYTE,1,4),t("a",L.UNSIGNED_BYTE,1,4),t("r",L.FLOAT,4,1),t=u(2*B).U(J),u(-1).u(A.multiply(t)));L.uniformMatrix4fv(L.getUniformLocation(Eb,"m"),!1,[t.x,0,0,0,0,t.y,0,0,1,1,1,1,i.x,i.y,0,0])}function Ra(t){t!=Fb&&(Qb(),L.bindTexture(L.TEXTURE_2D,Fb=t))}function Ob(t,i){return i=L.createShader(i),L.shaderSource(i,t),L.compileShader(i),i}function Qb(){var t;V&&(t=Jb?L.ONE:L.ONE_MINUS_SRC_ALPHA,L.blendFuncSeparate(L.SRC_ALPHA,t,L.ONE,t),L.enable(L.BLEND),L.bufferSubData(L.ARRAY_BUFFER,0,U),L.drawArraysInstanced(L.TRIANGLE_STRIP,0,4,V),V=0,Jb=xb)}function Rb(t=!1){var i=E;(V||t)&&(Qb(),t)&&i.drawImage(R,0,0)}function Sa(t,i,e,a,s,h,n,r,o,u,l=0){(1e4<=V||Jb!=xb)&&Qb();var c=11*V++;U[c++]=t,U[c++]=i,U[c++]=e,U[c++]=a,U[c++]=h,U[c++]=n,U[c++]=r,U[c++]=o,Ib[c++]=u,Ib[c++]=l,U[+c]=s}const wb=1/60;let C=[],Ga=[],Sb=0,ia=0,Tb=0,Ub=0,W=0;const Vb=[],Wb=[];function Xb(t){Vb.includes(void 0),Wb.includes(t),t&&Wb.push(t)}function Yb(){Ga=C.filter(t=>t.ca);for(const t of C)t.parent||(function t(i){if(!i.A){i.update();for(const e of i.children)t(e)}}(t),Da(t));C=C.filter(t=>!t.A)}function Zb(t){const u=I;var e=G.width=innerWidth,a=G.height=innerHeight,s=r(t,1,.8),n=r(t,0,.5),i=u.createRadialGradient(e/2,a/2,0,e/2,a/2,.7*Math.hypot(e,a));i.addColorStop(0,y(0,0,s/2*k(n),s).toString()),i.addColorStop(1,y(0,0,0,s).toString()),u.save(),u.fillStyle=i,u.fillRect(0,0,e,a),i=(t,i,e,a,s)=>{u.beginPath(),u.rect(t,i,e,s?a*l:a),(u.fillStyle=s)?u.fill():u.stroke()},n=(t,i,e,a=0,s=2*h,n,r)=>{var o=(a+s)/2;a=l*(s-a)/2,u.beginPath(),r&&u.lineTo(t,i),u.arc(t,i,e,o-a,o+a),(u.fillStyle=n)?u.fill():u.stroke()},s=(t=0,i=0)=>y([.98,.3,.57,.14][t%4]-10,.8,[0,.3,.5,.8,.9][i]).toString();const l=r(t=ha(t),.1,.5);for(u.translate(e/2,a/2),e=Math.min(6,Math.min(e,a)/99),u.scale(e,e),u.translate(-40,-35),u.lineJoin=u.lineCap="round",u.lineWidth=.1+1.9*l,u.setLineDash([99*r(t,.1,1),99]),i(7,16,18,-8,s(2,2)),i(7,8,18,4,s(2,3)),i(25,8,8,8,s(2,1)),i(25,8,-18,8),i(25,8,8,8),i(25,16,7,23,s()),i(11,39,14,-23,s(1,1)),i(11,16,14,18,s(1,2)),i(11,16,14,8,s(1,3)),i(25,16,-14,24),i(15,29,6,-9,s(2,2)),n(15,21,5,0,h/2,s(2,4),1),i(21,21,-6,9),i(37,14,9,6,s(3,2)),i(37,14,4.5,6,s(3,3)),i(37,14,9,6),i(50,20,10,-8,s(0,1)),i(50,20,6.5,-8,s(0,2)),i(50,20,3.5,-8,s(0,3)),i(50,20,10,-8),n(55,2,11.4,.5,h-.5,s(3,3)),n(55,2,11.4,.5,h/2,s(3,2),1),n(55,2,11.4,.5,h-.5),i(45,7,20,-7,s(0,2)),i(45,-1,20,4,s(0,3)),i(45,-1,20,8),e=5;e--;)n(60-6*e,30,9.9,0,2*h,s(e+2,3)),n(60-6*e,30,10,-.5,h+.5,s(e+2,2)),n(60-6*e,30,10.1,.5,h-.5,s(e+2,1));for(n(36,30,10,h/2,3*h/2),n(48,30,10,h/2,3*h/2),n(60,30,10),u.beginPath(),u.lineTo(36,20),u.lineTo(60,20),u.stroke(),n(60,30,4,h,3*h,s(3,2)),n(60,30,4,h,2*h,s(3,3)),n(60,30,4,h,3*h),e=6;e--;)u.beginPath(),u.lineTo(53,54),u.lineTo(53,40),u.lineTo(53+(1+2.9*e)*l,40),u.lineTo(53+(4+3.5*e)*l,54),u.fillStyle=s(0,e%2+2),u.fill(),e%2&&u.stroke();for(i(6,40,5,5),i(6,40,5,5,s()),i(15,54,38,-14,s()),e=3;e--;)for(a=2;a--;)n(15*e+15,47,a?7:1,h,3*h,s(e,3)),u.stroke(),n(15*e+15,47,a?7:1,0,h,s(e,2)),u.stroke();for(u.beginPath(),u.lineTo(6,40),u.lineTo(68,40),u.stroke(),u.beginPath(),u.lineTo(77,54),u.lineTo(4,54),u.stroke(),u.font="900 16px arial",u.textAlign="center",u.textBaseline="top",u.lineWidth=.1+3.9*l,e=n=0;e<8;++e)n+=u.measureText("LittleJS"[e]).width;for(e=2;e--;)for(let t=0,i=41-n/2;t<8;++t)u.fillStyle=s(t,2),a=u.measureText("LittleJS"[t]).width,u[e?"strokeText":"fillText"]("LittleJS"[t],i+a/2,55.5,17*l),i+=a;u.restore()}va=!0,Aa=.5;const $b=new hb,ac=new Db;Ab="Hello World",Cb(t=>t.aa=!!localStorage[Ab+"_"+t.id]),Xb(function(){var t,i;zb.length&&(t=zb[0],i=Tb-Bb,Bb?5<i?(Bb=0,zb.shift()):t.C(i<.5?1-i/.5:4.5<i?(i-4.5)/.5:0):Bb=Tb)});let Z;!function(i,a,s,h,n,t,e=document.body){function r(t=0){var i=t-Ub;for(Ub=t,Tb+=i/1e3,W+=i,W=Math.min(W,50),o(),t=0,W<0&&-9<W&&(t=W,W=0);0<=W;W-=1e3/60)ia=Sb++/60,cb||document.hasFocus()||(O=[[]]),Wa=Ma(),fb(),a(),Vb.forEach(t=>t()),Yb(),s(),$a();W+=t,J=u(D.width,D.height),I.imageSmoothingEnabled=E.imageSmoothingEnabled=!1,Pb(),h(),C.sort((t,i)=>t.P-i.P);for(const e of C)e.A||e.C();n(),Wb.forEach(t=>t()),Rb(),requestAnimationFrame(r)}function o(){var t,i;ua.x?(D.width=ua.x,D.height=ua.y,t=innerWidth/innerHeight,i=D.width/D.height,(R||D).style.width=D.style.width=G.style.width=t<i?"100%":"",(R||D).style.height=D.style.height=G.style.height=t<i?"":"100%"):(D.width=Math.min(innerWidth,ta.x),D.height=Math.min(innerHeight,ta.y)),G.width=D.width,G.height=D.height,J=u(D.width,D.height)}i||=()=>{},a||=()=>{},s||=()=>{},h||=()=>{},n||=()=>{},e.style.cssText="margin:0;overflow:hidden;width:100vw;height:100vh;display:flex;align-items:center;justify-content:center;background:#000;image-rendering:pixelated;user-select:none;-webkit-user-select:none;touch-action:none;-webkit-touch-callout:none",e.appendChild(D=document.createElement("canvas")),E=D.getContext("2d"),ab(),(gb=P.createGain()).connect(P.destination),gb.gain.value=.3,Kb(),e.appendChild(G=document.createElement("canvas")),I=G.getContext("2d"),D.style.cssText=G.style.cssText="position:absolute",R&&(R.style.cssText="position:absolute"),o(),e=t.map((e,a)=>new Promise(t=>{const i=new Image;i.crossOrigin="anonymous",i.onerror=i.onload=()=>{K[a]=new La(i),t()},i.src=e})),t.length||e.push(new Promise(t=>{K[0]=new La(new Image),t()})),va&&e.push(new Promise(i=>{let e=0;console.log("LittleJS Engine v1.11.10"),function t(){O=[[]],Zb(e+=.01),1<e?i():setTimeout(t,16)}()})),Promise.all(e).then(function(){new Promise(t=>t(i())).then(r)})}(function(){Q=u(32,16);for(var t=(pb=[]).length=Math.abs(Q.x*Q.y);t--;)pb[t]=0;var i,e,a,s=u(),t=new sb(s,Q),n=K[0].image,r=(E.drawImage(n,0,0),E.getImageData(0,0,n.width,n.height).data);for(s.x=Q.x;s.x--;)for(s.y=Q.y;s.y--;)r[4*(s.x+n.width*(15+Q.y-s.y))]&&(i=Math.floor(v(4,0)),e=!Math.floor(v(2,0)),a=oa(),t.setData(s,new qb(1,i,e,a)),ra(s,Q))&&(pb[(0|s.y)*Q.x+s.x|0]=1);for(t.Ca=[D,E,J,A,B],D=t.canvas,E=t.context,J=t.size.multiply(t.l.size),A=t.size.scale(.5),B=t.l.size.x,D.width=J.x,D.height=J.y,t.context.imageSmoothingEnabled=!1,Pb(),s=t.size.x;s--;)for(n=t.size.y;n--;)rb(t,u(s,n),!1);Rb(!0),[D,E,J,A,B]=t.Ca,A=u(16,8),B=32,Ba=-.01,(Z=new vb(u(16,9),0,0,0,500,h,Ja(0,16),y(1,1,1),y(0,0,0),y(0,0,0,0),y(0,0,0,0),2,.2,.2,.1,.05,.99,1,1,h,.05,.5,!0,!0)).s=.3,Z.H=2},function(){O[0]&&2&O[0][0]&&($b.play(Wa),Z.S=y(),Z.T=oa(),Z.da=Z.S.scale(1,0),Z.ea=Z.T.scale(1,0),ac.unlock()),Xa&&(B=k(B-=Math.sign(Xa)*B/5,10,300)),Pa.x&&(Z.i=Wa)},function(){},function(){Ia(u(16,8),u(20,14),void 0,y(0,0,.6),0,!1,void 0,!1),Ia(u(21,5),u(4.5),Ja(3,128))},function(){Ua("LittleJS Demo",u(J.x/2,70),80,y(0,0,1),6,y(0,0,0))},["tiles.png"]);
|
|
2
|
+
</script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const h=Math.PI;function aa(t,i=1){return(t%i+i)%i}function k(t,i=0,e=1){return t<i?i:e<t?e:t}function r(t,i,e){return(e-=i)?k((t-i)/e):0}function ba(t,i,e,a=u()){return 2*Math.abs(t.x-e.x)<i.x+a.x&&2*Math.abs(t.y-e.y)<i.y+a.y}function ha(t=ia){return.5*(1-Math.cos(2*t*h))}function v(t=1,i=0){return i+Math.random()*(t-i)}function ja(t=1){return ma(new w,v(2*h),t)}function na(t=1){return 0<t?ja(t*v(0/t,1)**.5):new w}function oa(t=new x,i=new x(0,0,0,1),e=!1){return e?t.la(i,v()):new x(v(t.r,i.r),v(t.j,i.j),v(t.b,i.b),v(t.a,i.a))}function u(t=0,i){return"number"==typeof t?new w(t,null==i?t:i):new w(t.x,t.y)}function ma(t,i=0,e=1){return t.x=e*Math.sin(i),t.y=e*Math.cos(i),t}function pa(t){return t.x**2+t.y**2}function qa(t){var i=t.length();return 1<i?t.scale(1/i):t}function ra(t,i){return 0<=t.x&&0<=t.y&&t.x<i.x&&t.y<i.y}class w{constructor(t=0,i=0){this.x=t,this.y=i}set(t=0,i=0){return this.x=t,this.y=i,this}v(){return new w(this.x,this.y)}add(t){return new w(this.x+t.x,this.y+t.y)}u(t){return new w(this.x-t.x,this.y-t.y)}multiply(t){return new w(this.x*t.x,this.y*t.y)}U(t){return new w(this.x/t.x,this.y/t.y)}scale(t){return new w(this.x*t,this.y*t)}length(){return pa(this)**.5}normalize(t=1){var i=this.length();return i?this.scale(t/i):new w(0,t)}angle(){return Math.atan2(this.x,this.y)}rotate(t){var i=Math.cos(-t);return t=Math.sin(-t),new w(this.x*i-this.y*t,this.x*t+this.y*i)}setDirection(t,i=1){return u((t=aa(t,4))%2?t-1?-i:i:0,t%2?0:t?-i:i)}direction(){return Math.abs(this.x)>Math.abs(this.y)?this.x<0?3:1:this.y<0?2:0}floor(){return new w(Math.floor(this.x),Math.floor(this.y))}la(t,i){return this.add(t.u(this).scale(k(i)))}toString(){}}function y(t=0,i=0,e=1,a=1){var s=new x,h=(t=aa(t,1),i=k(i),e=k(e),(t,i,e)=>6*(e=aa(e,1))<1?t+6*(i-t)*e:2*e<1?i:3*e<2?t+(i-t)*(4-6*e):t);return s.r=h(e=2*e-(i=e<.5?e*(1+i):e+i-e*i),i,t+1/3),s.j=h(e,i,t),s.b=h(e,i,t-1/3),s.a=a,s}function sa(t){return(255*k(t.r)|0)+(255*k(t.j)<<8)+(255*k(t.b)<<16)+(255*k(t.a)<<24)}class x{constructor(t=1,i=1,e=1,a=1){this.r=t,this.j=i,this.b=e,this.a=a}set(t=1,i=1,e=1,a=1){return this.r=t,this.j=i,this.b=e,this.a=a,this}v(){return new x(this.r,this.j,this.b,this.a)}add(t){return new x(this.r+t.r,this.j+t.j,this.b+t.b,this.a+t.a)}u(t){return new x(this.r-t.r,this.j-t.j,this.b-t.b,this.a-t.a)}multiply(t){return new x(this.r*t.r,this.j*t.j,this.b*t.b,this.a*t.a)}U(t){return new x(this.r/t.r,this.j/t.j,this.b/t.b,this.a/t.a)}scale(t,i=t){return new x(this.r*t,this.j*t,this.b*t,this.a*i)}la(t,i){return this.add(t.u(this).scale(k(i)))}toString(t=!0){var i=t=>((t=255*k(t)|0)<16?"0":"")+t.toString(16);return"#"+i(this.r)+i(this.j)+i(this.b)+(t?i(this.a):"")}}let A=u(),B=32,ta=u(1920,1080),ua=u(),va=!1,za=u(16),Aa=0,Ba=0,Ca=u(640,80);function Da(t){var i,e=t.parent;e&&(i=e.o?-1:1,t.i=t.ya.multiply(u(i,1)).rotate(e.angle).add(e.i),t.angle=i*t.xa+e.angle);for(const a of t.children)Da(a)}function Ea(t){if(!t.A){t.A=1,t.parent&&t.parent.removeChild(t);for(const i of t.children)Ea(i,i.parent=0)}}class Fa{constructor(t=u(),i=u(1),e,a=0,s=new x,h=0){this.i=t.v(),this.size=i,this.ua=void 0,this.l=e,this.angle=a,this.color=s,this.sa=void 0,this.o=!1,this.J=this.D=this.h=1,this.s=0,this.W=.8,this.N=1,this.P=h,this.g=u(),this.R=0,this.ra=ia,this.children=[],this.ba=!0,this.parent=this.m=void 0,this.ya=u(),this.xa=0,this.ka=this.ca=this.K=!1,C.push(this)}update(){var t;if(!this.parent&&(this.ba?(this.g.x=k(this.g.x,-1,1),this.g.y=k(this.g.y,-1,1)):1<(t=pa(this.g))&&(this.g.x*=t=1/t**.5,this.g.y*=t),t=this.i.v(),this.g.x*=this.D,this.g.y*=this.D,this.h&&(this.g.y+=Ba*this.N),this.i.x+=this.g.x,this.i.y+=this.g.y,this.angle+=this.R*=this.J,this.h)){var i,e,a,s,h,n,r=this.g.y<0;if(this.m&&(i=this.m.g?this.m.g.x:0,this.g.x=i+(this.g.x-i)*this.W,this.m=void 0),this.ca)for(var o of Ga)!this.ka&&!o.ka||o.A||o.parent||o==this||ba(this.i,this.size,o.i,o.size)&&(ba(t,this.size,o.i,o.size)?(i=(e=(i=t.u(o.i)).length())<.01?ja(.001):i.scale(.001/e),this.g=this.g.add(i),o.h&&(o.g=o.g.u(i))):(e=this.size.add(o.size),a=2*(t.y-o.i.y)>e.y+Ba,s=2*Math.abs(t.y-o.i.y)<e.y,h=2*Math.abs(t.x-o.i.x)<e.x,i=Math.max(this.s,o.s),!a&&!h&&s||(this.i.y=o.i.y+(e.y/2+.001)*Math.sign(t.y-o.i.y),o.m&&r||!o.h?(r&&(this.m=o),this.g.y*=-i):o.h&&(h=(this.h*this.g.y+o.h*o.g.y)/(this.h+o.h),n=o.g.y*(o.h-this.h)/(this.h+o.h)+2*this.g.y*this.h/(this.h+o.h),this.g.y=h+k(i)*(this.g.y*(this.h-o.h)/(this.h+o.h)+2*o.g.y*o.h/(this.h+o.h)-h),o.g.y=h+k(i)*(n-h))),!a&&s&&(this.i.x=o.i.x+(e.x/2+.001)*Math.sign(t.x-o.i.x),o.h?(e=(this.h*this.g.x+o.h*o.g.x)/(this.h+o.h),a=o.g.x*(o.h-this.h)/(this.h+o.h)+2*this.g.x*this.h/(this.h+o.h),this.g.x=e+k(i)*(this.g.x*(this.h-o.h)/(this.h+o.h)+2*o.g.x*o.h/(this.h+o.h)-e),o.g.x=e+k(i)*(a-e)):this.g.x*=-i)));this.K&&Ha(this.i,this.size,this)&&!Ha(t,this.size,this)&&(o=Ha(u(this.i.x,t.y),this.size,this),!Ha(u(t.x,this.i.y),this.size,this)&&o||(this.g.y*=-this.s,r?(this.i.y=(t.y-this.size.y/2|0)+this.size.y/2+1e-4,this.m=this):(this.i.y=t.y,this.m=void 0)),o)&&(this.i.x=t.x,this.g.x*=-this.s)}}C(){Ia(this.i,this.ua||this.size,this.l,this.color,this.angle,this.o,this.sa)}removeChild(t){t.parent==this&&this.children.includes(t),this.children.splice(this.children.indexOf(t),1),t.parent=0}toString(){}}let D,E,G,I,J=u(),K=[];function Ja(t=u(),i=za,e=0,a=0){"number"==typeof i&&(i=u(i));var s=K[e],h=i.add(u(2*a));return"number"==typeof t&&(t=0<(s=s.size.x/h.x|0)?u(t%s,t/s|0):u()),t=u(t.x*h.x+a,t.y*h.y+a),new Ka(t,i,e,a)}class Ka{constructor(t=u(),i=za,e=0,a=0){this.i=t.v(),this.size=i.v(),this.Z=e,this.padding=a}offset(t){return new Ka(this.i.add(t),this.size,this.Z)}frame(t){return this.offset(u(t*(this.size.x+2*this.padding),0))}}class La{constructor(t){this.image=t,this.size=u(t.width,t.height);var i=L.createTexture();L.bindTexture(L.TEXTURE_2D,i),t&&t.width?L.texImage2D(L.TEXTURE_2D,0,L.RGBA,L.RGBA,L.UNSIGNED_BYTE,t):(t=new Uint8Array([255,255,255,255]),L.texImage2D(L.TEXTURE_2D,0,L.RGBA,1,1,0,L.RGBA,L.UNSIGNED_BYTE,t)),t=L.NEAREST,L.texParameteri(L.TEXTURE_2D,L.TEXTURE_MIN_FILTER,t),L.texParameteri(L.TEXTURE_2D,L.TEXTURE_MAG_FILTER,t),this.ja=i}}function Ma(){var t=Pa;return new w((t.x-J.x/2+.5)/B+A.x,(t.y-J.y/2+.5)/-B+A.y)}function Qa(t){return new w((t.x-A.x)*B+J.x/2-.5,(t.y-A.y)*-B+J.y/2-.5)}function Ia(t,i=u(1),h,n=new x,e=0,a,s=new x(0,0,0,0),r=!0){const o=h&&K[h.Z];var l,c,b,d;r?o?(d=u(1).U(o.size),r=h.i.x*d.x,l=h.i.y*d.y,c=h.size.x*d.x,b=h.size.y*d.y,d=d.scale(Aa),Ra(o.ja),Sa(t.x,t.y,a?-i.x:i.x,i.y,e,r+d.x,l+d.y,r-d.x+c,l-d.y+b,sa(n),sa(s))):Sa(t.x,t.y,i.x,i.y,e,0,0,0,0,0,sa(n)):Ta(t,i=u(i.x,-i.y),e,a,t=>{var i,e,a,s;o?(i=h.i.x+Aa,e=h.i.y+Aa,a=h.size.x-2*Aa,s=h.size.y-2*Aa,t.globalAlpha=n.a,t.drawImage(o.image,i,e,a,s,-.5,-.5,1,1),t.globalAlpha=1):(t.fillStyle=n.toString(),t.fillRect(-.5,-.5,1,1))})}function Ta(t,i,e,a,s){var h=E;t=Qa(t),i=i.scale(B),h.save(),h.translate(t.x+.5,t.y+.5),h.rotate(e),h.scale(a?-i.x:i.x,-i.y),s(h),h.restore()}function Ua(t,i,e=1,a=new x,s=0,h=new x(0,0,0),n="center"){var r=I;r.fillStyle=a.toString(),r.lineWidth=s,r.strokeStyle=h.toString(),r.textAlign=n,r.font=e+"px arial",r.textBaseline="middle",r.lineJoin="round",i=i.v(),t=(t+"").split("\n"),i.y-=(t.length-1)*e/2,t.forEach(t=>{s&&r.strokeText(t,i.x,i.y,void 0),r.fillText(t,i.x,i.y,void 0),i.y+=e})}function Va(t,i=0){return O[i]&&!!(1&O[i][t])}let Wa=u(),Pa=u(),Xa=0,Ya=!1;function Za(t,i=0){return Va(t,i+1)}let O=[[]];function $a(){for(const t of O)for(const i in t)t[i]&=1;Xa=0}function ab(){function i(t){return"KeyW"==t?"ArrowUp":"KeyS"==t?"ArrowDown":"KeyA"==t?"ArrowLeft":"KeyD"==t?"ArrowRight":t}onkeydown=t=>{t.repeat||(Ya=!1,O[0][t.code]=3,O[0][i(t.code)]=3)},onkeyup=t=>{O[0][t.code]=4,O[0][i(t.code)]=4},onmousedown=t=>{P&&"running"!=P.state&&P.resume(),Ya=!1,O[0][t.button]=3,Pa=bb(t),t.button&&t.preventDefault()},onmouseup=t=>O[0][t.button]=2&O[0][t.button]|4,onmousemove=t=>Pa=bb(t),onwheel=t=>Xa=t.ctrlKey?0:Math.sign(t.deltaY),oncontextmenu=()=>!1,onblur=()=>{O=[[]]},cb&&db()}function bb(t){var i=D.getBoundingClientRect();return u(r(t.x,i.left,i.right)*D.width,r(t.y,i.top,i.bottom)*D.height)}const eb=[];function fb(){var i,e;if(navigator&&navigator.getGamepads&&document.hasFocus()){var a=navigator.getGamepads();for(let t=a.length;t--;){var s=a[t],h=O[t+1]||(O[t+1]=[]),n=eb[t]||(eb[t]=[]);if(s){for(var o=0;o<s.axes.length-1;o+=2)n[o>>1]=(i=u(s.axes[o],s.axes[o+1]),void 0,qa(u((e=t=>.3<t?r(t,.3,.8):t<-.3?-r(-t,.3,.8):0)(i.x),e(-i.y))));for(o=s.buttons.length;o--;){var l=s.buttons[o],c=Za(o,t);h[o]=l.pressed?c?1:3:c?4:0,Ya||=!t&&l.pressed}pa(s=u((Za(15,t)&&1)-(Za(14,t)&&1),(Za(12,t)&&1)-(Za(13,t)&&1)))&&(n[0]=qa(s))}}}}const cb=void 0!==window.ontouchstart;function db(){function i(t){P&&"running"!=P.state&&P.resume();var i=t.touches.length;return i?(Pa=bb(u(t.touches[0].clientX,t.touches[0].clientY)),e?Ya=!1:O[0][0]=3):e&&(O[0][0]=2&O[0][0]|4),e=i,document.hasFocus()&&t.preventDefault(),!0}document.addEventListener("touchstart",t=>i(t),{passive:!1}),document.addEventListener("touchmove",t=>i(t),{passive:!1}),document.addEventListener("touchend",t=>i(t),{passive:!1}),onmousedown=onmouseup=()=>0;let e}let P=new AudioContext,gb;class hb{constructor(){var t=[1,.5];this.Ba=40,this.Fa=.7,this.O=0,t&&(this.O=null!=t[1]?t[1]:.05,t[1]=0,this.qa=[ib(...t)],this.sampleRate=44100)}play(t,i=1,e=1,a=1,s=!1){if(this.qa){var h;if(t){if(h=this.Ba){var n=A;if(h*h<(n=(A.x-t.x)**2+(n.y-t.y)**2))return;i*=r(n**.5,h,h*this.Fa)}h=2*Qa(t).x/D.width-1}return t=e+e*this.O*a*v(-1,1),this.va=P.createGain(),this.source=jb(this.qa,i,t,h,s,this.sampleRate,this.va)}}stop(){this.source&&this.source.stop(),this.source=void 0}}function jb(t,i=1,e=1,a=0,s=!1,h=44100,n){const r=P.createBuffer(t.length,t[0].length,h),o=P.createBufferSource();return t.forEach((t,i)=>r.getChannelData(i).set(t)),o.buffer=r,o.playbackRate.value=e,o.loop=s,(n=n||P.createGain()).gain.value=i,n.connect(gb),t=new StereoPannerNode(P,{pan:k(a,-1,1)}),o.connect(t).connect(n),"running"!=P.state?P.resume().then(()=>o.start()):o.start(),o}function ib(t=1,i=.05,e=220,a=0,s=0,n=.1,r=0,o=1,u=0,l=0,c=0,b=0,x=0,d=0,y=0,g=0,f=0,m=1,w=0,p=0,L=0){var A=2*h,G=u*=500*A/44100/44100;i=e*=v(1+i,1-i)*A/44100;let E=[],D=0,J=0,R=0,T=1,W=0,_=0,M=0;var S=A*Math.abs(L)*2/44100,B=Math.cos(S),P=1+(z=Math.sin(S)/2/2),S=-2*B/P,z=(1-z)/P;let U=(1+Math.sign(L)*B)/2/P,j=-(Math.sign(L)+B)/P,I=0,C=0,F=0,O=0;for(l*=500*A/44100**3,y*=A/44100,c*=A/44100,b*=44100,x=44100*x|0,P=(a=44100*a+9)+(w*=44100)+(s*=44100)+(n*=44100)+(f*=44100)|0;R<P;E[R++]=M*t)++_%(100*g|0)||(M=r?1<r?2<r?3<r?Math.sin(D**3):k(Math.tan(D),1,-1):1-(2*D/A%2+2)%2:1-4*Math.abs(Math.round(D/A)-D/A):Math.sin(D),M=(x?1-p+p*Math.sin(A*R/x):1)*Math.sign(M)*Math.abs(M)**o*(R<a?R/a:R<a+w?1-(R-a)/w*(1-m):R<a+w+s?m:R<P-f?(P-R-f)/n*m:0),M=f?M/2+(f>R?0:(R<P-f?1:(P-R)/f)*E[R-f|0]/2/t):M,L&&(M=O=U*I+j*(I=C)+U*(C=M)-z*F-S*(F=O))),B=(e+=u+=l)*Math.cos(y*J++),D+=B+B*d*Math.sin(R**5),T&&++T>b&&(e+=c,i+=c,T=0),!x||++W%x||(e=i,u=G,T=T||1);return E}let pb=[],Q=u();function Ha(t,i=u(),e){var a=Math.max(t.x-i.x/2|0,0),s=Math.max(t.y-i.y/2|0,0),h=Math.min(t.x+i.x/2,Q.x);for(t=Math.min(t.y+i.y/2,Q.y);s<t;++s)for(i=a;i<h;++i){var n=pb[s*Q.x+i];if(n&&(!e||0<n))return!0}return!1}class qb{constructor(t,i=0,e=!1,a=new x){this.$=t,this.direction=i,this.o=e,this.color=a}clear(){this.$=this.direction=0,this.o=!1,this.color=new x}}function rb(t,i,e=!0){var a=t.l.size;e&&(e=i.multiply(a),t.context.clearRect(e.x,t.canvas.height-e.y,a.x,-a.y)),null!=(e=t.getData(i)).$&&(i=i.add(u(.5)),t=Ja(e.$,a,t.l.Z,t.l.padding),Ia(i,u(1),t,e.color,e.direction*h/2,e.o))}class sb extends Fa{constructor(t,i=Q){var e=Ja(),a=u(1);for(super(t,i,e,0,void 0,0),this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.scale=a,this.wa=!1,this.data=[],t=this.size,t=Math.abs(t.x*t.y);t--;)this.data.push(new qb)}setData(t,i,e=!1){ra(t,this.size)&&(this.data[(0|t.y)*this.size.x+t.x|0]=i,e)&&rb(this,t)}getData(t){return ra(t,this.size)&&this.data[(0|t.y)*this.size.x+t.x|0]}update(){}C(){let t=Qa(this.i.add(u(0,this.size.y*this.scale.y)));t=t.floor(),(this.wa?I:E).drawImage(this.canvas,t.x,t.y,B*this.size.x*this.scale.x,B*this.size.y*this.scale.y)}}function tb(t){var i="number"==typeof t.V?na(t.V/2):u(v(-.5,.5),v(-.5,.5)).multiply(t.V).rotate(t.angle);let e=v(t.na,-t.na);t.X||(i=t.i.add(i),e+=t.angle);const a=t.O;var s=(o=t=>t+t*v(a,-a))(t.Aa),h=o(t.Y),n=o(t.Da),r=o(t.speed),o=o(t.ta)*(2*Math.floor(v(2,0))-1),l=v(t.ga,-t.ga),c=oa(t.S,t.T,t.pa),b=oa(t.da,t.ea,t.pa),l=t.X?l:t.angle+l;(i=new ub(i,t.l,e,c,b,s,h,n,t.G,t.I,t.H,t.X&&t,t.za)).g=ma(u(),l,r),i.R=o,i.G=t.G,i.D=t.D,i.J=t.J,i.s=t.s,i.W=t.W,i.N=t.N,i.K=t.K,i.P=t.P,i.o=!!Math.floor(v(2,0)),t.oa&&t.oa(i)}class vb extends Fa{constructor(t,i,e=0,a=0,s=100,n=h,r,o=new x,l=new x,c=new x(1,1,1,0),b=new x(1,1,1,0),d=.5,y=.1,g=1,f=.1,v=.05,m=1,w=1,p=0,L=h,A=.1,E=.2,D=!1,R=!1,T=!0,M=R?1e9:0,S=!1){super(t,u(),r,i,void 0,M),this.V=e,this.ia=a,this.ha=s,this.ga=n,this.S=o,this.T=l,this.da=c,this.ea=b,this.pa=T,this.Aa=d,this.Y=y,this.Da=g,this.speed=f,this.ta=v,this.D=m,this.J=w,this.N=p,this.na=L,this.G=A,this.O=E,this.K=D,this.I=R,this.X=S,this.H=0,this.oa=this.za=void 0,this.F=0}update(){if(this.parent&&super.update(),!this.ia||ia-this.ra<=this.ia){if(+this.ha){var t=1/this.ha;for(this.F+=wb;0<this.F;this.F-=t)tb(this)}}else Ea(this)}C(){}}class ub extends Fa{constructor(t,i,e,a,s,h,n,r,o,l,c,b,x){super(t,u(),i,e),this.M=a,this.L=s.u(a),this.ma=h,this.Y=n,this.Ea=r-n,this.G=o,this.I=l,this.H=c,this.B=b,this.fa=x,this.ba=!1}C(){var t=0<this.ma?Math.min((ia-this.ra)/this.ma,1):1,i=u(this.Y+t*this.Ea),e=this.G/2,e=new x(this.M.r+t*this.L.r,this.M.j+t*this.L.j,this.M.b+t*this.L.b,(this.M.a+t*this.L.a)*(t<e?t/e:1-e<t?(1-t)/e:1));this.I&&(xb=!0);let a=this.i;var s,h,n=this.angle;this.B&&(a=this.B.i.add(a.rotate(-this.B.angle)),n+=this.B.angle),this.H?(s=this.g,(n=(s=this.B?s.rotate(-this.B.angle):s).length())&&(s=s.scale(1/n),h=n*this.H,i.y=Math.max(i.x,h),n=s.angle(),Ia(a.add(s.multiply(u(0,-h/2))),i,this.l,e,n,this.o))):Ia(a,i,this.l,e,n,this.o),this.I&&(xb=void 0),1==t&&(this.color=e,this.size=i,this.fa&&this.fa(this),this.A=1)}}const yb={};let zb=[],Ab,Bb;function Cb(i){Object.values(yb).forEach(t=>i(t))}class Db{constructor(){this.id=0,this.name="Example Medal",this.description="Welcome to LittleJS!",this.icon="🏆",this.aa=!1,yb[0]=this}unlock(){this.aa||(localStorage[Ab+"_"+this.id]=this.aa=!0,zb.push(this))}C(t=0){var i=I,e=Math.min(Ca.x,D.width),a=G.width-e;t*=-Ca.y,i.save(),i.beginPath(),i.fillStyle=new x(.9,.9,.9).toString(),i.strokeStyle=new x(0,0,0).toString(),i.lineWidth=3,i.rect(a,t,e,Ca.y),i.fill(),i.stroke(),i.clip(),e=u(a+15+25,t+Ca.y/2),this.image?I.drawImage(this.image,e.x-25,e.y-25,50,50):Ua(this.icon,e,35,new x(0,0,0)),a=u(a+50+30,t+28),Ua(this.name,a,38,new x(0,0,0),0,void 0,"left"),a.y+=32,Ua(this.description,a,24,new x(0,0,0),0,void 0,"left"),i.restore()}}let R,L,Eb,Fb,Gb,Hb,U,Ib,V,xb,Jb;function Kb(){R=document.createElement("canvas"),L=R.getContext("webgl2",{antialias:!0}),D.parentElement.appendChild(R);var t=L.createProgram();L.attachShader(t,Ob("#version 300 es\nprecision highp float;uniform mat4 m;in vec2 g;in vec4 p,u,c,a;in float r;out vec2 v;out vec4 d,e;void main(){vec2 s=(g-.5)*p.zw;gl_Position=m*vec4(p.xy+s*cos(r)-vec2(-s.y,s)*sin(r),1,1);v=mix(u.xw,u.zy,g);d=c;e=a;}",L.VERTEX_SHADER)),L.attachShader(t,Ob("#version 300 es\nprecision highp float;uniform sampler2D s;in vec2 v;in vec4 d,e;out vec4 c;void main(){c=texture(s,v)*d+e;}",L.FRAGMENT_SHADER)),L.linkProgram(t),Eb=t,t=new ArrayBuffer(44e4),U=new Float32Array(t),Ib=new Uint32Array(t),Gb=L.createBuffer(),Hb=L.createBuffer(),t=new Float32Array([V=0,0,1,0,0,1,1,1]),L.bindBuffer(L.ARRAY_BUFFER,Hb),L.bufferData(L.ARRAY_BUFFER,t,L.STATIC_DRAW)}function Pb(){L.viewport(0,0,R.width=D.width,R.height=D.height),L.clear(L.COLOR_BUFFER_BIT),L.useProgram(Eb),L.activeTexture(L.TEXTURE0),K[0]&&L.bindTexture(L.TEXTURE_2D,Fb=K[0].ja);let r=xb=Jb=0;var t=(t,i,e,a)=>{t=L.getAttribLocation(Eb,t);var s=e&&44,h=e&&1,n=1==e;L.enableVertexAttribArray(t),L.vertexAttribPointer(t,a,i,n,s,r),L.vertexAttribDivisor(t,h),r+=a*e},i=(L.bindBuffer(L.ARRAY_BUFFER,Hb),t("g",L.FLOAT,0,2),L.bindBuffer(L.ARRAY_BUFFER,Gb),L.bufferData(L.ARRAY_BUFFER,44e4,L.DYNAMIC_DRAW),t("p",L.FLOAT,4,4),t("u",L.FLOAT,4,4),t("c",L.UNSIGNED_BYTE,1,4),t("a",L.UNSIGNED_BYTE,1,4),t("r",L.FLOAT,4,1),t=u(2*B).U(J),u(-1).u(A.multiply(t)));L.uniformMatrix4fv(L.getUniformLocation(Eb,"m"),!1,[t.x,0,0,0,0,t.y,0,0,1,1,1,1,i.x,i.y,0,0])}function Ra(t){t!=Fb&&(Qb(),L.bindTexture(L.TEXTURE_2D,Fb=t))}function Ob(t,i){return i=L.createShader(i),L.shaderSource(i,t),L.compileShader(i),i}function Qb(){var t;V&&(t=Jb?L.ONE:L.ONE_MINUS_SRC_ALPHA,L.blendFuncSeparate(L.SRC_ALPHA,t,L.ONE,t),L.enable(L.BLEND),L.bufferSubData(L.ARRAY_BUFFER,0,U),L.drawArraysInstanced(L.TRIANGLE_STRIP,0,4,V),V=0,Jb=xb)}function Rb(t=!1){var i=E;(V||t)&&(Qb(),t)&&i.drawImage(R,0,0)}function Sa(t,i,e,a,s,h,n,r,o,u,l=0){(1e4<=V||Jb!=xb)&&Qb();var c=11*V++;U[c++]=t,U[c++]=i,U[c++]=e,U[c++]=a,U[c++]=h,U[c++]=n,U[c++]=r,U[c++]=o,Ib[c++]=u,Ib[c++]=l,U[+c]=s}const wb=1/60;let C=[],Ga=[],Sb=0,ia=0,Tb=0,Ub=0,W=0;const Vb=[],Wb=[];function Xb(t){Vb.includes(void 0),Wb.includes(t),t&&Wb.push(t)}function Yb(){Ga=C.filter(t=>t.ca);for(const t of C)t.parent||(function t(i){if(!i.A){i.update();for(const e of i.children)t(e)}}(t),Da(t));C=C.filter(t=>!t.A)}function Zb(t){const u=I;var e=G.width=innerWidth,a=G.height=innerHeight,s=r(t,1,.8),n=r(t,0,.5),i=u.createRadialGradient(e/2,a/2,0,e/2,a/2,.7*Math.hypot(e,a));i.addColorStop(0,y(0,0,s/2*k(n),s).toString()),i.addColorStop(1,y(0,0,0,s).toString()),u.save(),u.fillStyle=i,u.fillRect(0,0,e,a),i=(t,i,e,a,s)=>{u.beginPath(),u.rect(t,i,e,s?a*l:a),(u.fillStyle=s)?u.fill():u.stroke()},n=(t,i,e,a=0,s=2*h,n,r)=>{var o=(a+s)/2;a=l*(s-a)/2,u.beginPath(),r&&u.lineTo(t,i),u.arc(t,i,e,o-a,o+a),(u.fillStyle=n)?u.fill():u.stroke()},s=(t=0,i=0)=>y([.98,.3,.57,.14][t%4]-10,.8,[0,.3,.5,.8,.9][i]).toString();const l=r(t=ha(t),.1,.5);for(u.translate(e/2,a/2),e=Math.min(6,Math.min(e,a)/99),u.scale(e,e),u.translate(-40,-35),u.lineJoin=u.lineCap="round",u.lineWidth=.1+1.9*l,u.setLineDash([99*r(t,.1,1),99]),i(7,16,18,-8,s(2,2)),i(7,8,18,4,s(2,3)),i(25,8,8,8,s(2,1)),i(25,8,-18,8),i(25,8,8,8),i(25,16,7,23,s()),i(11,39,14,-23,s(1,1)),i(11,16,14,18,s(1,2)),i(11,16,14,8,s(1,3)),i(25,16,-14,24),i(15,29,6,-9,s(2,2)),n(15,21,5,0,h/2,s(2,4),1),i(21,21,-6,9),i(37,14,9,6,s(3,2)),i(37,14,4.5,6,s(3,3)),i(37,14,9,6),i(50,20,10,-8,s(0,1)),i(50,20,6.5,-8,s(0,2)),i(50,20,3.5,-8,s(0,3)),i(50,20,10,-8),n(55,2,11.4,.5,h-.5,s(3,3)),n(55,2,11.4,.5,h/2,s(3,2),1),n(55,2,11.4,.5,h-.5),i(45,7,20,-7,s(0,2)),i(45,-1,20,4,s(0,3)),i(45,-1,20,8),e=5;e--;)n(60-6*e,30,9.9,0,2*h,s(e+2,3)),n(60-6*e,30,10,-.5,h+.5,s(e+2,2)),n(60-6*e,30,10.1,.5,h-.5,s(e+2,1));for(n(36,30,10,h/2,3*h/2),n(48,30,10,h/2,3*h/2),n(60,30,10),u.beginPath(),u.lineTo(36,20),u.lineTo(60,20),u.stroke(),n(60,30,4,h,3*h,s(3,2)),n(60,30,4,h,2*h,s(3,3)),n(60,30,4,h,3*h),e=6;e--;)u.beginPath(),u.lineTo(53,54),u.lineTo(53,40),u.lineTo(53+(1+2.9*e)*l,40),u.lineTo(53+(4+3.5*e)*l,54),u.fillStyle=s(0,e%2+2),u.fill(),e%2&&u.stroke();for(i(6,40,5,5),i(6,40,5,5,s()),i(15,54,38,-14,s()),e=3;e--;)for(a=2;a--;)n(15*e+15,47,a?7:1,h,3*h,s(e,3)),u.stroke(),n(15*e+15,47,a?7:1,0,h,s(e,2)),u.stroke();for(u.beginPath(),u.lineTo(6,40),u.lineTo(68,40),u.stroke(),u.beginPath(),u.lineTo(77,54),u.lineTo(4,54),u.stroke(),u.font="900 16px arial",u.textAlign="center",u.textBaseline="top",u.lineWidth=.1+3.9*l,e=n=0;e<8;++e)n+=u.measureText("LittleJS"[e]).width;for(e=2;e--;)for(let t=0,i=41-n/2;t<8;++t)u.fillStyle=s(t,2),a=u.measureText("LittleJS"[t]).width,u[e?"strokeText":"fillText"]("LittleJS"[t],i+a/2,55.5,17*l),i+=a;u.restore()}va=!0,Aa=.5;const $b=new hb,ac=new Db;Ab="Hello World",Cb(t=>t.aa=!!localStorage[Ab+"_"+t.id]),Xb(function(){var t,i;zb.length&&(t=zb[0],i=Tb-Bb,Bb?5<i?(Bb=0,zb.shift()):t.C(i<.5?1-i/.5:4.5<i?(i-4.5)/.5:0):Bb=Tb)});let Z;!function(i,a,s,h,n,t,e=document.body){function r(t=0){var i=t-Ub;for(Ub=t,Tb+=i/1e3,W+=i,W=Math.min(W,50),o(),t=0,W<0&&-9<W&&(t=W,W=0);0<=W;W-=1e3/60)ia=Sb++/60,cb||document.hasFocus()||(O=[[]]),Wa=Ma(),fb(),a(),Vb.forEach(t=>t()),Yb(),s(),$a();W+=t,J=u(D.width,D.height),I.imageSmoothingEnabled=E.imageSmoothingEnabled=!1,Pb(),h(),C.sort((t,i)=>t.P-i.P);for(const e of C)e.A||e.C();n(),Wb.forEach(t=>t()),Rb(),requestAnimationFrame(r)}function o(){var t,i;ua.x?(D.width=ua.x,D.height=ua.y,t=innerWidth/innerHeight,i=D.width/D.height,(R||D).style.width=D.style.width=G.style.width=t<i?"100%":"",(R||D).style.height=D.style.height=G.style.height=t<i?"":"100%"):(D.width=Math.min(innerWidth,ta.x),D.height=Math.min(innerHeight,ta.y)),G.width=D.width,G.height=D.height,J=u(D.width,D.height)}i||=()=>{},a||=()=>{},s||=()=>{},h||=()=>{},n||=()=>{},e.style.cssText="margin:0;overflow:hidden;width:100vw;height:100vh;display:flex;align-items:center;justify-content:center;background:#000;image-rendering:pixelated;user-select:none;-webkit-user-select:none;touch-action:none;-webkit-touch-callout:none",e.appendChild(D=document.createElement("canvas")),E=D.getContext("2d"),ab(),(gb=P.createGain()).connect(P.destination),gb.gain.value=.3,Kb(),e.appendChild(G=document.createElement("canvas")),I=G.getContext("2d"),D.style.cssText=G.style.cssText="position:absolute",R&&(R.style.cssText="position:absolute"),o(),e=t.map((e,a)=>new Promise(t=>{const i=new Image;i.crossOrigin="anonymous",i.onerror=i.onload=()=>{K[a]=new La(i),t()},i.src=e})),t.length||e.push(new Promise(t=>{K[0]=new La(new Image),t()})),va&&e.push(new Promise(i=>{let e=0;console.log("LittleJS Engine v1.11.10"),function t(){O=[[]],Zb(e+=.01),1<e?i():setTimeout(t,16)}()})),Promise.all(e).then(function(){new Promise(t=>t(i())).then(r)})}(function(){Q=u(32,16);for(var t=(pb=[]).length=Math.abs(Q.x*Q.y);t--;)pb[t]=0;var i,e,a,s=u(),t=new sb(s,Q),n=K[0].image,r=(E.drawImage(n,0,0),E.getImageData(0,0,n.width,n.height).data);for(s.x=Q.x;s.x--;)for(s.y=Q.y;s.y--;)r[4*(s.x+n.width*(15+Q.y-s.y))]&&(i=Math.floor(v(4,0)),e=!Math.floor(v(2,0)),a=oa(),t.setData(s,new qb(1,i,e,a)),ra(s,Q))&&(pb[(0|s.y)*Q.x+s.x|0]=1);for(t.Ca=[D,E,J,A,B],D=t.canvas,E=t.context,J=t.size.multiply(t.l.size),A=t.size.scale(.5),B=t.l.size.x,D.width=J.x,D.height=J.y,t.context.imageSmoothingEnabled=!1,Pb(),s=t.size.x;s--;)for(n=t.size.y;n--;)rb(t,u(s,n),!1);Rb(!0),[D,E,J,A,B]=t.Ca,A=u(16,8),B=32,Ba=-.01,(Z=new vb(u(16,9),0,0,0,500,h,Ja(0,16),y(1,1,1),y(0,0,0),y(0,0,0,0),y(0,0,0,0),2,.2,.2,.1,.05,.99,1,1,h,.05,.5,!0,!0)).s=.3,Z.H=2},function(){O[0]&&2&O[0][0]&&($b.play(Wa),Z.S=y(),Z.T=oa(),Z.da=Z.S.scale(1,0),Z.ea=Z.T.scale(1,0),ac.unlock()),Xa&&(B=k(B-=Math.sign(Xa)*B/5,10,300)),Pa.x&&(Z.i=Wa)},function(){},function(){Ia(u(16,8),u(20,14),void 0,y(0,0,.6),0,!1,void 0,!1),Ia(u(21,5),u(4.5),Ja(3,128))},function(){Ua("LittleJS Demo",u(J.x/2,70),80,y(0,0,1),6,y(0,0,0))},["tiles.png"]);
|
|
Binary file
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
const PROGRAM_TITLE = 'Little JS Starter Project';
|
|
10
10
|
const PROGRAM_NAME = 'game';
|
|
11
11
|
const BUILD_FOLDER = 'build';
|
|
12
|
+
const USE_ROADROLLER = false; // enable for extra compression
|
|
12
13
|
const sourceFiles =
|
|
13
14
|
[
|
|
14
15
|
'../../dist/littlejs.release.js',
|
|
@@ -42,7 +43,9 @@ Build
|
|
|
42
43
|
(
|
|
43
44
|
`${BUILD_FOLDER}/index.js`,
|
|
44
45
|
sourceFiles,
|
|
45
|
-
|
|
46
|
+
USE_ROADROLLER ?
|
|
47
|
+
[closureCompilerStep, uglifyBuildStep, roadrollerBuildStep, htmlBuildStep, zipBuildStep] :
|
|
48
|
+
[closureCompilerStep, uglifyBuildStep, htmlBuildStep, zipBuildStep]
|
|
46
49
|
);
|
|
47
50
|
|
|
48
51
|
console.log('');
|
|
@@ -72,6 +75,7 @@ function closureCompilerStep(filename)
|
|
|
72
75
|
{
|
|
73
76
|
console.log(`Running closure compiler...`);
|
|
74
77
|
|
|
78
|
+
// use closer compiler to minify the code
|
|
75
79
|
const filenameTemp = filename + '.tmp';
|
|
76
80
|
fs.copyFileSync(filename, filenameTemp);
|
|
77
81
|
child_process.execSync(`npx google-closure-compiler --js=${filenameTemp} --js_output_file=${filename} --compilation_level=ADVANCED --warning_level=VERBOSE --jscomp_off=* --assume_function_wrapper`, {stdio: 'inherit'});
|
|
@@ -84,6 +88,12 @@ function uglifyBuildStep(filename)
|
|
|
84
88
|
child_process.execSync(`npx uglifyjs ${filename} -c -m -o ${filename}`, {stdio: 'inherit'});
|
|
85
89
|
};
|
|
86
90
|
|
|
91
|
+
function roadrollerBuildStep(filename)
|
|
92
|
+
{
|
|
93
|
+
console.log(`Running roadroller...`);
|
|
94
|
+
child_process.execSync(`npx roadroller ${filename} -o ${filename}`, {stdio: 'inherit'});
|
|
95
|
+
};
|
|
96
|
+
|
|
87
97
|
function htmlBuildStep(filename)
|
|
88
98
|
{
|
|
89
99
|
console.log(`Building html...`);
|
|
@@ -106,7 +116,7 @@ function zipBuildStep(filename)
|
|
|
106
116
|
{
|
|
107
117
|
console.log(`Zipping...`);
|
|
108
118
|
|
|
109
|
-
|
|
119
|
+
// zip the build folder using ect
|
|
110
120
|
const args = ['-9', '-strip', '-zip', `../${PROGRAM_NAME}.zip`, 'index.html', ...dataFiles];
|
|
111
|
-
child_process.spawnSync(ect, args, {stdio: 'inherit', cwd: BUILD_FOLDER});
|
|
121
|
+
child_process.spawnSync('ect', args, {stdio: 'inherit', cwd: BUILD_FOLDER});
|
|
112
122
|
};
|
package/examples/starter/game.js
CHANGED
|
@@ -58,7 +58,7 @@ function gameInit()
|
|
|
58
58
|
|
|
59
59
|
// setup camera
|
|
60
60
|
cameraPos = vec2(16,8);
|
|
61
|
-
cameraScale =
|
|
61
|
+
cameraScale = 32;
|
|
62
62
|
|
|
63
63
|
// enable gravity
|
|
64
64
|
gravity = -.01;
|
|
@@ -96,6 +96,13 @@ function gameUpdate()
|
|
|
96
96
|
medal_example.unlock();
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
if (mouseWheel)
|
|
100
|
+
{
|
|
101
|
+
// zoom in and out with mouse wheel
|
|
102
|
+
cameraScale -= sign(mouseWheel)*cameraScale/5;
|
|
103
|
+
cameraScale = clamp(cameraScale, 10, 300);
|
|
104
|
+
}
|
|
105
|
+
|
|
99
106
|
// move particles to mouse location if on screen
|
|
100
107
|
if (mousePosScreen.x)
|
|
101
108
|
particleEmitter.pos = mousePos;
|
|
Binary file
|