littlejsengine 1.10.2 → 1.10.4
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 +7 -15
- package/dist/littlejs.d.ts +49 -1
- package/dist/littlejs.esm.js +60 -37
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +46 -37
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +46 -37
- package/examples/box2d/game.js +3 -0
- package/examples/breakoutTutorial/README.md +9 -7
- package/examples/breakoutTutorial/game.js +6 -6
- package/examples/js13k/build/index.html +1 -0
- package/examples/js13k/build/index.js +1 -0
- package/examples/js13k/build/tiles.png +0 -0
- package/examples/js13k/game - Copy.zip +0 -0
- package/examples/js13k/game.zip +0 -0
- package/examples/platformer/game.js +6 -4
- package/examples/platformer/gameCharacter.js +12 -11
- package/examples/platformer/gameEffects.js +3 -4
- package/examples/platformer/gameLevel.js +17 -33
- package/examples/platformer/gameObjects.js +9 -14
- 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/game.zip +0 -0
- package/examples/typescript/build/build/littlejs.esm.js +4327 -0
- package/examples/typescript/build/dist/littlejs.esm.js +4425 -0
- package/examples/typescript/build/examples/typescript/build.js +24 -0
- package/examples/typescript/build/examples/typescript/game.js +100 -0
- package/examples/typescript/build/examples/typescript/test/build/littlejs.esm.js +3934 -0
- package/examples/typescript/build/examples/typescript/test/examples/typescript/build.js +86 -0
- package/examples/typescript/build/examples/typescript/test/examples/typescript/game.js +92 -0
- package/examples/typescript/game.ts +1 -1
- package/package.json +1 -1
- package/plugins/postProcess.js +8 -1
- package/src/engine.js +5 -13
- package/src/engineDraw.js +19 -18
- package/src/engineExport.js +14 -0
- package/src/engineInput.js +1 -3
- package/src/engineObject.js +1 -0
- package/src/engineTileLayer.js +2 -1
- package/src/engineUtilities.js +1 -0
- package/src/engineWebGL.js +17 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<body><script>const g=Math.PI;function n(t,i=0,e=1){return t<i?i:e<t?e:t}function aa(t,i,e){return(e-=i)?n((t-i)/e):0}function ba(t,i,e,a=q()){return 2*Math.abs(t.x-e.x)<i.x+a.x&&2*Math.abs(t.y-e.y)<i.y+a.y}function t(t=1,i=0){return i+Math.random()*(t-i)}function ca(i=1){return da(new v,t(2*g),i)}function ea(i=1){return 0<i?ca(i*t(0/i,1)**.5):new v}function ja(i=new w,e=new w(0,0,0,1),a=!1){return a?i.ma(e,t()):new w(t(i.r,e.r),t(i.j,e.j),t(i.b,e.b),t(i.a,e.a))}function q(t=0,i){return"number"==typeof t?new v(t,null==i?t:i):new v(t.x,t.y)}function da(t,i=0,e=1){return t.x=e*Math.sin(i),t.y=e*Math.cos(i),t}function ka(t){return t.x**2+t.y**2}function la(t,i){return(t.x-i.x)**2+(t.y-i.y)**2}function ma(t){var i=t.length();return 1<i?t.scale(1/i):t}function na(t){return Math.abs(t.x*t.y)}function pa(t,i){return 0<=t.x&&0<=t.y&&t.x<i.x&&t.y<i.y}class v{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 v(this.x,this.y)}add(t){return new v(this.x+t.x,this.y+t.y)}l(t){return new v(this.x-t.x,this.y-t.y)}multiply(t){return new v(this.x*t.x,this.y*t.y)}U(t){return new v(this.x/t.x,this.y/t.y)}scale(t){return new v(this.x*t,this.y*t)}length(){return ka(this)**.5}normalize(t=1){var i=this.length();return i?this.scale(t/i):new v(0,t)}angle(){return Math.atan2(this.x,this.y)}rotate(t){var i=Math.cos(t);return t=Math.sin(t),new v(this.x*i-this.y*t,this.x*t+this.y*i)}setDirection(t,i=1){return q(t%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 v(Math.floor(this.x),Math.floor(this.y))}ma(t,i){return this.add(t.l(this).scale(n(i)))}toString(){}}function qa(t){return(255*n(t.r)|0)+(255*n(t.j)<<8)+(255*n(t.b)<<16)+(255*n(t.a)<<24)}class w{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 w(this.r,this.j,this.b,this.a)}add(t){return new w(this.r+t.r,this.j+t.j,this.b+t.b,this.a+t.a)}l(t){return new w(this.r-t.r,this.j-t.j,this.b-t.b,this.a-t.a)}multiply(t){return new w(this.r*t.r,this.j*t.j,this.b*t.b,this.a*t.a)}U(t){return new w(this.r/t.r,this.j/t.j,this.b/t.b,this.a/t.a)}scale(t,i=t){return new w(this.r*t,this.j*t,this.b*t,this.a*i)}ma(t,i){return this.add(t.l(this).scale(n(i)))}toString(t=!0){var i=t=>((t=255*t|0)<16?"0":"")+t.toString(16);return"#"+i(this.r)+i(this.j)+i(this.b)+(t?i(this.a):"")}}class ra{constructor(){this.setTime=this.time=void 0}set(t=0){this.time=x+t,this.setTime=t}active(){return x<this.time}get(){return null!=this.time?x-this.time:0}toString(){}valueOf(){return this.get()}}function ua(t){var i,e=t.parent;e&&(i=e.o?-1:1,t.i=t.Ca.multiply(q(i,1)).rotate(-e.angle).add(e.i),t.angle=i*t.Ba+e.angle);for(const a of t.children)ua(a)}function va(t){if(!t.A){t.A=1,t.parent&&t.parent.removeChild(t);for(const i of t.children)va(i,i.parent=0)}}class wa{constructor(t=q(),i=q(1),e,a=0,s,h=0){this.i=t.v(),this.size=i,this.xa=void 0,this.s=e,this.angle=a,this.color=s,this.va=void 0,this.o=!1,this.h=xa,this.m=ya,this.K=za,this.u=Aa,this.X=Ba,this.B=1,this.P=h,this.g=q(),this.R=0,this.ua=x,this.children=[],this.ba=!0,this.parent=void 0,this.Ca=q(),this.Ba=0,this.la=this.ca=this.L=!1,y.push(this)}update(){var t;if(!this.parent&&(this.ba?(this.g.x=n(this.g.x,-z,z),this.g.y=n(this.g.y,-z,z)):(t=ka(this.g))>z*z&&(t=z/t**.5,this.g.x*=t,this.g.y*=t),t=this.i.v(),this.g.y+=Ca*this.B,this.i.x+=this.g.x*=this.m,this.i.y+=this.g.y*=this.m,this.angle+=this.R*=this.K,Da&&this.h)){var i,e,a,s,h,r,o=this.g.y<0;if(this.C&&(i=this.C.g?this.C.g.x:0,this.g.x=i+(this.g.x-i)*this.X,this.C=0),this.ca)for(var c of Ea)!this.la&&!c.la||c.A||c.parent||c==this||ba(this.i,this.size,c.i,c.size)&&(ba(t,this.size,c.i,c.size)?(i=(e=(i=t.l(c.i)).length())<.01?ca(.001):i.scale(.001/e),this.g=this.g.add(i),c.h&&(c.g=c.g.l(i))):(e=this.size.add(c.size),a=2*(t.y-c.i.y)>e.y+Ca,s=2*Math.abs(t.y-c.i.y)<e.y,h=2*Math.abs(t.x-c.i.x)<e.x,i=Math.max(this.u,c.u),!a&&!h&&s||(this.i.y=c.i.y+(e.y/2+.001)*Math.sign(t.y-c.i.y),c.C&&o||!c.h?(o&&(this.C=c),this.g.y*=-i):c.h&&(h=(this.h*this.g.y+c.h*c.g.y)/(this.h+c.h),r=c.g.y*(c.h-this.h)/(this.h+c.h)+2*this.g.y*this.h/(this.h+c.h),this.g.y=h+n(i)*(this.g.y*(this.h-c.h)/(this.h+c.h)+2*c.g.y*c.h/(this.h+c.h)-h),c.g.y=h+n(i)*(r-h))),!a&&s&&(this.i.x=c.i.x+(e.x/2+.001)*Math.sign(t.x-c.i.x),c.h?(e=(this.h*this.g.x+c.h*c.g.x)/(this.h+c.h),a=c.g.x*(c.h-this.h)/(this.h+c.h)+2*this.g.x*this.h/(this.h+c.h),this.g.x=e+n(i)*(this.g.x*(this.h-c.h)/(this.h+c.h)+2*c.g.x*c.h/(this.h+c.h)-e),c.g.x=e+n(i)*(a-e)):this.g.x*=-i)));this.L&&Fa(this.i,this.size,this)&&!Fa(t,this.size,this)&&(c=Fa(q(this.i.x,t.y),this.size,this),!Fa(q(t.x,this.i.y),this.size,this)&&c||(this.C=o,this.g.y*=-this.u,(o=(t.y-this.size.y/2|0)-(t.y-this.size.y/2))<0&&o>this.m*this.g.y+Ca*this.B&&(this.g.y=this.m?(o-Ca*this.B)/this.m:0),this.i.y=t.y),c)&&(this.i.x=t.x,this.g.x*=-this.u)}}H(){Ga(this.i,this.xa||this.size,this.s,this.color,this.angle,this.o,this.va)}removeChild(t){t.parent==this&&this.children.includes(t),this.children.splice(this.children.indexOf(t),1),t.parent=0}toString(){}}let B,C,D,Ha,E=q(),Na=[];function Oa(t=q(),i=Pa,e=0){var a;return F?new Qa:("number"==typeof i&&(i=q(i)),"number"==typeof t&&(t=q(t%(a=Na[e].size.x/i.x|0)*i.x,(t/a|0)*i.y)),new Qa(t,i,e))}class Qa{constructor(t=q(),i=Pa,e=0){this.i=t.v(),this.size=i.v(),this.$=e}offset(t){return new Qa(this.i.add(t),this.size,this.$)}frame(t){return this.offset(q(t*this.size.x,0))}}class Ra{constructor(t){var i;this.image=t,this.size=q(t.width,t.height),(i=Sa)&&(i=G.createTexture(),G.bindTexture(3553,i),t&&G.texImage2D(3553,0,6408,6408,5121,t),t=Ta?9728:9729,G.texParameteri(3553,10241,t),G.texParameteri(3553,10240,t)),this.ja=i,this.ya=q(Ua).U(this.size)}}function Va(t){return new v((t.x-I.x)*J+E.x/2-.5,(t.y-I.y)*-J+E.y/2-.5)}function Ga(t,i=q(1),h,n=new w,e=0,a,s=new w(0,0,0,0),r=Sa){const o=h&&Na[h.$];var c,u,l,b;r?o?(r=h.i.x/o.size.x,c=h.i.y/o.size.y,u=h.size.x/o.size.x,l=h.size.y/o.size.y,b=o.ya,Wa(o.ja),Xa(t.x,t.y,a?-i.x:i.x,i.y,e,r+b.x,c+b.y,r-b.x+u,c-b.y+l,qa(n),qa(s))):Xa(t.x,t.y,i.x,i.y,e,0,0,0,0,0,qa(n)):ab(t,i,e,a,t=>{var i,e,a,s;o?(i=h.i.x+Ua,e=h.i.y+Ua,a=h.size.x-2*Ua,s=h.size.y-2*Ua,t.globalAlpha=n.a,t.drawImage(o.image,i,e,a,s,-.5,-.5,1,1),t.globalAlpha=1):(t.fillStyle=n,t.fillRect(-.5,-.5,1,1))})}function ab(t,i,e,a,s){var h=C;t=Va(t),i=i.scale(J),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 bb(t){var i;Sa?cb=t:(i||=C).globalCompositeOperation=t?"lighter":"source-over"}function db(){var i=q(E.x/2,70),t=new w(0,0,0),e=eb,a=Ha;a.fillStyle=(new w).toString(),a.lineWidth=0,a.strokeStyle=t.toString(),a.textAlign="center",a.font="80px "+e,a.textBaseline="middle",a.lineJoin="round",i=i.v(),["LittleJS JS13K Demo"].forEach(t=>{a.fillText(t,i.x,i.y),i.y+=80})}function fb(t,i=0){return K[i]&&!!(1&K[i][t])}let gb=q(),hb=q(),ib=!1;function jb(t,i=0){return fb(t,i+1)}let K=[[]];function kb(){var t;F||(N&&lb||document.hasFocus()||(K=[[]]),t=hb,gb=new v((t.x-E.x/2+.5)/J+I.x,(t.y-E.y/2+.5)/-J+I.y),mb&&nb())}function ob(){if(!F)for(const t of K)for(const i in t)t[i]&=1}function pb(){function i(t){return qb?"KeyW"==t?"ArrowUp":"KeyS"==t?"ArrowDown":"KeyA"==t?"ArrowLeft":"KeyD"==t?"ArrowRight":t:t}F||(onkeydown=t=>{t.repeat||(ib=!1,K[0][t.code]=3,qb&&(K[0][i(t.code)]=3))},onkeyup=t=>{K[0][t.code]=4,qb&&(K[0][i(t.code)]=4)},onmousedown=t=>{ib=!1,K[0][t.button]=3,hb=rb(t),t.button&&t.preventDefault()},onmouseup=t=>K[0][t.button]=2&K[0][t.button]|4,onmousemove=t=>hb=rb(t),onwheel=t=>t.ctrlKey?0:Math.sign(t.deltaY),oncontextmenu=()=>!1,lb&&N&&!F&&sb())}function rb(t){var i;return!B||F?q():(i=B.getBoundingClientRect(),q(B.width,B.height).multiply(q(aa(t.x,i.left,i.right),aa(t.y,i.top,i.bottom))))}const tb=[];function nb(){var t=t=>{var i=t=>.3<t?aa(t,.3,.8):t<-.3?-aa(-t,.3,.8):0;return ma(q(i(t.x),i(-t.y)))};if(ub&&lb&&null!=Ab.time){(i=tb[0]||(tb[0]=[]))[0]=q(),Bb?i[0]=t(O):.3<ka(O)&&(i[0].x=Math.round(O.x),i[0].y=-Math.round(O.y),i[0]=ma(i[0]));for(var i=K[1]||(K[1]=[]),e=10;e--;){var a=3==e?2:2==e?3:e,s=jb(a,0);i[a]=Q[e]?s?1:3:s?4:0}}if(mb&&mb&&navigator&&navigator.getGamepads&&document.hasFocus())for(e=(i=navigator.getGamepads()).length;e--;){var s=i[e],h=K[e+1]||(K[e+1]=[]),a=tb[e]||(tb[e]=[]);if(s){for(var n=0;n<s.axes.length-1;n+=2)a[n>>1]=t(q(s.axes[n],s.axes[n+1]));for(n=s.buttons.length;n--;){var r=s.buttons[n],o=jb(n,e);h[n]=r.pressed?o?1:3:o?4:0,ib||=!e&&r.pressed}Cb&&ka(s=q((jb(15,e)&&1)-(jb(14,e)&&1),(jb(12,e)&&1)-(jb(13,e)&&1)))&&(a[0]=ma(s)),ub&&ib&&(Ab.time=void 0)}}}const lb=void 0!==window.ontouchstart;let Ab=new ra,Q,O;function sb(){function n(t){Db&&R&&"running"!=R.state&&new Eb([0]).play();var i=t.touches.length;return i?(hb=rb(q(t.touches[0].clientX,t.touches[0].clientY)),e?ib=!1:K[0][0]=3):e&&(K[0][0]=2&K[0][0]|4),e=i,document.hasFocus()&&t.preventDefault(),!0}let i=n;ub&&(i=function(t){if(O=q(),Q=[],ib=!0,!t.touches.length||(Ab.set(),!Fb)){var i=q(S,E.y-S),e=E.l(q(S,S)),a=E.scale(.5);for(const h of t.touches){var s=rb(q(h.clientX,h.clientY));la(s,i)**.5<S?O=ma(s.l(i).scale(2/S)):la(s,e)**.5<S?(s=s.l(e).direction(),Q[s]=1):la(s,a)**.5<S&&(Q[9]=1)}return n(t),!0}Q[9]=1},Q=[],O=q()),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}function Gb(){if(N&&lb&&!F&&ub&&null!=Ab.time){var t=aa(Ab.get(),4,3);if(t&&!Fb){var i=Ha;if(i.save(),i.globalAlpha=t*Hb,i.strokeStyle="#fff",i.lineWidth=3,i.fillStyle=0<ka(O)?"#fff":"#000",i.beginPath(),t=q(S,E.y-S),Bb)i.arc(t.x,t.y,S/2,0,9),i.fill();else for(var e=10;e--;){var a=e*g/4;i.arc(t.x,t.y,.6*S,a+g/8,a+g/8),e%2&&i.arc(t.x,t.y,.33*S,a,a),1==e&&i.fill()}for(i.stroke(),t=q(E.x-S,E.y-S),e=4;e--;)a=t.add(q().setDirection(e,S/2)),i.fillStyle=Q[e]?"#fff":"#000",i.beginPath(),i.arc(a.x,a.y,S/4,0,9),i.fill(),i.stroke();i.restore()}}}let R,Ib;class Eb{constructor(t){var i=Jb,e=Kb;Db&&!F&&(this.Fa=i,this.Ja=e,this.O=0,t)&&(this.O=t[1]||.05,this.ta=[Lb(...t)],this.sampleRate=44100)}play(i,e=1,a=1,s=1,h=!1){if(Db&&!F&&this.ta){var n;if(i){if(n=this.Fa){var r=la(I,i);if(n*n<r)return;e*=aa(r**.5,n,n*this.Ja)}n=2*Va(i).x/B.width-1}return i=a+a*this.O*s*t(-1,1),this.za=R.createGain(),this.source=Mb(this.ta,e,i,n,h,this.sampleRate,this.za)}}stop(){this.source&&this.source.stop(),this.source=void 0}}let Nb=!1;function Mb(t,i=1,e=1,a=0,s=!1,h=44100,r){if(Db&&!F){var o,c=Nb;if(!(Nb="running"!=R.state)||(R.resume(),!c))return o=R.createBuffer(t.length,t[0].length,h),h=R.createBufferSource(),t.forEach((t,i)=>o.getChannelData(i).set(t)),h.buffer=o,h.playbackRate.value=e,h.loop=s,(r=r||R.createGain()).gain.value=i,r.connect(Ib),h.connect(new StereoPannerNode(R,{pan:n(a,-1,1)})).connect(r),h.start(),h}}function Lb(t=1,i,e=220,a=0,s=0,h=.1,r=0,o=1,c=0,u=0,l=0,b=0,f=0,d=0,y=0,x=0,v=0,m=1,w=0,p=0,q=0){let O=c*=500*(i=2*g)/44100/44100,S=e*=i/44100,z=[],G=0,k=0,M=0,B=1,U=0,J=0,D=0;var F=i*Math.abs(q)*2/44100,C=Math.cos(F),E=1+(A=Math.sin(F)/2/2),F=-2*C/E,A=(1-A)/E;let j=(1+Math.sign(q)*C)/2/E,P=-(Math.sign(q)+C)/E,T=0,K=0,I=0,R=0;for(u*=500*i/44100**3,y*=i/44100,l*=i/44100,b*=44100,f=44100*f|0,E=(a=44100*a+9)+(w*=44100)+(s*=44100)+(h*=44100)+(v*=44100)|0;M<E;z[M++]=D*t)++J%(100*x|0)||(D=r?1<r?2<r?3<r?Math.sin(G**3):n(Math.tan(G),1,-1):1-(2*G/i%2+2)%2:1-4*Math.abs(Math.round(G/i)-G/i):Math.sin(G),D=(f?1-p+p*Math.sin(i*M/f):1)*Math.sign(D)*Math.abs(D)**o*(M<a?M/a:M<a+w?1-(M-a)/w*(1-m):M<a+w+s?m:M<E-v?(E-M-v)/h*m:0),D=v?D/2+(v>M?0:(M<E-v?1:(E-M)/v)*z[M-v|0]/2/t):D,q&&(D=R=j*T+P*(T=K)+j*(K=D)-A*I-F*(I=R))),C=(e+=c+=u)*Math.cos(y*k++),G+=C+C*d*Math.sin(M**5),B&&++B>b&&(e+=l,S+=l,B=0),!f||++U%f||(e=S,c=O,B=B||1);return z}let Ob=[],T=q();function Fa(t,i=q(),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,T.x);for(t=Math.min(t.y+i.y/2,T.y);s<t;++s)for(i=a;i<h;++i){var n=Ob[s*T.x+i];if(n&&(!e||0<n))return!0}}class Pb{constructor(t,i=0,e=!1,a=new w){this.aa=t,this.direction=i,this.o=e,this.color=a}clear(){this.aa=this.direction=0,this.o=!1,this.color=new w}}class Qb extends wa{constructor(t,i=T){var e=q(1);for(super(t,i,Oa(),0,void 0,0),this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.scale=e,this.ka=!1,this.data=[],t=na(this.size);t--;)this.data.push(new Pb);F&&(this.qa=()=>{},this.H=()=>{},this.sa=()=>{},this.ra=()=>{},this.V=()=>{})}setData(t,i,e=!1){pa(t,this.size)&&(this.data[(0|t.y)*this.size.x+t.x|0]=i,e)&&this.V(t)}getData(t){return pa(t,this.size)&&this.data[(0|t.y)*this.size.x+t.x|0]}update(){}H(){Rb||this.ka||Sb();var t=Va(this.i.add(q(0,this.size.y*this.scale.y)));(this.ka?Ha:C).drawImage(this.canvas,t.x,t.y,J*this.size.x*this.scale.x,J*this.size.y*this.scale.y)}qa(){this.sa(!0);for(let i=this.size.x;i--;)for(let t=this.size.y;t--;)this.V(q(i,t),!1);this.ra()}sa(t=!1){this.Ga=[B,C,E,I,J],B=this.canvas,C=this.context,E=this.size.multiply(this.s.size),I=this.size.scale(.5),J=this.s.size.x,t&&(B.width=E.x,B.height=E.y),this.context.imageSmoothingEnabled=!Ta,Tb()}ra(){Sb(!0),[B,C,E,I,J]=this.Ga}V(t,i=!0){var e=this.s.size;i&&(i=t.multiply(e),this.context.clearRect(i.x,this.canvas.height-i.y,e.x,-e.y)),null!=(i=this.getData(t)).aa&&Ga(t=this.i.add(t).add(q(.5)),q(1),Oa(i.aa,e,this.s.$),i.color,i.direction*g/2,i.o)}}function Ub(i){var e="number"==typeof i.W?ea(i.W/2):q(t(-.5,.5),t(-.5,.5)).multiply(i.W).rotate(i.angle);let a=t(i.na,-i.na);i.Y||(e=i.i.add(e),a+=i.angle);const s=i.O;var h=(c=i=>i+i*t(s,-s))(i.Ea),n=c(i.Z),r=c(i.Ha),o=c(i.speed),c=c(i.wa)*(2*Math.floor(t(2,0))-1),u=t(i.ga,-i.ga),l=ja(i.S,i.T,i.pa),b=ja(i.da,i.ea,i.pa),u=i.Y?u:i.angle+u;(e=new Vb(e,i.s,a,l,b,h,n,r,i.G,i.J,i.I,i.Y&&i,i.Da)).g=da(q(),u,o),e.R=c,e.G=i.G,e.m=i.m,e.K=i.K,e.u=i.u,e.X=i.X,e.B=i.B,e.L=i.L,e.P=i.P,e.o=!!Math.floor(t(2,0)),i.oa&&i.oa(e)}class Wb extends wa{constructor(t,i,e=0,a=0,s=100,h=g,n,r=new w,o=new w,c=new w(1,1,1,0),u=new w(1,1,1,0),l=.5,b=.1,f=1,d=.1,y=.05,x=1,v=1,m=0,p=g,S=.1,z=.2,G=!1,M=!1,B=!0,D=M?1e9:0,F=!1){super(t,q(),n,i,void 0,D),this.W=e,this.ia=a,this.ha=s,this.ga=h,this.S=r,this.T=o,this.da=c,this.ea=u,this.pa=B,this.Ea=l,this.Z=b,this.Ha=f,this.speed=d,this.wa=y,this.m=x,this.K=v,this.B=m,this.na=p,this.G=S,this.O=z,this.L=G,this.J=M,this.Y=F,this.I=0,this.oa=this.Da=void 0,this.F=0}update(){if(this.parent&&super.update(),!this.ia||x-this.ua<=this.ia){if(this.ha*Xb){var t=1/this.ha/Xb;for(this.F+=Yb;0<this.F;this.F-=t)Ub(this)}}else va(this)}H(){}}class Vb extends wa{constructor(t,i,e,a,s,h,n,r,o,c,u,l,b){super(t,q(),i,e),this.N=a,this.M=s.l(a),this.Aa=h,this.Z=n,this.Ia=r-n,this.G=o,this.J=c,this.I=u,this.D=l,this.fa=b,this.ba=!1}H(){var t=Math.min((x-this.ua)/this.Aa,1),i=q(this.Z+t*this.Ia),e=this.G/2,e=new w(this.N.r+t*this.M.r,this.N.j+t*this.M.j,this.N.b+t*this.M.b,(this.N.a+t*this.M.a)*(t<e?t/e:1-e<t?(1-t)/e:1));this.J&&bb(!0);let a=this.i;var s,h,n=this.angle;this.D&&(a=this.D.i.add(a.rotate(-this.D.angle)),n+=this.D.angle),this.I?(s=this.g,(n=(s=this.D?s.rotate(-this.D.angle):s).length())&&(s=s.scale(1/n),h=n*this.I,i.y=Math.max(i.x,h),n=s.angle(),Ga(a.add(s.multiply(q(0,-h/2))),i,this.s,e,n,this.o))):Ga(a,i,this.s,e,n,this.o),this.J&&bb(),1==t&&(this.color=e,this.size=i,this.fa&&this.fa(this),this.A=1)}}let U,G,Zb,$b,ac,bc,V,cc,W,cb,dc;function ec(){var t;Sa&&!F&&(U=document.createElement("canvas"),G=U.getContext("webgl2"),Rb&&document.body.appendChild(U),t=G.createProgram(),G.attachShader(t,ic("#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;}",35633)),G.attachShader(t,ic("#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;}",35632)),G.linkProgram(t),Zb=t,t=new ArrayBuffer(44e4),V=new Float32Array(t),cc=new Uint32Array(t),ac=G.createBuffer(),bc=G.createBuffer(),t=new Float32Array([W=0,0,1,0,0,1,1,1]),G.bindBuffer(34962,bc),G.bufferData(34962,t,35044))}function Tb(){var r,t,i;Sa&&!F&&(G.viewport(0,0,U.width=B.width,U.height=B.height),G.clear(16384),G.useProgram(Zb),G.activeTexture(33984),G.bindTexture(3553,$b=Na[0].ja),r=cb=dc=0,t=(t,i,e,a)=>{t=G.getAttribLocation(Zb,t);var s=e&&44,h=e&&1,n=1==e;G.enableVertexAttribArray(t),G.vertexAttribPointer(t,a,i,n,s,r),G.vertexAttribDivisor(t,h),r+=a*e},G.bindBuffer(34962,bc),t("g",5126,0,2),G.bindBuffer(34962,ac),G.bufferData(34962,44e4,35048),t("p",5126,4,4),t("u",5126,4,4),t("c",5121,1,4),t("a",5121,1,4),t("r",5126,4,1),t=q(2*J).U(E),i=q(-1).l(I.multiply(t)),G.uniformMatrix4fv(G.getUniformLocation(Zb,"m"),!1,[t.x,0,0,0,0,t.y,0,0,1,1,1,1,i.x,i.y,0,0]))}function Wa(t){F||t==$b||(jc(),G.bindTexture(3553,$b=t))}function ic(t,i){return i=G.createShader(i),G.shaderSource(i,t),G.compileShader(i),i}function jc(){var t;W&&(t=dc?1:771,G.blendFuncSeparate(770,t,1,t),G.enable(3042),G.bufferSubData(34962,0,V),G.drawArraysInstanced(5,0,4,W),W=0,dc=cb)}function Sb(t=!1){var i=C;Sa&&(W||t)&&(jc(),Rb&&!t||i.drawImage(U,0,0))}function Xa(t,i,e,a,s,h,n,r,o,c,u=0){(1e4<=W||dc!=cb)&&jc();var l=11*W;V[l++]=t,V[l++]=i,V[l++]=e,V[l++]=a,V[l++]=h,V[l++]=n,V[l++]=r,V[l++]=o,cc[l++]=c,cc[l++]=u,V[+l]=s,W++}const Yb=1/60;let y=[],Ea=[],kc=0,x=0,Fb=!1,lc=0,X=0;const mc=[],nc=[];function oc(){Ea=y.filter(t=>t.ca);for(const t of y)t.parent||(function t(i){if(!i.A){i.update();for(const e of i.children)t(e)}}(t),ua(t));y=y.filter(t=>!t.A)}let I=q(),J=32,pc=q(1920,1080),qc=q(),Ta=!0,eb="arial",F=!1,Sa=!0,Rb=!0,Pa=q(16),Ua=.5,Da=!0,xa=1,ya=1,za=1,Aa=0,Ba=.8,z=1,Ca=0,Xb=1,mb=!1,Cb=!(mb=!1),qb=!0,N=!1,ub=N=N=!1,Bb=!0,S=99,Hb=.3,Db=!0,rc=.3,Jb=40,Kb=.7;function sc(){var t=rc;rc=t,Db&&!F&&Ib&&(Ib.gain.value=t)}let Y;qb=N=!1;const tc=new Eb([1,.5]);!function(s,h,n,r,i=["tiles.png"]){function o(t=0){var i=t-lc;if(lc=t,X+=Fb?0:i,X=Math.min(X,50),c(),Fb){for(const e of y)e.parent||ua(e);kb(),h(),ob()}else{for(t=0,X<0&&-9<X&&(t=X,X=0);0<=X;X-=1e3/60)x=kc++/60,kb(),s(),mc.forEach(t=>t()),oc(),h(),ob();X+=t}if(!F){E=q(B.width,B.height),C.imageSmoothingEnabled=!Ta,Tb(),n(),y.sort((t,i)=>t.P-i.P);for(const a of y)a.A||a.H();r(),nc.forEach(t=>t()),Gb(),Sb()}requestAnimationFrame(o)}function c(){var t,i;F||(qc.x?(B.width=qc.x,B.height=qc.y,t=innerWidth/innerHeight,i=B.width/B.height,(U||B).style.width=B.style.width=D.style.width=t<i?"100%":"",(U||B).style.height=B.style.height=D.style.height=t<i?"":"100%"):(B.width=Math.min(innerWidth,pc.x),B.height=Math.min(innerHeight,pc.y)),D.width=B.width,D.height=B.height,E=q(B.width,B.height))}function e(){{T=q(32,16);for(var i=(Ob=[]).length=na(T);i--;)Ob[i]=0;i=q();var e=new Qb(i,T),a=Na[0].image,s=(C.drawImage(a,0,0),C.getImageData(0,0,a.width,a.height).data),h,n,r;for(i.x=T.x;i.x--;)for(i.y=T.y;i.y--;)s[4*(i.x+a.width*(15+T.y-i.y))]&&(h=Math.floor(t(4,0)),n=Math.floor(t(2,0)),r=ja(),e.setData(i,new Pb(1,h,n,r)),pa(i,T))&&(Ob[(0|i.y)*T.x+i.x|0]=1);e.qa(),I=q(16,8),Ca=-.01,(Y=new Wb(q(16,9),0,1,0,500,g,Oa(0,16),new w(1,1,1),new w(0,0,0),new w(0,0,0,0),new w(0,0,0,0),2,.2,.2,.1,.05,.99,1,1,g,.05,.5,1,1)).u=.3,Y.I=2}o()}F?e():(document.body.style.cssText="margin:0;overflow:hidden;background:#000;user-select:none;-webkit-user-select:none;"+(N?"touch-action:none;-webkit-touch-callout:none":""),document.body.appendChild(B=document.createElement("canvas")),C=B.getContext("2d"),pb(),Db&&!F&&(R=new AudioContext,(Ib=R.createGain()).connect(R.destination),sc()),ec(),document.body.appendChild(D=document.createElement("canvas")),Ha=D.getContext("2d"),(U||B).style.cssText=B.style.cssText=D.style.cssText="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)",c(),i=i.map((e,a)=>new Promise(t=>{const i=new Image;i.onerror=i.onload=()=>{Na[a]=new Ra(i),t()},i.src=e})),Promise.all(i).then(e))}(function(){K[0]&&2&K[0][0]&&(tc.play(gb),Y.S=new w,Y.T=ja(),Y.da=Y.S.scale(1,0),Y.ea=Y.T.scale(1,0)),hb.x&&(Y.i=gb)},function(){},function(){Ga(q(16,8),q(20,14),void 0,new w(.6,.6,.6),0,!1,void 0,0)},function(){db()});</script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const g=Math.PI;function n(t,i=0,e=1){return t<i?i:e<t?e:t}function aa(t,i,e){return(e-=i)?n((t-i)/e):0}function ba(t,i,e,a=q()){return 2*Math.abs(t.x-e.x)<i.x+a.x&&2*Math.abs(t.y-e.y)<i.y+a.y}function t(t=1,i=0){return i+Math.random()*(t-i)}function ca(i=1){return da(new v,t(2*g),i)}function ea(i=1){return 0<i?ca(i*t(0/i,1)**.5):new v}function ja(i=new w,e=new w(0,0,0,1),a=!1){return a?i.ma(e,t()):new w(t(i.r,e.r),t(i.j,e.j),t(i.b,e.b),t(i.a,e.a))}function q(t=0,i){return"number"==typeof t?new v(t,null==i?t:i):new v(t.x,t.y)}function da(t,i=0,e=1){return t.x=e*Math.sin(i),t.y=e*Math.cos(i),t}function ka(t){return t.x**2+t.y**2}function la(t,i){return(t.x-i.x)**2+(t.y-i.y)**2}function ma(t){var i=t.length();return 1<i?t.scale(1/i):t}function na(t){return Math.abs(t.x*t.y)}function pa(t,i){return 0<=t.x&&0<=t.y&&t.x<i.x&&t.y<i.y}class v{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 v(this.x,this.y)}add(t){return new v(this.x+t.x,this.y+t.y)}l(t){return new v(this.x-t.x,this.y-t.y)}multiply(t){return new v(this.x*t.x,this.y*t.y)}U(t){return new v(this.x/t.x,this.y/t.y)}scale(t){return new v(this.x*t,this.y*t)}length(){return ka(this)**.5}normalize(t=1){var i=this.length();return i?this.scale(t/i):new v(0,t)}angle(){return Math.atan2(this.x,this.y)}rotate(t){var i=Math.cos(t);return t=Math.sin(t),new v(this.x*i-this.y*t,this.x*t+this.y*i)}setDirection(t,i=1){return q(t%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 v(Math.floor(this.x),Math.floor(this.y))}ma(t,i){return this.add(t.l(this).scale(n(i)))}toString(){}}function qa(t){return(255*n(t.r)|0)+(255*n(t.j)<<8)+(255*n(t.b)<<16)+(255*n(t.a)<<24)}class w{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 w(this.r,this.j,this.b,this.a)}add(t){return new w(this.r+t.r,this.j+t.j,this.b+t.b,this.a+t.a)}l(t){return new w(this.r-t.r,this.j-t.j,this.b-t.b,this.a-t.a)}multiply(t){return new w(this.r*t.r,this.j*t.j,this.b*t.b,this.a*t.a)}U(t){return new w(this.r/t.r,this.j/t.j,this.b/t.b,this.a/t.a)}scale(t,i=t){return new w(this.r*t,this.j*t,this.b*t,this.a*i)}ma(t,i){return this.add(t.l(this).scale(n(i)))}toString(t=!0){var i=t=>((t=255*t|0)<16?"0":"")+t.toString(16);return"#"+i(this.r)+i(this.j)+i(this.b)+(t?i(this.a):"")}}class ra{constructor(){this.setTime=this.time=void 0}set(t=0){this.time=x+t,this.setTime=t}active(){return x<this.time}get(){return null!=this.time?x-this.time:0}toString(){}valueOf(){return this.get()}}function ua(t){var i,e=t.parent;e&&(i=e.o?-1:1,t.i=t.Ca.multiply(q(i,1)).rotate(-e.angle).add(e.i),t.angle=i*t.Ba+e.angle);for(const a of t.children)ua(a)}function va(t){if(!t.A){t.A=1,t.parent&&t.parent.removeChild(t);for(const i of t.children)va(i,i.parent=0)}}class wa{constructor(t=q(),i=q(1),e,a=0,s,h=0){this.i=t.v(),this.size=i,this.xa=void 0,this.s=e,this.angle=a,this.color=s,this.va=void 0,this.o=!1,this.h=xa,this.m=ya,this.K=za,this.u=Aa,this.X=Ba,this.B=1,this.P=h,this.g=q(),this.R=0,this.ua=x,this.children=[],this.ba=!0,this.parent=void 0,this.Ca=q(),this.Ba=0,this.la=this.ca=this.L=!1,y.push(this)}update(){var t;if(!this.parent&&(this.ba?(this.g.x=n(this.g.x,-z,z),this.g.y=n(this.g.y,-z,z)):(t=ka(this.g))>z*z&&(t=z/t**.5,this.g.x*=t,this.g.y*=t),t=this.i.v(),this.g.y+=Ca*this.B,this.i.x+=this.g.x*=this.m,this.i.y+=this.g.y*=this.m,this.angle+=this.R*=this.K,Da&&this.h)){var i,e,a,s,h,r,o=this.g.y<0;if(this.C&&(i=this.C.g?this.C.g.x:0,this.g.x=i+(this.g.x-i)*this.X,this.C=0),this.ca)for(var c of Ea)!this.la&&!c.la||c.A||c.parent||c==this||ba(this.i,this.size,c.i,c.size)&&(ba(t,this.size,c.i,c.size)?(i=(e=(i=t.l(c.i)).length())<.01?ca(.001):i.scale(.001/e),this.g=this.g.add(i),c.h&&(c.g=c.g.l(i))):(e=this.size.add(c.size),a=2*(t.y-c.i.y)>e.y+Ca,s=2*Math.abs(t.y-c.i.y)<e.y,h=2*Math.abs(t.x-c.i.x)<e.x,i=Math.max(this.u,c.u),!a&&!h&&s||(this.i.y=c.i.y+(e.y/2+.001)*Math.sign(t.y-c.i.y),c.C&&o||!c.h?(o&&(this.C=c),this.g.y*=-i):c.h&&(h=(this.h*this.g.y+c.h*c.g.y)/(this.h+c.h),r=c.g.y*(c.h-this.h)/(this.h+c.h)+2*this.g.y*this.h/(this.h+c.h),this.g.y=h+n(i)*(this.g.y*(this.h-c.h)/(this.h+c.h)+2*c.g.y*c.h/(this.h+c.h)-h),c.g.y=h+n(i)*(r-h))),!a&&s&&(this.i.x=c.i.x+(e.x/2+.001)*Math.sign(t.x-c.i.x),c.h?(e=(this.h*this.g.x+c.h*c.g.x)/(this.h+c.h),a=c.g.x*(c.h-this.h)/(this.h+c.h)+2*this.g.x*this.h/(this.h+c.h),this.g.x=e+n(i)*(this.g.x*(this.h-c.h)/(this.h+c.h)+2*c.g.x*c.h/(this.h+c.h)-e),c.g.x=e+n(i)*(a-e)):this.g.x*=-i)));this.L&&Fa(this.i,this.size,this)&&!Fa(t,this.size,this)&&(c=Fa(q(this.i.x,t.y),this.size,this),!Fa(q(t.x,this.i.y),this.size,this)&&c||(this.C=o,this.g.y*=-this.u,(o=(t.y-this.size.y/2|0)-(t.y-this.size.y/2))<0&&o>this.m*this.g.y+Ca*this.B&&(this.g.y=this.m?(o-Ca*this.B)/this.m:0),this.i.y=t.y),c)&&(this.i.x=t.x,this.g.x*=-this.u)}}H(){Ga(this.i,this.xa||this.size,this.s,this.color,this.angle,this.o,this.va)}removeChild(t){t.parent==this&&this.children.includes(t),this.children.splice(this.children.indexOf(t),1),t.parent=0}toString(){}}let B,C,D,Ha,E=q(),Na=[];function Oa(t=q(),i=Pa,e=0){var a;return F?new Qa:("number"==typeof i&&(i=q(i)),"number"==typeof t&&(t=q(t%(a=Na[e].size.x/i.x|0)*i.x,(t/a|0)*i.y)),new Qa(t,i,e))}class Qa{constructor(t=q(),i=Pa,e=0){this.i=t.v(),this.size=i.v(),this.$=e}offset(t){return new Qa(this.i.add(t),this.size,this.$)}frame(t){return this.offset(q(t*this.size.x,0))}}class Ra{constructor(t){var i;this.image=t,this.size=q(t.width,t.height),(i=Sa)&&(i=G.createTexture(),G.bindTexture(3553,i),t&&G.texImage2D(3553,0,6408,6408,5121,t),t=Ta?9728:9729,G.texParameteri(3553,10241,t),G.texParameteri(3553,10240,t)),this.ja=i,this.ya=q(Ua).U(this.size)}}function Va(t){return new v((t.x-I.x)*J+E.x/2-.5,(t.y-I.y)*-J+E.y/2-.5)}function Ga(t,i=q(1),h,n=new w,e=0,a,s=new w(0,0,0,0),r=Sa){const o=h&&Na[h.$];var c,u,l,b;r?o?(r=h.i.x/o.size.x,c=h.i.y/o.size.y,u=h.size.x/o.size.x,l=h.size.y/o.size.y,b=o.ya,Wa(o.ja),Xa(t.x,t.y,a?-i.x:i.x,i.y,e,r+b.x,c+b.y,r-b.x+u,c-b.y+l,qa(n),qa(s))):Xa(t.x,t.y,i.x,i.y,e,0,0,0,0,0,qa(n)):ab(t,i,e,a,t=>{var i,e,a,s;o?(i=h.i.x+Ua,e=h.i.y+Ua,a=h.size.x-2*Ua,s=h.size.y-2*Ua,t.globalAlpha=n.a,t.drawImage(o.image,i,e,a,s,-.5,-.5,1,1),t.globalAlpha=1):(t.fillStyle=n,t.fillRect(-.5,-.5,1,1))})}function ab(t,i,e,a,s){var h=C;t=Va(t),i=i.scale(J),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 bb(t){var i;Sa?cb=t:(i||=C).globalCompositeOperation=t?"lighter":"source-over"}function db(){var i=q(E.x/2,70),t=new w(0,0,0),e=eb,a=Ha;a.fillStyle=(new w).toString(),a.lineWidth=0,a.strokeStyle=t.toString(),a.textAlign="center",a.font="80px "+e,a.textBaseline="middle",a.lineJoin="round",i=i.v(),["LittleJS JS13K Demo"].forEach(t=>{a.fillText(t,i.x,i.y),i.y+=80})}function fb(t,i=0){return K[i]&&!!(1&K[i][t])}let gb=q(),hb=q(),ib=!1;function jb(t,i=0){return fb(t,i+1)}let K=[[]];function kb(){var t;F||(N&&lb||document.hasFocus()||(K=[[]]),t=hb,gb=new v((t.x-E.x/2+.5)/J+I.x,(t.y-E.y/2+.5)/-J+I.y),mb&&nb())}function ob(){if(!F)for(const t of K)for(const i in t)t[i]&=1}function pb(){function i(t){return qb?"KeyW"==t?"ArrowUp":"KeyS"==t?"ArrowDown":"KeyA"==t?"ArrowLeft":"KeyD"==t?"ArrowRight":t:t}F||(onkeydown=t=>{t.repeat||(ib=!1,K[0][t.code]=3,qb&&(K[0][i(t.code)]=3))},onkeyup=t=>{K[0][t.code]=4,qb&&(K[0][i(t.code)]=4)},onmousedown=t=>{ib=!1,K[0][t.button]=3,hb=rb(t),t.button&&t.preventDefault()},onmouseup=t=>K[0][t.button]=2&K[0][t.button]|4,onmousemove=t=>hb=rb(t),onwheel=t=>t.ctrlKey?0:Math.sign(t.deltaY),oncontextmenu=()=>!1,lb&&N&&!F&&sb())}function rb(t){var i;return!B||F?q():(i=B.getBoundingClientRect(),q(B.width,B.height).multiply(q(aa(t.x,i.left,i.right),aa(t.y,i.top,i.bottom))))}const tb=[];function nb(){var t=t=>{var i=t=>.3<t?aa(t,.3,.8):t<-.3?-aa(-t,.3,.8):0;return ma(q(i(t.x),i(-t.y)))};if(ub&&lb&&null!=Ab.time){(i=tb[0]||(tb[0]=[]))[0]=q(),Bb?i[0]=t(O):.3<ka(O)&&(i[0].x=Math.round(O.x),i[0].y=-Math.round(O.y),i[0]=ma(i[0]));for(var i=K[1]||(K[1]=[]),e=10;e--;){var a=3==e?2:2==e?3:e,s=jb(a,0);i[a]=Q[e]?s?1:3:s?4:0}}if(mb&&mb&&navigator&&navigator.getGamepads&&document.hasFocus())for(e=(i=navigator.getGamepads()).length;e--;){var s=i[e],h=K[e+1]||(K[e+1]=[]),a=tb[e]||(tb[e]=[]);if(s){for(var n=0;n<s.axes.length-1;n+=2)a[n>>1]=t(q(s.axes[n],s.axes[n+1]));for(n=s.buttons.length;n--;){var r=s.buttons[n],o=jb(n,e);h[n]=r.pressed?o?1:3:o?4:0,ib||=!e&&r.pressed}Cb&&ka(s=q((jb(15,e)&&1)-(jb(14,e)&&1),(jb(12,e)&&1)-(jb(13,e)&&1)))&&(a[0]=ma(s)),ub&&ib&&(Ab.time=void 0)}}}const lb=void 0!==window.ontouchstart;let Ab=new ra,Q,O;function sb(){function n(t){Db&&R&&"running"!=R.state&&new Eb([0]).play();var i=t.touches.length;return i?(hb=rb(q(t.touches[0].clientX,t.touches[0].clientY)),e?ib=!1:K[0][0]=3):e&&(K[0][0]=2&K[0][0]|4),e=i,document.hasFocus()&&t.preventDefault(),!0}let i=n;ub&&(i=function(t){if(O=q(),Q=[],ib=!0,!t.touches.length||(Ab.set(),!Fb)){var i=q(S,E.y-S),e=E.l(q(S,S)),a=E.scale(.5);for(const h of t.touches){var s=rb(q(h.clientX,h.clientY));la(s,i)**.5<S?O=ma(s.l(i).scale(2/S)):la(s,e)**.5<S?(s=s.l(e).direction(),Q[s]=1):la(s,a)**.5<S&&(Q[9]=1)}return n(t),!0}Q[9]=1},Q=[],O=q()),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}function Gb(){if(N&&lb&&!F&&ub&&null!=Ab.time){var t=aa(Ab.get(),4,3);if(t&&!Fb){var i=Ha;if(i.save(),i.globalAlpha=t*Hb,i.strokeStyle="#fff",i.lineWidth=3,i.fillStyle=0<ka(O)?"#fff":"#000",i.beginPath(),t=q(S,E.y-S),Bb)i.arc(t.x,t.y,S/2,0,9),i.fill();else for(var e=10;e--;){var a=e*g/4;i.arc(t.x,t.y,.6*S,a+g/8,a+g/8),e%2&&i.arc(t.x,t.y,.33*S,a,a),1==e&&i.fill()}for(i.stroke(),t=q(E.x-S,E.y-S),e=4;e--;)a=t.add(q().setDirection(e,S/2)),i.fillStyle=Q[e]?"#fff":"#000",i.beginPath(),i.arc(a.x,a.y,S/4,0,9),i.fill(),i.stroke();i.restore()}}}let R,Ib;class Eb{constructor(t){var i=Jb,e=Kb;Db&&!F&&(this.Fa=i,this.Ja=e,this.O=0,t)&&(this.O=t[1]||.05,this.ta=[Lb(...t)],this.sampleRate=44100)}play(i,e=1,a=1,s=1,h=!1){if(Db&&!F&&this.ta){var n;if(i){if(n=this.Fa){var r=la(I,i);if(n*n<r)return;e*=aa(r**.5,n,n*this.Ja)}n=2*Va(i).x/B.width-1}return i=a+a*this.O*s*t(-1,1),this.za=R.createGain(),this.source=Mb(this.ta,e,i,n,h,this.sampleRate,this.za)}}stop(){this.source&&this.source.stop(),this.source=void 0}}let Nb=!1;function Mb(t,i=1,e=1,a=0,s=!1,h=44100,r){if(Db&&!F){var o,c=Nb;if(!(Nb="running"!=R.state)||(R.resume(),!c))return o=R.createBuffer(t.length,t[0].length,h),h=R.createBufferSource(),t.forEach((t,i)=>o.getChannelData(i).set(t)),h.buffer=o,h.playbackRate.value=e,h.loop=s,(r=r||R.createGain()).gain.value=i,r.connect(Ib),h.connect(new StereoPannerNode(R,{pan:n(a,-1,1)})).connect(r),h.start(),h}}function Lb(t=1,i,e=220,a=0,s=0,h=.1,r=0,o=1,c=0,u=0,l=0,b=0,f=0,d=0,y=0,x=0,v=0,m=1,w=0,p=0,q=0){let O=c*=500*(i=2*g)/44100/44100,S=e*=i/44100,z=[],G=0,k=0,M=0,B=1,U=0,J=0,D=0;var F=i*Math.abs(q)*2/44100,C=Math.cos(F),E=1+(A=Math.sin(F)/2/2),F=-2*C/E,A=(1-A)/E;let j=(1+Math.sign(q)*C)/2/E,P=-(Math.sign(q)+C)/E,T=0,K=0,I=0,R=0;for(u*=500*i/44100**3,y*=i/44100,l*=i/44100,b*=44100,f=44100*f|0,E=(a=44100*a+9)+(w*=44100)+(s*=44100)+(h*=44100)+(v*=44100)|0;M<E;z[M++]=D*t)++J%(100*x|0)||(D=r?1<r?2<r?3<r?Math.sin(G**3):n(Math.tan(G),1,-1):1-(2*G/i%2+2)%2:1-4*Math.abs(Math.round(G/i)-G/i):Math.sin(G),D=(f?1-p+p*Math.sin(i*M/f):1)*Math.sign(D)*Math.abs(D)**o*(M<a?M/a:M<a+w?1-(M-a)/w*(1-m):M<a+w+s?m:M<E-v?(E-M-v)/h*m:0),D=v?D/2+(v>M?0:(M<E-v?1:(E-M)/v)*z[M-v|0]/2/t):D,q&&(D=R=j*T+P*(T=K)+j*(K=D)-A*I-F*(I=R))),C=(e+=c+=u)*Math.cos(y*k++),G+=C+C*d*Math.sin(M**5),B&&++B>b&&(e+=l,S+=l,B=0),!f||++U%f||(e=S,c=O,B=B||1);return z}let Ob=[],T=q();function Fa(t,i=q(),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,T.x);for(t=Math.min(t.y+i.y/2,T.y);s<t;++s)for(i=a;i<h;++i){var n=Ob[s*T.x+i];if(n&&(!e||0<n))return!0}}class Pb{constructor(t,i=0,e=!1,a=new w){this.aa=t,this.direction=i,this.o=e,this.color=a}clear(){this.aa=this.direction=0,this.o=!1,this.color=new w}}class Qb extends wa{constructor(t,i=T){var e=q(1);for(super(t,i,Oa(),0,void 0,0),this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.scale=e,this.ka=!1,this.data=[],t=na(this.size);t--;)this.data.push(new Pb);F&&(this.qa=()=>{},this.H=()=>{},this.sa=()=>{},this.ra=()=>{},this.V=()=>{})}setData(t,i,e=!1){pa(t,this.size)&&(this.data[(0|t.y)*this.size.x+t.x|0]=i,e)&&this.V(t)}getData(t){return pa(t,this.size)&&this.data[(0|t.y)*this.size.x+t.x|0]}update(){}H(){Rb||this.ka||Sb();var t=Va(this.i.add(q(0,this.size.y*this.scale.y)));(this.ka?Ha:C).drawImage(this.canvas,t.x,t.y,J*this.size.x*this.scale.x,J*this.size.y*this.scale.y)}qa(){this.sa(!0);for(let i=this.size.x;i--;)for(let t=this.size.y;t--;)this.V(q(i,t),!1);this.ra()}sa(t=!1){this.Ga=[B,C,E,I,J],B=this.canvas,C=this.context,E=this.size.multiply(this.s.size),I=this.size.scale(.5),J=this.s.size.x,t&&(B.width=E.x,B.height=E.y),this.context.imageSmoothingEnabled=!Ta,Tb()}ra(){Sb(!0),[B,C,E,I,J]=this.Ga}V(t,i=!0){var e=this.s.size;i&&(i=t.multiply(e),this.context.clearRect(i.x,this.canvas.height-i.y,e.x,-e.y)),null!=(i=this.getData(t)).aa&&Ga(t=this.i.add(t).add(q(.5)),q(1),Oa(i.aa,e,this.s.$),i.color,i.direction*g/2,i.o)}}function Ub(i){var e="number"==typeof i.W?ea(i.W/2):q(t(-.5,.5),t(-.5,.5)).multiply(i.W).rotate(i.angle);let a=t(i.na,-i.na);i.Y||(e=i.i.add(e),a+=i.angle);const s=i.O;var h=(c=i=>i+i*t(s,-s))(i.Ea),n=c(i.Z),r=c(i.Ha),o=c(i.speed),c=c(i.wa)*(2*Math.floor(t(2,0))-1),u=t(i.ga,-i.ga),l=ja(i.S,i.T,i.pa),b=ja(i.da,i.ea,i.pa),u=i.Y?u:i.angle+u;(e=new Vb(e,i.s,a,l,b,h,n,r,i.G,i.J,i.I,i.Y&&i,i.Da)).g=da(q(),u,o),e.R=c,e.G=i.G,e.m=i.m,e.K=i.K,e.u=i.u,e.X=i.X,e.B=i.B,e.L=i.L,e.P=i.P,e.o=!!Math.floor(t(2,0)),i.oa&&i.oa(e)}class Wb extends wa{constructor(t,i,e=0,a=0,s=100,h=g,n,r=new w,o=new w,c=new w(1,1,1,0),u=new w(1,1,1,0),l=.5,b=.1,f=1,d=.1,y=.05,x=1,v=1,m=0,p=g,S=.1,z=.2,G=!1,M=!1,B=!0,D=M?1e9:0,F=!1){super(t,q(),n,i,void 0,D),this.W=e,this.ia=a,this.ha=s,this.ga=h,this.S=r,this.T=o,this.da=c,this.ea=u,this.pa=B,this.Ea=l,this.Z=b,this.Ha=f,this.speed=d,this.wa=y,this.m=x,this.K=v,this.B=m,this.na=p,this.G=S,this.O=z,this.L=G,this.J=M,this.Y=F,this.I=0,this.oa=this.Da=void 0,this.F=0}update(){if(this.parent&&super.update(),!this.ia||x-this.ua<=this.ia){if(this.ha*Xb){var t=1/this.ha/Xb;for(this.F+=Yb;0<this.F;this.F-=t)Ub(this)}}else va(this)}H(){}}class Vb extends wa{constructor(t,i,e,a,s,h,n,r,o,c,u,l,b){super(t,q(),i,e),this.N=a,this.M=s.l(a),this.Aa=h,this.Z=n,this.Ia=r-n,this.G=o,this.J=c,this.I=u,this.D=l,this.fa=b,this.ba=!1}H(){var t=Math.min((x-this.ua)/this.Aa,1),i=q(this.Z+t*this.Ia),e=this.G/2,e=new w(this.N.r+t*this.M.r,this.N.j+t*this.M.j,this.N.b+t*this.M.b,(this.N.a+t*this.M.a)*(t<e?t/e:1-e<t?(1-t)/e:1));this.J&&bb(!0);let a=this.i;var s,h,n=this.angle;this.D&&(a=this.D.i.add(a.rotate(-this.D.angle)),n+=this.D.angle),this.I?(s=this.g,(n=(s=this.D?s.rotate(-this.D.angle):s).length())&&(s=s.scale(1/n),h=n*this.I,i.y=Math.max(i.x,h),n=s.angle(),Ga(a.add(s.multiply(q(0,-h/2))),i,this.s,e,n,this.o))):Ga(a,i,this.s,e,n,this.o),this.J&&bb(),1==t&&(this.color=e,this.size=i,this.fa&&this.fa(this),this.A=1)}}let U,G,Zb,$b,ac,bc,V,cc,W,cb,dc;function ec(){var t;Sa&&!F&&(U=document.createElement("canvas"),G=U.getContext("webgl2"),Rb&&document.body.appendChild(U),t=G.createProgram(),G.attachShader(t,ic("#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;}",35633)),G.attachShader(t,ic("#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;}",35632)),G.linkProgram(t),Zb=t,t=new ArrayBuffer(44e4),V=new Float32Array(t),cc=new Uint32Array(t),ac=G.createBuffer(),bc=G.createBuffer(),t=new Float32Array([W=0,0,1,0,0,1,1,1]),G.bindBuffer(34962,bc),G.bufferData(34962,t,35044))}function Tb(){var r,t,i;Sa&&!F&&(G.viewport(0,0,U.width=B.width,U.height=B.height),G.clear(16384),G.useProgram(Zb),G.activeTexture(33984),G.bindTexture(3553,$b=Na[0].ja),r=cb=dc=0,t=(t,i,e,a)=>{t=G.getAttribLocation(Zb,t);var s=e&&44,h=e&&1,n=1==e;G.enableVertexAttribArray(t),G.vertexAttribPointer(t,a,i,n,s,r),G.vertexAttribDivisor(t,h),r+=a*e},G.bindBuffer(34962,bc),t("g",5126,0,2),G.bindBuffer(34962,ac),G.bufferData(34962,44e4,35048),t("p",5126,4,4),t("u",5126,4,4),t("c",5121,1,4),t("a",5121,1,4),t("r",5126,4,1),t=q(2*J).U(E),i=q(-1).l(I.multiply(t)),G.uniformMatrix4fv(G.getUniformLocation(Zb,"m"),!1,[t.x,0,0,0,0,t.y,0,0,1,1,1,1,i.x,i.y,0,0]))}function Wa(t){F||t==$b||(jc(),G.bindTexture(3553,$b=t))}function ic(t,i){return i=G.createShader(i),G.shaderSource(i,t),G.compileShader(i),i}function jc(){var t;W&&(t=dc?1:771,G.blendFuncSeparate(770,t,1,t),G.enable(3042),G.bufferSubData(34962,0,V),G.drawArraysInstanced(5,0,4,W),W=0,dc=cb)}function Sb(t=!1){var i=C;Sa&&(W||t)&&(jc(),Rb&&!t||i.drawImage(U,0,0))}function Xa(t,i,e,a,s,h,n,r,o,c,u=0){(1e4<=W||dc!=cb)&&jc();var l=11*W;V[l++]=t,V[l++]=i,V[l++]=e,V[l++]=a,V[l++]=h,V[l++]=n,V[l++]=r,V[l++]=o,cc[l++]=c,cc[l++]=u,V[+l]=s,W++}const Yb=1/60;let y=[],Ea=[],kc=0,x=0,Fb=!1,lc=0,X=0;const mc=[],nc=[];function oc(){Ea=y.filter(t=>t.ca);for(const t of y)t.parent||(function t(i){if(!i.A){i.update();for(const e of i.children)t(e)}}(t),ua(t));y=y.filter(t=>!t.A)}let I=q(),J=32,pc=q(1920,1080),qc=q(),Ta=!0,eb="arial",F=!1,Sa=!0,Rb=!0,Pa=q(16),Ua=.5,Da=!0,xa=1,ya=1,za=1,Aa=0,Ba=.8,z=1,Ca=0,Xb=1,mb=!1,Cb=!(mb=!1),qb=!0,N=!1,ub=N=N=!1,Bb=!0,S=99,Hb=.3,Db=!0,rc=.3,Jb=40,Kb=.7;function sc(){var t=rc;rc=t,Db&&!F&&Ib&&(Ib.gain.value=t)}let Y;qb=N=!1;const tc=new Eb([1,.5]);!function(s,h,n,r,i=["tiles.png"]){function o(t=0){var i=t-lc;if(lc=t,X+=Fb?0:i,X=Math.min(X,50),c(),Fb){for(const e of y)e.parent||ua(e);kb(),h(),ob()}else{for(t=0,X<0&&-9<X&&(t=X,X=0);0<=X;X-=1e3/60)x=kc++/60,kb(),s(),mc.forEach(t=>t()),oc(),h(),ob();X+=t}if(!F){E=q(B.width,B.height),C.imageSmoothingEnabled=!Ta,Tb(),n(),y.sort((t,i)=>t.P-i.P);for(const a of y)a.A||a.H();r(),nc.forEach(t=>t()),Gb(),Sb()}requestAnimationFrame(o)}function c(){var t,i;F||(qc.x?(B.width=qc.x,B.height=qc.y,t=innerWidth/innerHeight,i=B.width/B.height,(U||B).style.width=B.style.width=D.style.width=t<i?"100%":"",(U||B).style.height=B.style.height=D.style.height=t<i?"":"100%"):(B.width=Math.min(innerWidth,pc.x),B.height=Math.min(innerHeight,pc.y)),D.width=B.width,D.height=B.height,E=q(B.width,B.height))}function e(){{T=q(32,16);for(var i=(Ob=[]).length=na(T);i--;)Ob[i]=0;i=q();var e=new Qb(i,T),a=Na[0].image,s=(C.drawImage(a,0,0),C.getImageData(0,0,a.width,a.height).data),h,n,r;for(i.x=T.x;i.x--;)for(i.y=T.y;i.y--;)s[4*(i.x+a.width*(15+T.y-i.y))]&&(h=Math.floor(t(4,0)),n=Math.floor(t(2,0)),r=ja(),e.setData(i,new Pb(1,h,n,r)),pa(i,T))&&(Ob[(0|i.y)*T.x+i.x|0]=1);e.qa(),I=q(16,8),Ca=-.01,(Y=new Wb(q(16,9),0,1,0,500,g,Oa(0,16),new w(1,1,1),new w(0,0,0),new w(0,0,0,0),new w(0,0,0,0),2,.2,.2,.1,.05,.99,1,1,g,.05,.5,1,1)).u=.3,Y.I=2}o()}F?e():(document.body.style.cssText="margin:0;overflow:hidden;background:#000;user-select:none;-webkit-user-select:none;"+(N?"touch-action:none;-webkit-touch-callout:none":""),document.body.appendChild(B=document.createElement("canvas")),C=B.getContext("2d"),pb(),Db&&!F&&(R=new AudioContext,(Ib=R.createGain()).connect(R.destination),sc()),ec(),document.body.appendChild(D=document.createElement("canvas")),Ha=D.getContext("2d"),(U||B).style.cssText=B.style.cssText=D.style.cssText="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)",c(),i=i.map((e,a)=>new Promise(t=>{const i=new Image;i.onerror=i.onload=()=>{Na[a]=new Ra(i),t()},i.src=e})),Promise.all(i).then(e))}(function(){K[0]&&2&K[0][0]&&(tc.play(gb),Y.S=new w,Y.T=ja(),Y.da=Y.S.scale(1,0),Y.ea=Y.T.scale(1,0)),hb.x&&(Y.i=gb)},function(){},function(){Ga(q(16,8),q(20,14),void 0,new w(.6,.6,.6),0,!1,void 0,0)},function(){db()});
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -13,6 +13,12 @@ setShowSplashScreen(true);
|
|
|
13
13
|
|
|
14
14
|
let spriteAtlas, score, deaths;
|
|
15
15
|
|
|
16
|
+
// enable touch gamepad on touch devices
|
|
17
|
+
touchGamepadEnable = true;
|
|
18
|
+
|
|
19
|
+
// fix texture bleeding by shrinking tile slightly
|
|
20
|
+
tileFixBleedScale = .1;
|
|
21
|
+
|
|
16
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
17
23
|
function gameInit()
|
|
18
24
|
{
|
|
@@ -30,10 +36,6 @@ function gameInit()
|
|
|
30
36
|
gun: tile(2,8),
|
|
31
37
|
grenade: tile(3,8),
|
|
32
38
|
};
|
|
33
|
-
|
|
34
|
-
// enable touch gamepad on touch devices
|
|
35
|
-
touchGamepadEnable = true;
|
|
36
|
-
|
|
37
39
|
// setup level
|
|
38
40
|
buildLevel();
|
|
39
41
|
|
|
@@ -31,6 +31,7 @@ class Character extends GameObject
|
|
|
31
31
|
this.renderOrder = 10;
|
|
32
32
|
this.walkCyclePercent = 0;
|
|
33
33
|
this.health = 1;
|
|
34
|
+
this.climbingLadder = false;
|
|
34
35
|
this.setCollision(true,false);
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -102,9 +103,9 @@ class Character extends GameObject
|
|
|
102
103
|
touchingLadder ||= collisionData == tileType_ladder;
|
|
103
104
|
}
|
|
104
105
|
if (!touchingLadder)
|
|
105
|
-
this.climbingLadder =
|
|
106
|
+
this.climbingLadder = false;
|
|
106
107
|
else if (moveInput.y)
|
|
107
|
-
this.climbingLadder =
|
|
108
|
+
this.climbingLadder = true;
|
|
108
109
|
|
|
109
110
|
if (this.weapon) // update weapon trigger
|
|
110
111
|
this.weapon.triggerIsDown = this.holdingShoot && !this.dodgeTimer.active();
|
|
@@ -236,10 +237,10 @@ class Character extends GameObject
|
|
|
236
237
|
damage(damage, damagingObject)
|
|
237
238
|
{
|
|
238
239
|
if (this.isDead() || this.getAliveTime() < 1 || this.dodgeTimer.active())
|
|
239
|
-
return;
|
|
240
|
+
return 0;
|
|
240
241
|
|
|
241
242
|
makeBlood(damagingObject ? damagingObject.pos : this.pos);
|
|
242
|
-
super.damage(damage, damagingObject);
|
|
243
|
+
return super.damage(damage, damagingObject);
|
|
243
244
|
}
|
|
244
245
|
|
|
245
246
|
kill(damagingObject)
|
|
@@ -251,31 +252,31 @@ class Character extends GameObject
|
|
|
251
252
|
sound_die.play(this.pos);
|
|
252
253
|
|
|
253
254
|
this.health = 0;
|
|
254
|
-
if (this.weapon)
|
|
255
|
-
this.weapon.destroy();
|
|
256
255
|
this.deadTimer.set();
|
|
257
256
|
this.size = this.size.scale(.5);
|
|
258
257
|
const fallDirection = damagingObject ? sign(damagingObject.velocity.x) : randSign();
|
|
259
258
|
this.angleVelocity = fallDirection*rand(.22,.14);
|
|
260
259
|
this.angleDamping = .9;
|
|
261
260
|
this.renderOrder = -1; // move to back layer
|
|
261
|
+
if (this.weapon)
|
|
262
|
+
this.weapon.destroy();
|
|
262
263
|
}
|
|
263
264
|
|
|
264
265
|
collideWithTile(data, pos)
|
|
265
266
|
{
|
|
266
267
|
if (!data)
|
|
267
|
-
return;
|
|
268
|
+
return false;
|
|
268
269
|
|
|
269
270
|
if (data == tileType_ladder)
|
|
270
271
|
{
|
|
271
272
|
// handle ladder collisions
|
|
272
273
|
if (pos.y + 1 > this.lastPos.y - this.size.y/2)
|
|
273
|
-
return;
|
|
274
|
+
return false;
|
|
274
275
|
|
|
275
276
|
if (getTileCollisionData(pos.add(vec2(0,1))) // above
|
|
276
277
|
&& !getTileCollisionData(pos.add(vec2(1,0))) // left
|
|
277
278
|
&& !getTileCollisionData(pos.add(vec2(1,0)))) // right
|
|
278
|
-
return; // dont collide if something above it and nothing to left or right
|
|
279
|
+
return false; // dont collide if something above it and nothing to left or right
|
|
279
280
|
|
|
280
281
|
// allow standing on top of ladders
|
|
281
282
|
return !this.climbingLadder;
|
|
@@ -287,9 +288,9 @@ class Character extends GameObject
|
|
|
287
288
|
{
|
|
288
289
|
// break blocks above
|
|
289
290
|
this.velocity.y = 0;
|
|
290
|
-
return;
|
|
291
|
+
return false;
|
|
291
292
|
}
|
|
292
293
|
|
|
293
|
-
return
|
|
294
|
+
return true;
|
|
294
295
|
}
|
|
295
296
|
}
|
|
@@ -129,13 +129,13 @@ function destroyTile(pos, makeSound = 1, cleanNeighbors = 1)
|
|
|
129
129
|
// destroy tile
|
|
130
130
|
const tileType = getTileCollisionData(pos);
|
|
131
131
|
if (!tileType)
|
|
132
|
-
return
|
|
132
|
+
return true;
|
|
133
133
|
|
|
134
134
|
const tileLayer = tileLayers[foregroundLayerIndex];
|
|
135
135
|
const centerPos = pos.add(vec2(.5));
|
|
136
136
|
const layerData = tileLayer.getData(pos);
|
|
137
137
|
if (!layerData || tileType == tileType_solid)
|
|
138
|
-
return;
|
|
138
|
+
return false;
|
|
139
139
|
|
|
140
140
|
// create effects
|
|
141
141
|
makeDebris(centerPos, layerData.color.mutate());
|
|
@@ -144,7 +144,6 @@ function destroyTile(pos, makeSound = 1, cleanNeighbors = 1)
|
|
|
144
144
|
// set and clear tile
|
|
145
145
|
tileLayer.setData(pos, new TileLayerData, 1);
|
|
146
146
|
setTileCollisionData(pos, tileType_empty);
|
|
147
|
-
setTileData(pos, foregroundLayerIndex, 0);
|
|
148
147
|
|
|
149
148
|
// cleanup neighbors
|
|
150
149
|
if (cleanNeighbors)
|
|
@@ -154,7 +153,7 @@ function destroyTile(pos, makeSound = 1, cleanNeighbors = 1)
|
|
|
154
153
|
decorateTile(pos.add(vec2(i,j)));
|
|
155
154
|
}
|
|
156
155
|
|
|
157
|
-
return
|
|
156
|
+
return true;
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -12,16 +12,14 @@ const tileType_empty = 0;
|
|
|
12
12
|
const tileType_solid = 1;
|
|
13
13
|
const tileType_breakable = 2;
|
|
14
14
|
|
|
15
|
-
let player, playerStartPos,
|
|
16
|
-
let levelSize, levelColor, levelBackgroundColor, levelOutlineColor
|
|
17
|
-
|
|
18
|
-
const setTileData = (pos, layer, data)=>
|
|
19
|
-
pos.arrayCheck(tileCollisionSize) && (tileData[layer][(pos.y|0)*tileCollisionSize.x+pos.x|0] = data);
|
|
20
|
-
const getTileData = (pos, layer)=>
|
|
21
|
-
pos.arrayCheck(tileCollisionSize) ? tileData[layer][(pos.y|0)*tileCollisionSize.x+pos.x|0]: 0;
|
|
15
|
+
let player, playerStartPos, tileLayers, foregroundLayerIndex, sky;
|
|
16
|
+
let levelSize, levelColor, levelBackgroundColor, levelOutlineColor;
|
|
22
17
|
|
|
23
18
|
function buildLevel()
|
|
24
19
|
{
|
|
20
|
+
// destroy all objects
|
|
21
|
+
engineObjectsDestroy();
|
|
22
|
+
|
|
25
23
|
// create the level
|
|
26
24
|
levelColor = randColor(hsl(0,0,.2), hsl(0,0,.8));
|
|
27
25
|
levelBackgroundColor = levelColor.mutate().scale(.4,1);
|
|
@@ -34,20 +32,6 @@ function buildLevel()
|
|
|
34
32
|
// create parallax layers
|
|
35
33
|
for (let i=3; i--;)
|
|
36
34
|
new ParallaxLayer(i);
|
|
37
|
-
|
|
38
|
-
// apply decoration to all level tiles
|
|
39
|
-
const pos = vec2();
|
|
40
|
-
const layerCount = tileLayers.length;
|
|
41
|
-
for (let layer=layerCount; layer--;)
|
|
42
|
-
for (pos.x=levelSize.x; pos.x--;)
|
|
43
|
-
for (pos.y=levelSize.y; pos.y--;)
|
|
44
|
-
decorateTile(pos, layer);
|
|
45
|
-
|
|
46
|
-
// warm up level
|
|
47
|
-
warmup = 1;
|
|
48
|
-
for (let i = 500; i--;)
|
|
49
|
-
engineObjectsUpdate();
|
|
50
|
-
warmup = 0;
|
|
51
35
|
|
|
52
36
|
// spawn player
|
|
53
37
|
player = new Player(playerStartPos);
|
|
@@ -56,11 +40,9 @@ function buildLevel()
|
|
|
56
40
|
function loadLevel(level=0)
|
|
57
41
|
{
|
|
58
42
|
// load level data from an exported Tiled js file
|
|
59
|
-
const
|
|
60
|
-
const tileMapData = TileMaps[dataName];
|
|
43
|
+
const tileMapData = TileMaps['gameLevelData'];
|
|
61
44
|
levelSize = vec2(tileMapData.width, tileMapData.height);
|
|
62
45
|
initTileCollision(levelSize);
|
|
63
|
-
engineObjectsDestroy();
|
|
64
46
|
|
|
65
47
|
// create table for tiles in the level tilemap
|
|
66
48
|
const tileLookup =
|
|
@@ -76,7 +58,6 @@ function loadLevel(level=0)
|
|
|
76
58
|
}
|
|
77
59
|
|
|
78
60
|
// set all level data tiles
|
|
79
|
-
tileData = [];
|
|
80
61
|
tileLayers = [];
|
|
81
62
|
playerStartPos = vec2(1, levelSize.y);
|
|
82
63
|
const layerCount = tileMapData.layers.length;
|
|
@@ -87,7 +68,6 @@ function loadLevel(level=0)
|
|
|
87
68
|
const tileLayer = new TileLayer(vec2(), levelSize, tile(0,16,1));
|
|
88
69
|
tileLayer.renderOrder = -1e3+layer;
|
|
89
70
|
tileLayers[layer] = tileLayer;
|
|
90
|
-
tileData[layer] = [];
|
|
91
71
|
|
|
92
72
|
for (let x=levelSize.x; x--;)
|
|
93
73
|
for (let y=levelSize.y; y--;)
|
|
@@ -109,10 +89,7 @@ function loadLevel(level=0)
|
|
|
109
89
|
new Coin(objectPos);
|
|
110
90
|
continue;
|
|
111
91
|
}
|
|
112
|
-
|
|
113
|
-
// set the tile data
|
|
114
|
-
setTileData(pos, layer, tile);
|
|
115
|
-
|
|
92
|
+
|
|
116
93
|
// get tile type for special tiles
|
|
117
94
|
let tileType = tileType_empty;
|
|
118
95
|
if (tile > 0)
|
|
@@ -144,6 +121,13 @@ function loadLevel(level=0)
|
|
|
144
121
|
}
|
|
145
122
|
tileLayer.redraw();
|
|
146
123
|
}
|
|
124
|
+
|
|
125
|
+
// apply decoration to all level tiles
|
|
126
|
+
const pos = vec2();
|
|
127
|
+
for (let layer=layerCount; layer--;)
|
|
128
|
+
for (pos.x=levelSize.x; pos.x--;)
|
|
129
|
+
for (pos.y=levelSize.y; pos.y--;)
|
|
130
|
+
decorateTile(pos, layer);
|
|
147
131
|
}
|
|
148
132
|
|
|
149
133
|
function decorateTile(pos, layer=1)
|
|
@@ -181,11 +165,11 @@ function decorateTile(pos, layer=1)
|
|
|
181
165
|
else
|
|
182
166
|
{
|
|
183
167
|
// make round corners
|
|
184
|
-
for (let i=4;i--;)
|
|
168
|
+
for (let i=4; i--;)
|
|
185
169
|
{
|
|
186
170
|
// check corner neighbors
|
|
187
|
-
const neighborTileDataA =
|
|
188
|
-
const neighborTileDataB =
|
|
171
|
+
const neighborTileDataA = tileLayer.getData(pos.add(vec2().setDirection(i))).tile;
|
|
172
|
+
const neighborTileDataB = tileLayer.getData(pos.add(vec2().setDirection((i+1)%4))).tile;
|
|
189
173
|
if (neighborTileDataA > 0 || neighborTileDataB > 0)
|
|
190
174
|
continue;
|
|
191
175
|
|
|
@@ -23,17 +23,14 @@ class GameObject extends EngineObject
|
|
|
23
23
|
super.update();
|
|
24
24
|
|
|
25
25
|
// flash white when damaged
|
|
26
|
+
let brightness = 0;
|
|
26
27
|
if (!this.isDead() && this.damageTimer.isSet())
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.additiveColor = hsl(0,0,a,0);
|
|
30
|
-
}
|
|
31
|
-
else
|
|
32
|
-
this.additiveColor = hsl(0,0,0,0);
|
|
28
|
+
brightness = .5*percent(this.damageTimer, .15, 0);
|
|
29
|
+
this.additiveColor = hsl(0,0,brightness,0);
|
|
33
30
|
|
|
34
31
|
// kill if below level
|
|
35
32
|
if (!this.isDead() && this.pos.y < -9)
|
|
36
|
-
|
|
33
|
+
this.kill();
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
damage(damage, damagingObject)
|
|
@@ -104,10 +101,10 @@ class Coin extends EngineObject
|
|
|
104
101
|
drawTile(this.pos, vec2(.5+.5*Math.sin(t*2*PI), 1), this.tileInfo, this.color);
|
|
105
102
|
}
|
|
106
103
|
|
|
107
|
-
update(
|
|
104
|
+
update()
|
|
108
105
|
{
|
|
109
106
|
if (!player)
|
|
110
|
-
|
|
107
|
+
return;
|
|
111
108
|
|
|
112
109
|
// check if player in range
|
|
113
110
|
const d = this.pos.distanceSquared(player.pos);
|
|
@@ -145,9 +142,7 @@ class Enemy extends GameObject
|
|
|
145
142
|
|
|
146
143
|
// jump around randomly
|
|
147
144
|
if (this.groundObject && rand() < .01 && this.pos.distance(player.pos) < 20)
|
|
148
|
-
{
|
|
149
145
|
this.velocity = vec2(rand(.1,-.1), rand(.4,.2));
|
|
150
|
-
}
|
|
151
146
|
|
|
152
147
|
// damage player if touching
|
|
153
148
|
if (isOverlapping(this.pos, this.size, player.pos, player.size))
|
|
@@ -344,17 +339,17 @@ class Bullet extends EngineObject
|
|
|
344
339
|
}
|
|
345
340
|
|
|
346
341
|
this.kill();
|
|
347
|
-
return
|
|
342
|
+
return true;
|
|
348
343
|
}
|
|
349
344
|
|
|
350
345
|
collideWithTile(data, pos)
|
|
351
346
|
{
|
|
352
347
|
if (data <= 0)
|
|
353
|
-
return
|
|
348
|
+
return false;
|
|
354
349
|
|
|
355
350
|
destroyTile(pos);
|
|
356
351
|
this.kill();
|
|
357
|
-
return
|
|
352
|
+
return true;
|
|
358
353
|
}
|
|
359
354
|
|
|
360
355
|
kill()
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
<!DOCTYPE html><head><title>Little JS Starter Project</title></head><script>const h=Math.PI;function m(t,i=0,a=1){return t<i?i:a<t?a:t}function aa(t,i,a){return a-i?m((t-i)/(a-i)):0}function ba(t,i,a,e){return 2*Math.abs(t.x-a.x)<i.x+e.x&&2*Math.abs(t.y-a.y)<i.y+e.y}function n(t=1,i=0){return i+Math.random()*(t-i)}function ca(t=1){return fa(new p,n(2*h),t)}function ha(t=1){return 0<t?ca(t*n(0/t,1)**.5):new p}function ia(t=new v,i=new v(0,0,0,1),a){return a?t.ha(i,n()):new v(n(t.r,i.r),n(t.j,i.j),n(t.b,i.b),n(t.a,i.a))}function x(t=0,i){return null==t.x?new p(t,null==i?t:i):new p(t.x,t.y)}function fa(t,i=0,a=1){return t.x=a*Math.sin(i),t.y=a*Math.cos(i),t}function ja(t){var i=t.length();return 1<i?t.scale(1/i):t}function ka(t,i){return 0<=t.x&&0<=t.y&&t.x<i.x&&t.y<i.y}class p{constructor(t=0,i=0){this.x=t,this.y=i}M(){return new p(this.x,this.y)}add(t){return new p(this.x+t.x,this.y+t.y)}u(t){return new p(this.x-t.x,this.y-t.y)}multiply(t){return new p(this.x*t.x,this.y*t.y)}ca(t){return new p(this.x/t.x,this.y/t.y)}scale(t){return new p(this.x*t,this.y*t)}length(){return(this.x**2+this.y**2)**.5}normalize(t=1){var i=this.length();return i?this.scale(t/i):new p(0,t)}angle(){return Math.atan2(this.x,this.y)}rotate(t){var i=Math.cos(t);return t=Math.sin(t),new p(this.x*i-this.y*t,this.x*t+this.y*i)}direction(){return Math.abs(this.x)>Math.abs(this.y)?this.x<0?3:1:this.y<0?2:0}floor(){return new p(Math.floor(this.x),Math.floor(this.y))}ha(t,i){return this.add(t.u(this).scale(m(i)))}toString(){}}function la(t=1){var i=new v,a=t<.5?+t:t+0-0*t,e=(t,i,a)=>(a=(a%1+1)%1)<1/6?t+6*(i-t)*a:a<.5?i:a<2/3?t+(i-t)*(2/3-a)*6:t;return i.r=e(t=2*t-a,a,1/3),i.j=e(t,a,0),i.b=e(t,a,-1/3),i.a=1,i}function ma(t){return(255*m(t.r)|0)+((255*m(t.j)|0)<<8)+((255*m(t.b)|0)<<16)+((255*m(t.a)|0)<<24)}class v{constructor(t=1,i=1,a=1,e=1){this.r=t,this.j=i,this.b=a,this.a=e}M(){return new v(this.r,this.j,this.b,this.a)}add(t){return new v(this.r+t.r,this.j+t.j,this.b+t.b,this.a+t.a)}u(t){return new v(this.r-t.r,this.j-t.j,this.b-t.b,this.a-t.a)}multiply(t){return new v(this.r*t.r,this.j*t.j,this.b*t.b,this.a*t.a)}ca(t){return new v(this.r/t.r,this.j/t.j,this.b/t.b,this.a/t.a)}scale(t,i=t){return new v(this.r*t,this.j*t,this.b*t,this.a*i)}ha(t,i){return this.add(t.u(this).scale(m(i)))}toString(t=1){var i=t=>((t=255*t|0)<16?"0":"")+t.toString(16);return"#"+i(this.r)+i(this.j)+i(this.b)+(t?i(this.a):"")}}let y=x(),z=32,na=x(1920,1200),oa=x(),pa=x(16),qa=0,ra=x(640,80);function sa(t){if(!t.v){t.v=1,t.parent&&t.parent.removeChild(t);for(const i of t.children)sa(i,i.parent=0)}}class ta{constructor(t=x(),i=x(1),a,e=0,s,h=0){this.i=t.M(),this.size=i,this.pa,this.l=a,this.angle=e,this.color=s,this.ma,this.I=this.m=this.h=1,this.s=0,this.W=.8,this.A=1,this.O=h,this.g=x(),this.R=0,this.ka=ua,this.children=[],this.J=1,A.push(this)}update(){var t=this.parent;if(t)this.i=this.Ca.multiply(x(t.o?-1:1,1)).rotate(-t.angle).add(t.i),this.angle=(t.o?-1:1)*this.Ba+t.angle;else if(this.g.x=m(this.g.x,-1,1),this.g.y=m(this.g.y,-1,1),t=this.i.M(),this.g.y+=qa*this.A,this.i.x+=this.g.x*=this.m,this.i.y+=this.g.y*=this.m,this.angle+=this.R*=this.I,this.h){var i,a,e,s,h,n,r=this.g.y<0;if(this.B&&(i=this.B.g?this.B.g.x:0,this.g.x=i+(this.g.x-i)*this.W,this.B=0),this.oa)for(var o of va)!this.sa&&!o.sa||o.v||o.parent||o==this||ba(this.i,this.size,o.i,o.size)&&(ba(t,this.size,o.i,o.size)?(i=(a=(i=t.u(o.i)).length())<.01?ca(.001):i.scale(.001/a),this.g=this.g.add(i),o.h&&(o.g=o.g.u(i))):(a=this.size.add(o.size),e=2*(t.y-o.i.y)>a.y+qa,s=2*Math.abs(t.y-o.i.y)<a.y,h=2*Math.abs(t.x-o.i.x)<a.x,i=Math.max(this.s,o.s),!e&&!h&&s||(this.i.y=o.i.y+(a.y/2+.001)*Math.sign(t.y-o.i.y),o.B&&r||!o.h?(r&&(this.B=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+m(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+m(i)*(n-h))),!e&&s&&(this.i.x=o.i.x+(a.x/2+.001)*Math.sign(t.x-o.i.x),o.h?(a=(this.h*this.g.x+o.h*o.g.x)/(this.h+o.h),e=o.g.x*(o.h-this.h)/(this.h+o.h)+2*this.g.x*this.h/(this.h+o.h),this.g.x=a+m(i)*(this.g.x*(this.h-o.h)/(this.h+o.h)+2*o.g.x*o.h/(this.h+o.h)-a),o.g.x=a+m(i)*(e-a)):this.g.x*=-i)));this.J&&wa(this.i,this.size,this)&&!wa(t,this.size,this)&&(o=wa(x(this.i.x,t.y),this.size,this),!wa(x(t.x,this.i.y),this.size,this)&&o||(this.B=r,this.g.y*=-this.s,(r=(t.y-this.size.y/2|0)-(t.y-this.size.y/2))<0&&r>this.m*this.g.y+qa*this.A&&(this.g.y=this.m?(r-qa*this.A)/this.m:0),this.i.y=t.y),o)&&(this.i.x=t.x,this.g.x*=-this.s)}}D(){B(this.i,this.pa||this.size,this.l,this.color,this.angle,this.o,this.ma)}removeChild(t){t.parent==this&&this.children.includes(t),this.children.splice(this.children.indexOf(t),1),t.parent=0}toString(){}}let D,G,H,xa,J=x(),K=[];function Da(t=x(),i=pa,a=0){var e;return null==i.x&&(i=x(i)),null==t.x&&(t=x(t%(e=K[a].size.x/i.x|0)*i.x,(t/e|0)*i.y)),new Ea(t,i,a)}class Ea{constructor(t=x(),i=pa,a=0){this.i=t,this.size=i,this.P=a}offset(t){return new Ea(this.i.add(t),this.size,this.P)}}class Fa{constructor(t){this.image=t,this.size=x(t.width,t.height);var i=L.createTexture();L.bindTexture(3553,i),t&&t.width&&L.texImage2D(3553,0,6408,6408,5121,t),L.texParameteri(3553,10241,9728),L.texParameteri(3553,10240,9728),L.texParameteri(3553,10242,33071),L.texParameteri(3553,10243,33071),this.ga=i,this.qa=x(.3).ca(this.size)}}function Ga(){var t=Ha;return new p((t.x-J.x/2+.5)/z+y.x,(t.y-J.y/2+.5)/-z+y.y)}function Ia(t){return new p((t.x-y.x)*z+J.x/2-.5,(t.y-y.y)*-z+J.y/2-.5)}function B(t,i=x(1),h,n=new v,a=0,e,s=new v(0,0,0,0),r=1){var o,l,c,u,y;r?h?(r=K[h.P],o=h.size.x/r.size.x,l=h.size.y/r.size.y,c=h.i.x/r.size.x,u=h.i.y/r.size.y,y=r.qa,Ja(r.ga),Ka(t.x,t.y,e?-i.x:i.x,i.y,a,c+y.x,u+y.y,c-y.x+o,u-y.y+l,ma(n),ma(s))):Ka(t.x,t.y,i.x,i.y,a,0,0,0,0,0,ma(n)):La(t,i,a,e,t=>{var i,a,e,s;h?(i=h.i.x+.3,a=h.i.y+.3,e=h.size.x-.6,s=h.size.y-.6,t.globalAlpha=n.a,t.drawImage(K[h.P].image,i,a,e,s,-.5,-.5,1,1)):(t.fillStyle=n,t.fillRect(-.5,-.5,1,1))})}function La(t,i,a,e,s){var h=G;t=Ia(t),i=i.scale(z),h.save(),h.translate(t.x+.5,t.y+.5),h.rotate(a),h.scale(e?-i.x:i.x,i.y),s(h),h.restore()}function Ma(t,i,a=1,e=new v,s=0,h=new v(0,0,0),n="center"){var r=xa;r.fillStyle=e,r.lineWidth=s,r.strokeStyle=h,r.textAlign=n,r.font=a+"px arial",r.textBaseline="middle",r.lineJoin="round",i=i.M(),(t+"").split("\n").forEach(t=>{s&&r.strokeText(t,i.x,i.y),r.fillText(t,i.x,i.y),i.y+=a})}function Na(t,i=0){return M[i]&&1&M[i][t]}let Oa=x(),Ha=x();function N(t,i=0){return Na(t,i+1)}let M=[[]];function Pa(){for(const t of M)for(const i in t)t[i]&=1}function Qa(t){return 87==t?38:83==t?40:65==t?37:68==t?39:t}onkeydown=t=>{t.repeat||(M[0][Qa(t.which)]=3)},onkeyup=t=>{M[0][Qa(t.which)]=4},onmousedown=t=>{M[0][t.button]=3,onmousemove(t),t.button&&t.preventDefault()},onmouseup=t=>M[0][t.button]=2&M[0][t.button]|4,onmousemove=t=>{var i;return t=D?(i=D.getBoundingClientRect(),x(D.width,D.height).multiply(x(aa(t.x,i.left,i.right),aa(t.y,i.top,i.bottom)))):x(),Ha=t},onwheel=t=>t.ctrlKey||Math.sign(t.deltaY),oncontextmenu=()=>!1;const Ra=[];function Sa(){if(navigator&&navigator.getGamepads&&document.hasFocus()){var i=navigator.getGamepads();for(let t=i.length;t--;){var a=i[t],e=M[t+1]||(M[t+1]=[]),s=Ra[t]||(Ra[t]=[]);if(a){var h=t=>.3<t?aa(t,.3,.8):t<-.3?-aa(-t,.3,.8):0;for(let t=0;t<a.axes.length-1;t+=2)s[t>>1]=ja(x(h(a.axes[t]),h(-a.axes[t+1])));for(h=a.buttons.length;h--;)e[h]=a.buttons[h].pressed?1+2*!N(h,t):4*N(h,t);(a=x(N(15,t)-N(14,t),N(12,t)-N(13,t))).x**2+a.y**2&&(s[0]=ja(a))}}}}const Ta=void 0!==window.ontouchstart;if(Ta){let a,e=onmousedown,s=onmouseup;onmousedown=onmouseup=()=>0,ontouchstart=ontouchmove=ontouchend=t=>{t.button=0,O?O.resume():Ua([Va(0)]);var i=t.touches.length;return i?(t.x=t.touches[0].clientX,t.y=t.touches[0].clientY,(a?onmousemove:e)(t)):a&&s(t),a=i,document.hasFocus()&&t.preventDefault(),!0}}class Wa{constructor(){var t=[1,.5];this.wa=40,this.Aa=.7,this.N=0,t&&(this.N=t[1]||(t[1]=0),this.ja=[Va(...t)],this.sampleRate=44100)}play(t,i=1,a=1,e=1,s=0){if(this.ja){var h;if(t){if(h=this.wa){var r=y;if(h*h<(r=(y.x-t.x)**2+(r.y-t.y)**2))return;i*=aa(r**.5,h,h*this.Aa)}h=2*Ia(t).x/D.width-1}return this.source=Ua(this.ja,i,a+a*this.N*e*n(-1,1),h,s,this.sampleRate)}}stop(){this.source&&this.source.stop(),this.source=0}}let O;function Ua(t,i=1,a=1,e=0,s=0,h=44100){var n;if("running"==(O||=new AudioContext).state)return n=O.createBuffer(t.length,t[0].length,h),h=O.createBufferSource(),t.forEach((t,i)=>n.getChannelData(i).set(t)),h.buffer=n,h.playbackRate.value=a,h.loop=s,(t=O.createGain()).gain.value=.5*i,t.connect(O.destination),h.connect(new StereoPannerNode(O,{pan:m(e,-1,1)})).connect(t),h.start(),h;O.resume()}function Va(t=1,i=.05,a=220,e=0,s=0,r=.1,o=0,l=1,c=0,u=0,x=0,y=0,d=0,b=0,g=0,f=0,v=0,m=1,w=0,p=0){var M=2*h,z=c*=500*M/44100/44100,D=[];i=a*=(1+i*n(-1,1))*M/44100;let L=0,S=0,A=0,j=1,B=0,C=0,G=0,k,H;for(u*=500*M/44100**3,g*=M/44100,x*=M/44100,y*=44100,d=44100*d|0,H=(e=44100*e+9)+(w*=44100)+(s*=44100)+(r*=44100)+(v*=44100)|0;A<H;D[A++]=G)++C%(100*f|0)||(G=o?1<o?2<o?3<o?Math.sin((L%M)**3):Math.max(Math.min(Math.tan(L),1),-1):1-(2*L/M%2+2)%2:1-4*Math.abs(Math.round(L/M)-L/M):Math.sin(L),G=(d?1-p+p*Math.sin(M*A/d):1)*Math.sign(G)*Math.abs(G)**l*t*.5*(A<e?A/e:A<e+w?1-(A-e)/w*(1-m):A<e+w+s?m:A<H-v?(H-A-v)/r*m:0),G=v?G/2+(v>A?0:(A<H-v?1:(H-A)/v)*D[A-v|0]/2):G),k=(a+=c+=u)*Math.cos(g*S++),L+=k-k*b*(1-1e9*(Math.sin(A)+1)%2),j&&++j>y&&(a+=x,i+=x,j=0),!d||++B%d||(a=i,c=z,j||=1);return D}let Xa=[],Q=x();function wa(t,i=x(),a){var e=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=e;i<h;++i){var n=Xa[s*Q.x+i];if(n&&(!a||0<n))return 1}}class Ya{constructor(t,i=0,a=0,e=new v){this.Z=t,this.direction=i,this.o=a,this.color=e}clear(){this.Z=this.direction=this.o=0,color=new v}}function Za(t,i){var a=i.floor().add(t.i).add(x(.5));$a(t,a,t=>t.clearRect(-.5,-.5,1,1)),null!=(i=t.getData(i)).Z&&B(a,x(1),Da(i.Z,t.l.size,t.l.P),i.color,i.direction*h/2,i.o)}function $a(t,i,a){var e=x(1),s=t.context;s.save(),i=i.u(t.i).multiply(t.l.size),e=e.multiply(t.l.size),s.translate(i.x,t.canvas.height-i.y),s.rotate(0),s.scale(e.x,e.y),a(s),s.restore()}class ab extends ta{constructor(t,i=Q){var a=x(1);for(super(t,i,Da(),0,void 0,0),this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.scale=a,this.ra,this.data=[],t=this.size,t=Math.abs(t.x*t.y);t--;)this.data.push(new Ya)}setData(t,i,a){ka(t,this.size)&&(this.data[(0|t.y)*this.size.x+t.x|0]=i,a)&&Za(this,t)}getData(t){return ka(t,this.size)&&this.data[(0|t.y)*this.size.x+t.x|0]}update(){}D(){var t=Ia(this.i.add(x(0,this.size.y*this.scale.y)));(this.ra?xa:G).drawImage(this.canvas,t.x,t.y,z*this.size.x*this.scale.x,z*this.size.y*this.scale.y)}}function bb(t){var i=null!=t.U.x?x(n(-.5,.5),n(-.5,.5)).multiply(t.U).rotate(t.angle):ha(t.U/2);t.X||(i=t.i.add(i)),i=new cb(i,t.l,t.Ea);const a=t.N;var e=(o=t=>t+t*n(a,-a))(t.va),s=o(t.Y),h=o(t.ya),r=o(t.speed),o=o(t.na)*(2*Math.floor(n(2,0))-1),l=n(t.da,-t.da),c=ia(t.S,t.T,t.ia),u=ia(t.$,t.aa,t.ia),l=t.X?l:t.angle+l;i.L=c,i.K=u.u(c),i.g=fa(x(),l,r),i.R=o,i.ta=e,i.Y=s,i.za=h-s,i.V=t.V,i.m=t.m,i.I=t.I,i.s=t.s,i.W=t.W,i.A=t.A,i.J=t.J,i.H=t.H,i.O=t.O,i.G=t.G,i.o=Math.floor(n(2,0)),i.C=t.X&&t,i.ba=t.Da,t.ua&&t.ua(i)}class db extends ta{constructor(t,i,a=0,e=0,s=100,n=h,r,o=new v,l=new v,c=new v(1,1,1,0),u=new v(1,1,1,0),y=.5,d=.1,b=1,g=.1,f=.05,m=1,w=1,p=0,M,z=.1,D=.2,L,S,A=1,j=S?1e9:0,B){super(t,x(),r,i,void 0,j),this.U=a,this.fa=e,this.ea=s,this.da=n,this.S=o,this.T=l,this.$=c,this.aa=u,this.ia=A,this.va=y,this.Y=d,this.ya=b,this.speed=g,this.na=f,this.m=m,this.I=w,this.A=p,this.V=z,this.N=D,this.J=L,this.H=S,this.X=B,this.F=this.G=0}update(){if(this.parent&&super.update(),!this.fa||ua-this.ka<=this.fa){if(+this.ea){var t=1/this.ea;for(this.F+=eb;0<this.F;this.F-=t)bb(this)}}else sa(this)}D(){}}class cb extends ta{constructor(t,i,a){super(t,x(),i,a)}D(){var t=Math.min((ua-this.ka)/this.ta,1),i=x(this.Y+t*this.za),a=this.V/2,a=new v(this.L.r+t*this.K.r,this.L.j+t*this.K.j,this.L.b+t*this.K.b,(this.L.a+t*this.K.a)*(t<a?t/a:1-a<t?(1-t)/a:1));this.H&&fb(1);let e=this.i;var s,h,n=this.angle;this.C&&(e=this.C.i.add(e.rotate(-this.C.angle)),n+=this.C.angle),this.G?(s=this.g,n=(s=this.C?s.rotate(-this.C.angle):s).length(),s=s.scale(1/n),h=n*this.G,i.y=Math.max(i.x,h),n=s.angle(),B(e.add(s.multiply(x(0,-h/2))),i,this.l,a,n,this.o)):B(e,i,this.l,a,n,this.o),this.H&&fb(),1==t&&(this.color=a,this.size=i,this.ba&&this.ba(this),this.v=1)}}const gb=[];let hb=[],ib,jb;class kb{constructor(){(gb[this.id=0]=this).name="Example Medal",this.description="Welcome to LittleJS!",this.icon="🏆"}unlock(){this.la||(localStorage[ib+"_"+this.id]=this.la=1,hb.push(this),lb&&lb.Fa(this.id))}D(t=0){var i=xa,a=Math.min(ra.x,D.width),e=H.width-a;t*=-ra.y,i.save(),i.beginPath(),i.fillStyle=new v(.9,.9,.9),i.strokeStyle=new v(0,0,0),i.lineWidth=3,i.fill(i.rect(e,t,a,ra.y)),i.stroke(),i.clip(),a=x(e+15+25,t+ra.y/2),this.image?xa.drawImage(this.image,a.x-25,a.y-25,50,50):Ma(this.icon,a,35,new v(0,0,0)),e=x(e+50+30,t+28),Ma(this.name,e,38,new v(0,0,0),0,0,"left"),e.y+=32,Ma(this.description,e,24,new v(0,0,0),0,0,"left"),i.restore()}}function mb(){var t,i;hb.length&&(t=hb[0],i=nb-jb,jb?5<i?hb.shift(jb=0):t.D(i<.5?1-i/.5:4.5<i?(i-4.5)/.5:0):jb=nb)}let lb,S,L,ob,pb,qb,T,tb,U,ub,vb;function wb(){S=document.createElement("canvas"),L=S.getContext("webgl",{antialias:!1}),document.body.appendChild(S);var t=L.createProgram();L.attachShader(t,xb("precision highp float;uniform mat4 m;attribute vec2 p,t;attribute vec4 c,a;varying vec4 v,d,e;void main(){gl_Position=m*vec4(p,1,1);v=vec4(t,p);d=c;e=a;}",35633)),L.attachShader(t,xb("precision highp float;varying vec4 v,d,e;uniform sampler2D s;void main(){gl_FragColor=texture2D(s,v.xy)*d+e;}",35632)),L.linkProgram(t),pb=t,t=new ArrayBuffer(24e5),qb=L.createBuffer(),T=new Float32Array(t),tb=new Uint32Array(t),U=0}function yb(){L.viewport(0,0,S.width=D.width,S.height=D.height),L.clear(16384),L.useProgram(pb),L.activeTexture(33984),L.bindTexture(3553,ob=K[0].ga),L.bindBuffer(34962,qb),L.bufferData(34962,24e5,35048),fb();let h=0;var t=(t,i,a,e,s=0)=>{t=L.getAttribLocation(pb,t),L.enableVertexAttribArray(t),L.vertexAttribPointer(t,e,i,s,24,h),h+=e*a},i=(t("p",5126,4,2),t("t",5126,4,2),t("c",5121,1,4,1),t("a",5121,1,4,1),t=2*z/D.width,2*z/D.height);L.uniformMatrix4fv(L.getUniformLocation(pb,"m"),0,new Float32Array([t,0,0,0,0,i,0,0,1,1,-1,1,-1-t*y.x,-1-i*y.y,0,0]))}function fb(t=0){vb=t}function Ja(t){t!=ob&&(zb(),L.bindTexture(3553,ob=t))}function xb(t,i){return i=L.createShader(i),L.shaderSource(i,t),L.compileShader(i),i}function zb(){var t;U&&(t=ub?1:771,L.blendFuncSeparate(770,t,1,t),L.enable(3042),L.bufferSubData(34962,0,T.subarray(0,6*U)),L.drawArrays(5,0,U),U=0,ub=vb)}function Ab(t){var i=G;(U||t)&&(zb(),t)&&i.drawImage(S,0,0)}function Ka(a,e,t,i,s,h,n,r,o,l,c=0){(99994<=U||ub!=vb)&&zb();var u=Math.cos(s)/2,x=Math.sin(s)/2;s=u*t,u*=i,a=[a-s+(i*=x),e+u+(t*=x),h,n,a-s-i,e-u+t,h,o,a+s+i,e+u-t,r,n,a+s-i,e-u-t,r,o];for(let t=6,i=6*U;t--;)e=4*m(t-1,0,3),T[i++]=a[e++],T[i++]=a[e++],T[i++]=a[e++],T[i++]=a[e++],tb[i++]=l,tb[i++]=c;U+=6}const eb=1/60;let A=[],va=[],Bb=0,ua=0,nb=0,Cb=0,V=0;function Db(){J=x(D.width,D.height),G.imageSmoothingEnabled=!1,yb()}function Eb(){va=A.filter(t=>t.oa);for(const t of A)t.parent||function t(i){if(!i.v){i.update();for(const a of i.children)t(a)}}(t);A=A.filter(t=>!t.v)}const Fb=new Wa,Gb=new kb;ib="Hello World",gb.forEach(t=>t.la=0|localStorage[ib+"_"+t.id]);let Z;!function(e,s,r,o){function l(t=0){var i=t-Cb;for(Cb=t,nb+=i/1e3,V+=i,V=Math.min(V,50),oa.x?(D.width=oa.x,D.height=oa.y,t=innerWidth/innerHeight,i=D.width/D.height,(S||D).style.width=D.style.width=H.style.width=t<i?"100%":"",(S||D).style.height=D.style.height=H.style.height=t<i?"":"100%"):(D.width=Math.min(innerWidth,na.x),D.height=Math.min(innerHeight,na.y)),H.width=D.width,H.height=D.height,J=x(D.width,D.height),t=0,V<0&&-9<V&&(t=V,V=0);0<=V;V-=1e3/60)ua=Bb++/60,Ta||document.hasFocus()||(M=[[]]),Oa=Ga(),Sa(),e(),Eb(),s(),Pa();V+=t,Db(),r(),A.sort((t,i)=>t.O-i.O);for(const a of A)a.v||a.D();o(),mb(),Ab(),requestAnimationFrame(l)}document.body.style="margin:0;overflow:hidden;background:#000;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none",document.body.appendChild(D=document.createElement("canvas")),G=D.getContext("2d"),wb(),document.body.appendChild(H=document.createElement("canvas")),xa=H.getContext("2d"),(S||D).style=D.style=H.style="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);image-rendering:pixelated",Promise.all(["tiles.png","tiles3.png"].map((a,e)=>new Promise(t=>{const i=new Image;i.onerror=i.onload=()=>{K[e]=new Fa(i),t()},i.src=a}))).then(()=>{{Q=x(32,16);for(var t=(Xa=[]).length=Math.abs(Q.x*Q.y);t--;)Xa[t]=0;var i=x(),t=new ab(i,Q),a=K[0].image,e=(G.drawImage(a,0,0),G.getImageData(0,0,a.width,a.height).data),s,r,o;for(i.x=Q.x;i.x--;)for(i.y=Q.y;i.y--;)e[4*(i.x+a.width*(15+Q.y-i.y))]&&(s=Math.floor(n(4,0)),r=Math.floor(n(2,0)),(o=ia()).a=.1,t.setData(i,new Ya(1,s,r,o)),ka(i,Q))&&(Xa[(0|i.y)*Q.x+i.x|0]=1);for(t.xa=[D,G,J,y,z],D=t.canvas,G=t.context,y=t.size.scale(.5),z=t.l.size.x,D.width=t.size.x*t.l.size.x,D.height=t.size.y*t.l.size.y,Db(),i=t.size.x;i--;)for(a=t.size.y;a--;)Za(t,x(i,a));Ab(1),[D,G,J,y,z]=t.xa,y=x(16,8),z=48,qa=-.01,(Z=new db(x(16,15),0,1,0,500,h,Da(0,16),new v(1,1,1),new v(0,0,0),new v(1,1,1,0),new v(0,0,0,0),2,.2,.2,.1,.05,.99,1,1,h,.05,.5,1,1)).s=.3,Z.G=2}l()})}(function(){M[0]&&2&M[0][0]&&(Fb.play(Oa),Z.S=new v,Z.T=ia(),Z.$=Z.S.scale(1,0),Z.aa=Z.T.scale(1,0),Gb.unlock()),Ha.x&&(Z.i=Oa)},function(){},function(){B(x(16,8),x(20,14),void 0,la(.6),0,0,void 0,0),B(x(21,5),x(4.5),Da(2,16,1))},function(){Ma("LittleJS Engine Demo",x(J.x/2,70),80,la(1),6,la(0))});
|
|
2
|
+
</script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const h=Math.PI;function m(t,i=0,a=1){return t<i?i:a<t?a:t}function aa(t,i,a){return a-i?m((t-i)/(a-i)):0}function ba(t,i,a,e){return 2*Math.abs(t.x-a.x)<i.x+e.x&&2*Math.abs(t.y-a.y)<i.y+e.y}function n(t=1,i=0){return i+Math.random()*(t-i)}function ca(t=1){return fa(new p,n(2*h),t)}function ha(t=1){return 0<t?ca(t*n(0/t,1)**.5):new p}function ia(t=new v,i=new v(0,0,0,1),a){return a?t.ha(i,n()):new v(n(t.r,i.r),n(t.j,i.j),n(t.b,i.b),n(t.a,i.a))}function x(t=0,i){return null==t.x?new p(t,null==i?t:i):new p(t.x,t.y)}function fa(t,i=0,a=1){return t.x=a*Math.sin(i),t.y=a*Math.cos(i),t}function ja(t){var i=t.length();return 1<i?t.scale(1/i):t}function ka(t,i){return 0<=t.x&&0<=t.y&&t.x<i.x&&t.y<i.y}class p{constructor(t=0,i=0){this.x=t,this.y=i}M(){return new p(this.x,this.y)}add(t){return new p(this.x+t.x,this.y+t.y)}u(t){return new p(this.x-t.x,this.y-t.y)}multiply(t){return new p(this.x*t.x,this.y*t.y)}ca(t){return new p(this.x/t.x,this.y/t.y)}scale(t){return new p(this.x*t,this.y*t)}length(){return(this.x**2+this.y**2)**.5}normalize(t=1){var i=this.length();return i?this.scale(t/i):new p(0,t)}angle(){return Math.atan2(this.x,this.y)}rotate(t){var i=Math.cos(t);return t=Math.sin(t),new p(this.x*i-this.y*t,this.x*t+this.y*i)}direction(){return Math.abs(this.x)>Math.abs(this.y)?this.x<0?3:1:this.y<0?2:0}floor(){return new p(Math.floor(this.x),Math.floor(this.y))}ha(t,i){return this.add(t.u(this).scale(m(i)))}toString(){}}function la(t=1){var i=new v,a=t<.5?+t:t+0-0*t,e=(t,i,a)=>(a=(a%1+1)%1)<1/6?t+6*(i-t)*a:a<.5?i:a<2/3?t+(i-t)*(2/3-a)*6:t;return i.r=e(t=2*t-a,a,1/3),i.j=e(t,a,0),i.b=e(t,a,-1/3),i.a=1,i}function ma(t){return(255*m(t.r)|0)+((255*m(t.j)|0)<<8)+((255*m(t.b)|0)<<16)+((255*m(t.a)|0)<<24)}class v{constructor(t=1,i=1,a=1,e=1){this.r=t,this.j=i,this.b=a,this.a=e}M(){return new v(this.r,this.j,this.b,this.a)}add(t){return new v(this.r+t.r,this.j+t.j,this.b+t.b,this.a+t.a)}u(t){return new v(this.r-t.r,this.j-t.j,this.b-t.b,this.a-t.a)}multiply(t){return new v(this.r*t.r,this.j*t.j,this.b*t.b,this.a*t.a)}ca(t){return new v(this.r/t.r,this.j/t.j,this.b/t.b,this.a/t.a)}scale(t,i=t){return new v(this.r*t,this.j*t,this.b*t,this.a*i)}ha(t,i){return this.add(t.u(this).scale(m(i)))}toString(t=1){var i=t=>((t=255*t|0)<16?"0":"")+t.toString(16);return"#"+i(this.r)+i(this.j)+i(this.b)+(t?i(this.a):"")}}let y=x(),z=32,na=x(1920,1200),oa=x(),pa=x(16),qa=0,ra=x(640,80);function sa(t){if(!t.v){t.v=1,t.parent&&t.parent.removeChild(t);for(const i of t.children)sa(i,i.parent=0)}}class ta{constructor(t=x(),i=x(1),a,e=0,s,h=0){this.i=t.M(),this.size=i,this.pa,this.l=a,this.angle=e,this.color=s,this.ma,this.I=this.m=this.h=1,this.s=0,this.W=.8,this.A=1,this.O=h,this.g=x(),this.R=0,this.ka=ua,this.children=[],this.J=1,A.push(this)}update(){var t=this.parent;if(t)this.i=this.Ca.multiply(x(t.o?-1:1,1)).rotate(-t.angle).add(t.i),this.angle=(t.o?-1:1)*this.Ba+t.angle;else if(this.g.x=m(this.g.x,-1,1),this.g.y=m(this.g.y,-1,1),t=this.i.M(),this.g.y+=qa*this.A,this.i.x+=this.g.x*=this.m,this.i.y+=this.g.y*=this.m,this.angle+=this.R*=this.I,this.h){var i,a,e,s,h,n,r=this.g.y<0;if(this.B&&(i=this.B.g?this.B.g.x:0,this.g.x=i+(this.g.x-i)*this.W,this.B=0),this.oa)for(var o of va)!this.sa&&!o.sa||o.v||o.parent||o==this||ba(this.i,this.size,o.i,o.size)&&(ba(t,this.size,o.i,o.size)?(i=(a=(i=t.u(o.i)).length())<.01?ca(.001):i.scale(.001/a),this.g=this.g.add(i),o.h&&(o.g=o.g.u(i))):(a=this.size.add(o.size),e=2*(t.y-o.i.y)>a.y+qa,s=2*Math.abs(t.y-o.i.y)<a.y,h=2*Math.abs(t.x-o.i.x)<a.x,i=Math.max(this.s,o.s),!e&&!h&&s||(this.i.y=o.i.y+(a.y/2+.001)*Math.sign(t.y-o.i.y),o.B&&r||!o.h?(r&&(this.B=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+m(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+m(i)*(n-h))),!e&&s&&(this.i.x=o.i.x+(a.x/2+.001)*Math.sign(t.x-o.i.x),o.h?(a=(this.h*this.g.x+o.h*o.g.x)/(this.h+o.h),e=o.g.x*(o.h-this.h)/(this.h+o.h)+2*this.g.x*this.h/(this.h+o.h),this.g.x=a+m(i)*(this.g.x*(this.h-o.h)/(this.h+o.h)+2*o.g.x*o.h/(this.h+o.h)-a),o.g.x=a+m(i)*(e-a)):this.g.x*=-i)));this.J&&wa(this.i,this.size,this)&&!wa(t,this.size,this)&&(o=wa(x(this.i.x,t.y),this.size,this),!wa(x(t.x,this.i.y),this.size,this)&&o||(this.B=r,this.g.y*=-this.s,(r=(t.y-this.size.y/2|0)-(t.y-this.size.y/2))<0&&r>this.m*this.g.y+qa*this.A&&(this.g.y=this.m?(r-qa*this.A)/this.m:0),this.i.y=t.y),o)&&(this.i.x=t.x,this.g.x*=-this.s)}}D(){B(this.i,this.pa||this.size,this.l,this.color,this.angle,this.o,this.ma)}removeChild(t){t.parent==this&&this.children.includes(t),this.children.splice(this.children.indexOf(t),1),t.parent=0}toString(){}}let D,G,H,xa,J=x(),K=[];function Da(t=x(),i=pa,a=0){var e;return null==i.x&&(i=x(i)),null==t.x&&(t=x(t%(e=K[a].size.x/i.x|0)*i.x,(t/e|0)*i.y)),new Ea(t,i,a)}class Ea{constructor(t=x(),i=pa,a=0){this.i=t,this.size=i,this.P=a}offset(t){return new Ea(this.i.add(t),this.size,this.P)}}class Fa{constructor(t){this.image=t,this.size=x(t.width,t.height);var i=L.createTexture();L.bindTexture(3553,i),t&&t.width&&L.texImage2D(3553,0,6408,6408,5121,t),L.texParameteri(3553,10241,9728),L.texParameteri(3553,10240,9728),L.texParameteri(3553,10242,33071),L.texParameteri(3553,10243,33071),this.ga=i,this.qa=x(.3).ca(this.size)}}function Ga(){var t=Ha;return new p((t.x-J.x/2+.5)/z+y.x,(t.y-J.y/2+.5)/-z+y.y)}function Ia(t){return new p((t.x-y.x)*z+J.x/2-.5,(t.y-y.y)*-z+J.y/2-.5)}function B(t,i=x(1),h,n=new v,a=0,e,s=new v(0,0,0,0),r=1){var o,l,c,u,y;r?h?(r=K[h.P],o=h.size.x/r.size.x,l=h.size.y/r.size.y,c=h.i.x/r.size.x,u=h.i.y/r.size.y,y=r.qa,Ja(r.ga),Ka(t.x,t.y,e?-i.x:i.x,i.y,a,c+y.x,u+y.y,c-y.x+o,u-y.y+l,ma(n),ma(s))):Ka(t.x,t.y,i.x,i.y,a,0,0,0,0,0,ma(n)):La(t,i,a,e,t=>{var i,a,e,s;h?(i=h.i.x+.3,a=h.i.y+.3,e=h.size.x-.6,s=h.size.y-.6,t.globalAlpha=n.a,t.drawImage(K[h.P].image,i,a,e,s,-.5,-.5,1,1)):(t.fillStyle=n,t.fillRect(-.5,-.5,1,1))})}function La(t,i,a,e,s){var h=G;t=Ia(t),i=i.scale(z),h.save(),h.translate(t.x+.5,t.y+.5),h.rotate(a),h.scale(e?-i.x:i.x,i.y),s(h),h.restore()}function Ma(t,i,a=1,e=new v,s=0,h=new v(0,0,0),n="center"){var r=xa;r.fillStyle=e,r.lineWidth=s,r.strokeStyle=h,r.textAlign=n,r.font=a+"px arial",r.textBaseline="middle",r.lineJoin="round",i=i.M(),(t+"").split("\n").forEach(t=>{s&&r.strokeText(t,i.x,i.y),r.fillText(t,i.x,i.y),i.y+=a})}function Na(t,i=0){return M[i]&&1&M[i][t]}let Oa=x(),Ha=x();function N(t,i=0){return Na(t,i+1)}let M=[[]];function Pa(){for(const t of M)for(const i in t)t[i]&=1}function Qa(t){return 87==t?38:83==t?40:65==t?37:68==t?39:t}onkeydown=t=>{t.repeat||(M[0][Qa(t.which)]=3)},onkeyup=t=>{M[0][Qa(t.which)]=4},onmousedown=t=>{M[0][t.button]=3,onmousemove(t),t.button&&t.preventDefault()},onmouseup=t=>M[0][t.button]=2&M[0][t.button]|4,onmousemove=t=>{var i;return t=D?(i=D.getBoundingClientRect(),x(D.width,D.height).multiply(x(aa(t.x,i.left,i.right),aa(t.y,i.top,i.bottom)))):x(),Ha=t},onwheel=t=>t.ctrlKey||Math.sign(t.deltaY),oncontextmenu=()=>!1;const Ra=[];function Sa(){if(navigator&&navigator.getGamepads&&document.hasFocus()){var i=navigator.getGamepads();for(let t=i.length;t--;){var a=i[t],e=M[t+1]||(M[t+1]=[]),s=Ra[t]||(Ra[t]=[]);if(a){var h=t=>.3<t?aa(t,.3,.8):t<-.3?-aa(-t,.3,.8):0;for(let t=0;t<a.axes.length-1;t+=2)s[t>>1]=ja(x(h(a.axes[t]),h(-a.axes[t+1])));for(h=a.buttons.length;h--;)e[h]=a.buttons[h].pressed?1+2*!N(h,t):4*N(h,t);(a=x(N(15,t)-N(14,t),N(12,t)-N(13,t))).x**2+a.y**2&&(s[0]=ja(a))}}}}const Ta=void 0!==window.ontouchstart;if(Ta){let a,e=onmousedown,s=onmouseup;onmousedown=onmouseup=()=>0,ontouchstart=ontouchmove=ontouchend=t=>{t.button=0,O?O.resume():Ua([Va(0)]);var i=t.touches.length;return i?(t.x=t.touches[0].clientX,t.y=t.touches[0].clientY,(a?onmousemove:e)(t)):a&&s(t),a=i,document.hasFocus()&&t.preventDefault(),!0}}class Wa{constructor(){var t=[1,.5];this.wa=40,this.Aa=.7,this.N=0,t&&(this.N=t[1]||(t[1]=0),this.ja=[Va(...t)],this.sampleRate=44100)}play(t,i=1,a=1,e=1,s=0){if(this.ja){var h;if(t){if(h=this.wa){var r=y;if(h*h<(r=(y.x-t.x)**2+(r.y-t.y)**2))return;i*=aa(r**.5,h,h*this.Aa)}h=2*Ia(t).x/D.width-1}return this.source=Ua(this.ja,i,a+a*this.N*e*n(-1,1),h,s,this.sampleRate)}}stop(){this.source&&this.source.stop(),this.source=0}}let O;function Ua(t,i=1,a=1,e=0,s=0,h=44100){var n;if("running"==(O||=new AudioContext).state)return n=O.createBuffer(t.length,t[0].length,h),h=O.createBufferSource(),t.forEach((t,i)=>n.getChannelData(i).set(t)),h.buffer=n,h.playbackRate.value=a,h.loop=s,(t=O.createGain()).gain.value=.5*i,t.connect(O.destination),h.connect(new StereoPannerNode(O,{pan:m(e,-1,1)})).connect(t),h.start(),h;O.resume()}function Va(t=1,i=.05,a=220,e=0,s=0,r=.1,o=0,l=1,c=0,u=0,x=0,y=0,d=0,b=0,g=0,f=0,v=0,m=1,w=0,p=0){var M=2*h,z=c*=500*M/44100/44100,D=[];i=a*=(1+i*n(-1,1))*M/44100;let L=0,S=0,A=0,j=1,B=0,C=0,G=0,k,H;for(u*=500*M/44100**3,g*=M/44100,x*=M/44100,y*=44100,d=44100*d|0,H=(e=44100*e+9)+(w*=44100)+(s*=44100)+(r*=44100)+(v*=44100)|0;A<H;D[A++]=G)++C%(100*f|0)||(G=o?1<o?2<o?3<o?Math.sin((L%M)**3):Math.max(Math.min(Math.tan(L),1),-1):1-(2*L/M%2+2)%2:1-4*Math.abs(Math.round(L/M)-L/M):Math.sin(L),G=(d?1-p+p*Math.sin(M*A/d):1)*Math.sign(G)*Math.abs(G)**l*t*.5*(A<e?A/e:A<e+w?1-(A-e)/w*(1-m):A<e+w+s?m:A<H-v?(H-A-v)/r*m:0),G=v?G/2+(v>A?0:(A<H-v?1:(H-A)/v)*D[A-v|0]/2):G),k=(a+=c+=u)*Math.cos(g*S++),L+=k-k*b*(1-1e9*(Math.sin(A)+1)%2),j&&++j>y&&(a+=x,i+=x,j=0),!d||++B%d||(a=i,c=z,j||=1);return D}let Xa=[],Q=x();function wa(t,i=x(),a){var e=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=e;i<h;++i){var n=Xa[s*Q.x+i];if(n&&(!a||0<n))return 1}}class Ya{constructor(t,i=0,a=0,e=new v){this.Z=t,this.direction=i,this.o=a,this.color=e}clear(){this.Z=this.direction=this.o=0,color=new v}}function Za(t,i){var a=i.floor().add(t.i).add(x(.5));$a(t,a,t=>t.clearRect(-.5,-.5,1,1)),null!=(i=t.getData(i)).Z&&B(a,x(1),Da(i.Z,t.l.size,t.l.P),i.color,i.direction*h/2,i.o)}function $a(t,i,a){var e=x(1),s=t.context;s.save(),i=i.u(t.i).multiply(t.l.size),e=e.multiply(t.l.size),s.translate(i.x,t.canvas.height-i.y),s.rotate(0),s.scale(e.x,e.y),a(s),s.restore()}class ab extends ta{constructor(t,i=Q){var a=x(1);for(super(t,i,Da(),0,void 0,0),this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.scale=a,this.ra,this.data=[],t=this.size,t=Math.abs(t.x*t.y);t--;)this.data.push(new Ya)}setData(t,i,a){ka(t,this.size)&&(this.data[(0|t.y)*this.size.x+t.x|0]=i,a)&&Za(this,t)}getData(t){return ka(t,this.size)&&this.data[(0|t.y)*this.size.x+t.x|0]}update(){}D(){var t=Ia(this.i.add(x(0,this.size.y*this.scale.y)));(this.ra?xa:G).drawImage(this.canvas,t.x,t.y,z*this.size.x*this.scale.x,z*this.size.y*this.scale.y)}}function bb(t){var i=null!=t.U.x?x(n(-.5,.5),n(-.5,.5)).multiply(t.U).rotate(t.angle):ha(t.U/2);t.X||(i=t.i.add(i)),i=new cb(i,t.l,t.Ea);const a=t.N;var e=(o=t=>t+t*n(a,-a))(t.va),s=o(t.Y),h=o(t.ya),r=o(t.speed),o=o(t.na)*(2*Math.floor(n(2,0))-1),l=n(t.da,-t.da),c=ia(t.S,t.T,t.ia),u=ia(t.$,t.aa,t.ia),l=t.X?l:t.angle+l;i.L=c,i.K=u.u(c),i.g=fa(x(),l,r),i.R=o,i.ta=e,i.Y=s,i.za=h-s,i.V=t.V,i.m=t.m,i.I=t.I,i.s=t.s,i.W=t.W,i.A=t.A,i.J=t.J,i.H=t.H,i.O=t.O,i.G=t.G,i.o=Math.floor(n(2,0)),i.C=t.X&&t,i.ba=t.Da,t.ua&&t.ua(i)}class db extends ta{constructor(t,i,a=0,e=0,s=100,n=h,r,o=new v,l=new v,c=new v(1,1,1,0),u=new v(1,1,1,0),y=.5,d=.1,b=1,g=.1,f=.05,m=1,w=1,p=0,M,z=.1,D=.2,L,S,A=1,j=S?1e9:0,B){super(t,x(),r,i,void 0,j),this.U=a,this.fa=e,this.ea=s,this.da=n,this.S=o,this.T=l,this.$=c,this.aa=u,this.ia=A,this.va=y,this.Y=d,this.ya=b,this.speed=g,this.na=f,this.m=m,this.I=w,this.A=p,this.V=z,this.N=D,this.J=L,this.H=S,this.X=B,this.F=this.G=0}update(){if(this.parent&&super.update(),!this.fa||ua-this.ka<=this.fa){if(+this.ea){var t=1/this.ea;for(this.F+=eb;0<this.F;this.F-=t)bb(this)}}else sa(this)}D(){}}class cb extends ta{constructor(t,i,a){super(t,x(),i,a)}D(){var t=Math.min((ua-this.ka)/this.ta,1),i=x(this.Y+t*this.za),a=this.V/2,a=new v(this.L.r+t*this.K.r,this.L.j+t*this.K.j,this.L.b+t*this.K.b,(this.L.a+t*this.K.a)*(t<a?t/a:1-a<t?(1-t)/a:1));this.H&&fb(1);let e=this.i;var s,h,n=this.angle;this.C&&(e=this.C.i.add(e.rotate(-this.C.angle)),n+=this.C.angle),this.G?(s=this.g,n=(s=this.C?s.rotate(-this.C.angle):s).length(),s=s.scale(1/n),h=n*this.G,i.y=Math.max(i.x,h),n=s.angle(),B(e.add(s.multiply(x(0,-h/2))),i,this.l,a,n,this.o)):B(e,i,this.l,a,n,this.o),this.H&&fb(),1==t&&(this.color=a,this.size=i,this.ba&&this.ba(this),this.v=1)}}const gb=[];let hb=[],ib,jb;class kb{constructor(){(gb[this.id=0]=this).name="Example Medal",this.description="Welcome to LittleJS!",this.icon="🏆"}unlock(){this.la||(localStorage[ib+"_"+this.id]=this.la=1,hb.push(this),lb&&lb.Fa(this.id))}D(t=0){var i=xa,a=Math.min(ra.x,D.width),e=H.width-a;t*=-ra.y,i.save(),i.beginPath(),i.fillStyle=new v(.9,.9,.9),i.strokeStyle=new v(0,0,0),i.lineWidth=3,i.fill(i.rect(e,t,a,ra.y)),i.stroke(),i.clip(),a=x(e+15+25,t+ra.y/2),this.image?xa.drawImage(this.image,a.x-25,a.y-25,50,50):Ma(this.icon,a,35,new v(0,0,0)),e=x(e+50+30,t+28),Ma(this.name,e,38,new v(0,0,0),0,0,"left"),e.y+=32,Ma(this.description,e,24,new v(0,0,0),0,0,"left"),i.restore()}}function mb(){var t,i;hb.length&&(t=hb[0],i=nb-jb,jb?5<i?hb.shift(jb=0):t.D(i<.5?1-i/.5:4.5<i?(i-4.5)/.5:0):jb=nb)}let lb,S,L,ob,pb,qb,T,tb,U,ub,vb;function wb(){S=document.createElement("canvas"),L=S.getContext("webgl",{antialias:!1}),document.body.appendChild(S);var t=L.createProgram();L.attachShader(t,xb("precision highp float;uniform mat4 m;attribute vec2 p,t;attribute vec4 c,a;varying vec4 v,d,e;void main(){gl_Position=m*vec4(p,1,1);v=vec4(t,p);d=c;e=a;}",35633)),L.attachShader(t,xb("precision highp float;varying vec4 v,d,e;uniform sampler2D s;void main(){gl_FragColor=texture2D(s,v.xy)*d+e;}",35632)),L.linkProgram(t),pb=t,t=new ArrayBuffer(24e5),qb=L.createBuffer(),T=new Float32Array(t),tb=new Uint32Array(t),U=0}function yb(){L.viewport(0,0,S.width=D.width,S.height=D.height),L.clear(16384),L.useProgram(pb),L.activeTexture(33984),L.bindTexture(3553,ob=K[0].ga),L.bindBuffer(34962,qb),L.bufferData(34962,24e5,35048),fb();let h=0;var t=(t,i,a,e,s=0)=>{t=L.getAttribLocation(pb,t),L.enableVertexAttribArray(t),L.vertexAttribPointer(t,e,i,s,24,h),h+=e*a},i=(t("p",5126,4,2),t("t",5126,4,2),t("c",5121,1,4,1),t("a",5121,1,4,1),t=2*z/D.width,2*z/D.height);L.uniformMatrix4fv(L.getUniformLocation(pb,"m"),0,new Float32Array([t,0,0,0,0,i,0,0,1,1,-1,1,-1-t*y.x,-1-i*y.y,0,0]))}function fb(t=0){vb=t}function Ja(t){t!=ob&&(zb(),L.bindTexture(3553,ob=t))}function xb(t,i){return i=L.createShader(i),L.shaderSource(i,t),L.compileShader(i),i}function zb(){var t;U&&(t=ub?1:771,L.blendFuncSeparate(770,t,1,t),L.enable(3042),L.bufferSubData(34962,0,T.subarray(0,6*U)),L.drawArrays(5,0,U),U=0,ub=vb)}function Ab(t){var i=G;(U||t)&&(zb(),t)&&i.drawImage(S,0,0)}function Ka(a,e,t,i,s,h,n,r,o,l,c=0){(99994<=U||ub!=vb)&&zb();var u=Math.cos(s)/2,x=Math.sin(s)/2;s=u*t,u*=i,a=[a-s+(i*=x),e+u+(t*=x),h,n,a-s-i,e-u+t,h,o,a+s+i,e+u-t,r,n,a+s-i,e-u-t,r,o];for(let t=6,i=6*U;t--;)e=4*m(t-1,0,3),T[i++]=a[e++],T[i++]=a[e++],T[i++]=a[e++],T[i++]=a[e++],tb[i++]=l,tb[i++]=c;U+=6}const eb=1/60;let A=[],va=[],Bb=0,ua=0,nb=0,Cb=0,V=0;function Db(){J=x(D.width,D.height),G.imageSmoothingEnabled=!1,yb()}function Eb(){va=A.filter(t=>t.oa);for(const t of A)t.parent||function t(i){if(!i.v){i.update();for(const a of i.children)t(a)}}(t);A=A.filter(t=>!t.v)}const Fb=new Wa,Gb=new kb;ib="Hello World",gb.forEach(t=>t.la=0|localStorage[ib+"_"+t.id]);let Z;!function(e,s,r,o){function l(t=0){var i=t-Cb;for(Cb=t,nb+=i/1e3,V+=i,V=Math.min(V,50),oa.x?(D.width=oa.x,D.height=oa.y,t=innerWidth/innerHeight,i=D.width/D.height,(S||D).style.width=D.style.width=H.style.width=t<i?"100%":"",(S||D).style.height=D.style.height=H.style.height=t<i?"":"100%"):(D.width=Math.min(innerWidth,na.x),D.height=Math.min(innerHeight,na.y)),H.width=D.width,H.height=D.height,J=x(D.width,D.height),t=0,V<0&&-9<V&&(t=V,V=0);0<=V;V-=1e3/60)ua=Bb++/60,Ta||document.hasFocus()||(M=[[]]),Oa=Ga(),Sa(),e(),Eb(),s(),Pa();V+=t,Db(),r(),A.sort((t,i)=>t.O-i.O);for(const a of A)a.v||a.D();o(),mb(),Ab(),requestAnimationFrame(l)}document.body.style="margin:0;overflow:hidden;background:#000;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none",document.body.appendChild(D=document.createElement("canvas")),G=D.getContext("2d"),wb(),document.body.appendChild(H=document.createElement("canvas")),xa=H.getContext("2d"),(S||D).style=D.style=H.style="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);image-rendering:pixelated",Promise.all(["tiles.png","tiles3.png"].map((a,e)=>new Promise(t=>{const i=new Image;i.onerror=i.onload=()=>{K[e]=new Fa(i),t()},i.src=a}))).then(()=>{{Q=x(32,16);for(var t=(Xa=[]).length=Math.abs(Q.x*Q.y);t--;)Xa[t]=0;var i=x(),t=new ab(i,Q),a=K[0].image,e=(G.drawImage(a,0,0),G.getImageData(0,0,a.width,a.height).data),s,r,o;for(i.x=Q.x;i.x--;)for(i.y=Q.y;i.y--;)e[4*(i.x+a.width*(15+Q.y-i.y))]&&(s=Math.floor(n(4,0)),r=Math.floor(n(2,0)),(o=ia()).a=.1,t.setData(i,new Ya(1,s,r,o)),ka(i,Q))&&(Xa[(0|i.y)*Q.x+i.x|0]=1);for(t.xa=[D,G,J,y,z],D=t.canvas,G=t.context,y=t.size.scale(.5),z=t.l.size.x,D.width=t.size.x*t.l.size.x,D.height=t.size.y*t.l.size.y,Db(),i=t.size.x;i--;)for(a=t.size.y;a--;)Za(t,x(i,a));Ab(1),[D,G,J,y,z]=t.xa,y=x(16,8),z=48,qa=-.01,(Z=new db(x(16,15),0,1,0,500,h,Da(0,16),new v(1,1,1),new v(0,0,0),new v(1,1,1,0),new v(0,0,0,0),2,.2,.2,.1,.05,.99,1,1,h,.05,.5,1,1)).s=.3,Z.G=2}l()})}(function(){M[0]&&2&M[0][0]&&(Fb.play(Oa),Z.S=new v,Z.T=ia(),Z.$=Z.S.scale(1,0),Z.aa=Z.T.scale(1,0),Gb.unlock()),Ha.x&&(Z.i=Oa)},function(){},function(){B(x(16,8),x(20,14),void 0,la(.6),0,0,void 0,0),B(x(21,5),x(4.5),Da(2,16,1))},function(){Ma("LittleJS Engine Demo",x(J.x/2,70),80,la(1),6,la(0))});
|
|
Binary file
|
|
Binary file
|