This repository has been archived on 2021-04-27. You can view files and clone it, but cannot push or open issues or pull requests.
2021-04-25 13:45:50 -04:00

1 line
20 KiB
JavaScript

function createCanvas(e){var t=document.createElement("canvas");t.id=e,t.width=canvases.cvs.width,t.height=canvases.cvs.height,t.style="image-rendering:pixelated;image-rendering: crisp-edges;display:none",document.body.appendChild(t),canvases[`${e}cvs`]=document.getElementById(e),canvases[`${e}ctx`]=canvases[`${e}cvs`].getContext("2d")}function startLoops(){try{draw}catch(e){return console.warn(bug+" no draw function found"),null}try{update}catch(e){return console.warn(bug+" no update function found"),null}try{input}catch(e){seperateInputLoop=!1}try{onAssetsLoaded()}catch(e){}requestAnimationFrame(drawLoop),setInterval(updateLoop,1e3/updateFPS),seperateInputLoop&&setInterval(inputLoop,4)}function mousePosition(){if(0===drawMode){return{x:mousePos.x-camera.x,y:mousePos.y-camera.y}}if(1===drawMode){var e=canvases.cvs.width/2,t=canvases.cvs.height/2;return{x:(mousePos.x-e)/camera.zoom+e-camera.x,y:(mousePos.y-t)/camera.zoom+t-camera.y}}e=canvases.cvs.width/2,t=canvases.cvs.height/2;var a={x:(mousePos.x-e)/camera.zoom+e-camera.x,y:(mousePos.y-t)/camera.zoom+t-camera.y},n={x:-camera.x+cw/2,y:-camera.y+ch/2},s=pointTo(n,a)-camera.angle,o=dist(n,a);return{x:n.x+Math.cos(s)*o,y:n.y+Math.sin(s)*o}}function addStyle(){var e=document.createElement("style");e.id="gamejsstyle",document.head.appendChild(e);var t=document.createElement("meta");t.setAttribute("charset","utf-8"),document.head.appendChild(t)}function rand(e,t){return Math.floor(Math.random()*(t-e+1))+e}function radToDeg(e){return e/Math.PI*180}function degToRad(e){return e*Math.PI/180}function velocity(e){return{x:Math.sin(e),y:Math.cos(e)}}function pointTo(e,t){var a=t.x-e.x,n=t.y-e.y;return Math.atan2(n,a)}function loadImagesAndSounds(){var e="";function t(a,n){let s="";for(let o=0;o<a.length;o++){if("string"==typeof a[o]){if(0==o){e+=a[o],s=a[o]}else if("image"==n){let t=e+a[o];imagePaths.push(t);let n=new Image;n.src=t,n.onerror=function(){console.warn(bug+" "+this.src+" was not found")},n.onload=function(){spriteLoad(t,n)},imgs.push(n)}else{"sound"==n&&(audioPaths.push(e+a[o]),newSound(e+a[o]))}}"object"==typeof a[o]&&t(a[o],n)}e=e.slice(0,e.length-s.length)}context=new AudioContext,(sfxVolumeNode=context.createGain()).connect(context.destination),(bmgVolumeNode=context.createGain()).connect(context.destination),t(images,"image"),t(audio,"sound"),(loadingCircle=new Image).src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAf0lEQVQ4jc2SuxHAIAxDbY4pMpHmyJSeKGuQKpyj2Hy6qETPQvhQCWRmDRfeZ4cJAGW28mAUyL4Pqmx2nfK+zaR59glRHo5qZi0BaPHmbDhiyuzdsza9wcrtEVtG4Ip+FLCzTM+WneWxPv9gpQUzmhncLPOHUCYfHr4/C4r2dQPfhkeIbjeYWgAAAABJRU5ErkJggg==",clickSound=new Audio("data:audio/x-wav;base64,UklGRowBAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YWgBAADa/6T/2/+S/x//pP769Xr4fPh5+H34evh7+Pv6gf18/QIAhQcIDxUZFR4VHhgeEx6TFgkPCgqAAnz49/X18HLu7ubo4eXc5dzj3Gjf5+Fr5G7pce759YECiwwRFBQZlxuXG5cbFRmTFo8RCAoAAPz69/X08G7udO5s7vz1dvj++nv9gP3+/wEAgwKBAogHkBEpLUNG1lzqcPV683r4eu51ZmnVV7w+qypy88fDoKAXlAqKBoUAgIeHlpYsrTu87Ot9/ZIRGxkoKDEtqionIxgZiwfj5lnaz9JN0E3QV9pd3+Tm9fUBAAQFBwWNDBEPFxSYFpsWEA9+/fP1dfNt83bz8fX9+gQFkAwPDxQPEQ+IBwIAdfjv8OLm2+HX3Nrh4+bm63n4BAUUDx0ZqyCrJSkelBGEAnb4a+5a5Njcztxc31jkZunx9QgFGhQfGa0gqCCuIKkgpRsaFIsHdfhj6dfh0NzM19Th6es=");let a=cw/2-100,n=ch/2-100;optionsButtons.screenSize={x:a+160,y:n+12,w:50,h:20},optionsButtons.sfx={x:a+125,y:n+40,w:120,h:20},optionsButtons.bmg={x:a+125,y:n+70,w:120,h:20},loadLoop()}function loadLoop(){Object.keys(sprites).length==imagePaths.length&&audioPaths.length==audioLoadedLength?(startLoops(),imagePaths=[],audioPaths=[],imgs=[]):(curCtx.fillStyle="#2d2d2d",curCtx.fillRect(0,0,cw,ch),text(`audio: ${audioLoadedLength}/${audioPaths.length}`,10,30,"white",2),text(`sprites: ${Object.keys(sprites).length}/${imagePaths.length}`,10,10,"white",2),curCtx.setTransform(1,0,0,1,Math.round(cw/2),Math.round(ch/2)),curCtx.rotate(loadAng),loadAng+=.1,curCtx.drawImage(loadingCircle,Math.round(-8),Math.round(-8)),curCtx.setTransform(1,0,0,1,0,0),requestAnimationFrame(loadLoop))}function spriteLoad(e,t){let a,n=e.lastIndexOf(".");for(let t=n-1;acceptableChars.includes(e[t]);t--){a=t}let s=e.slice(a,n),o=Math.max(t.width,t.height)/2;sprites[s]={spr:t,drawLimitSize:o}}function newSound(e){let t,a=e.lastIndexOf(".");for(let n=a-1;acceptableChars.includes(e[n]);n--){t=n}let n=e.slice(t,a);sounds[n]={nodes:[],volNodes:[],src:e,type:"sfx",volume:1},sounds[n].nodes=[1];let s=new Audio;s.onerror=function(){console.warn(bug+" "+e+" was not found")},s.src=e,s.preload="auto",s.addEventListener("canplaythrough",function(){audioLoadedLength++},!1),sounds[n].nodes.push(s);let o=context.createMediaElementSource(s),r=context.createGain();o.connect(r),r.connect(sfxVolumeNode),abuffer.push(o),volumeList.push(r),sounds[n].volNodes.push(volumeList.length-1)}function addSound(e){let t=new Audio;t.src=e.src,t.preload="auto",e.nodes.splice(e.nodes[0],0,t);let a=context.createMediaElementSource(t),n=context.createGain();n.gain.value=e.volume,a.connect(n),n.connect("sfx"==e.type?sfxVolumeNode:bmgVolumeNode),abuffer.push(a),volumeList.push(n),e.volNodes.push(volumeList.length-1),volumeList[e.volNodes[e.volNodes.length-1]].gain.value=volumeList[e.volNodes[0]].gain.value}function play(e){s=e.nodes,s[s[0]].ended||!s[s[0]].played.length?(s[s[0]].play(),s[0]++,s[0]==s.length&&(s[0]=1)):(addSound(e),s[s[0]].play(),s[0]++,s[0]==s.length&&(s[0]=1))}function setVolume(e,t){for(let a=0,n=e.volNodes.length;a<n;a++){volumeList[e.volNodes[a]].gain.value=t}}function setType(e,t){for(let a=0,n=e.volNodes.length;a<n;a++){volumeList[e.volNodes[a]].disconnect("sfx"==e.type?sfxVolumeNode:bmgVolumeNode),volumeList[e.volNodes[a]].connect("sfx"==t?sfxVolumeNode:bmgVolumeNode)}e.type=t}function stop(e){s=e.nodes;for(let e=1;e<s.length;e++){s[e].pause(),s[e].currentTime=123456789}}function handleOptionsInput(){let e=!0;optionsMenu&&(mousePress[0]&&(rectpoint(optionsButtons.screenSize,mousePos)&&("1:1"==screenSize?(screenSize="fit",canvasScale=0):(screenSize="1:1",canvasScale=1)),rectpoint({x:cw/2,y:ch/2,w:200,h:200},mousePos)||(optionsMenu=!1,e=!1)),mouseDown[0]&&(rectpoint(optionsButtons.sfx,mousePos)&&(volume.sfx=(mousePos.x-(optionsButtons.sfx.x-60))/120),rectpoint(optionsButtons.bmg,mousePos)&&(volume.bgm=(mousePos.x-(optionsButtons.bmg.x-60))/120))),mousePos.x>cw-32&&mousePos.y<32?(mousePress[0]&&e&&(clickSound.play(),paused=!0,optionsMenu=!optionsMenu),optionsHover=25):optionsHover=0,mousePos.x<cw-32&&mousePos.x>cw-64&&mousePos.y<32?(pauseHover=25,mousePress[0]&&(clickSound.play(),paused=!paused)):pauseHover=0}function addFont(){var e=document.createElement("style");document.head.appendChild(e),canvases.ctx.textBaseline="hanging",canvases.ctx.textAlign="left"}function img(e,t,a,n=0,s=1,o=1){var r=e.drawLimitSize;if(t+r>drawLimitLeft&&t-r<drawLimitRight&&a+r>drawLimitTop&&a-r<drawLimitBottom||absDraw){let r=e.spr;0===n&&1===s&&1===o?curCtx.drawImage(r,Math.round(t+camera.x+difx-r.width/2),Math.round(a+camera.y+dify-r.height/2)):(curCtx.setTransform(s,0,0,o,Math.round(t+camera.x+difx),Math.round(a+camera.y+dify)),curCtx.rotate(n),curCtx.drawImage(r,Math.round(-r.width/2),Math.round(-r.height/2)),curCtx.setTransform(1,0,0,1,0,0))}}function imgIgnoreCutoff(e,t,a,n=0,s=1,o=1){let r=e.spr;0===n&&1===s&&1===o?curCtx.drawImage(r,Math.round(t+camera.x+difx-r.width/2),Math.round(a+camera.y+dify-r.height/2)):(curCtx.setTransform(s,0,0,o,Math.round(t+camera.x+difx),Math.round(a+camera.y+dify)),curCtx.rotate(n),curCtx.drawImage(r,Math.round(-r.width/2),Math.round(-r.height/2)),curCtx.setTransform(1,0,0,1,0,0))}function rect(e,t,a,n,s){curCtx.fillStyle=s,curCtx.fillRect(e-a/2+camera.x+difx,t-n/2+camera.y+dify,a,n)}function rectOut(e,t,a,n,s){curCtx.strokeStyle=s,curCtx.beginPath(),curCtx.rect(e-a/2+camera.x+difx,t-n/2+camera.y+dify,a,n),curCtx.stroke()}function circle(e,t,a,n){curCtx.beginPath(),curCtx.arc(e+camera.x+difx,t+camera.y+dify,a,0,2*Math.PI,!1),curCtx.fillStyle=n,curCtx.fill()}function shape(e,t,a,n){e+=camera.x+difx,t+=camera.y+dify,curCtx.fillStyle=n,curCtx.beginPath(),curCtx.moveTo(e+a[0].x,t+a[0].y);for(let n=1,s=a.length;n<s;n++){curCtx.lineTo(e+a[n].x,t+a[n].y)}curCtx.fill()}function text(e,t,a,n="black",s=1,o=cw){e=e.toString(),curCtx.fillStyle=n,curCtx.font=`${8*Math.round(s)}px PixelArial11`;var r=e.split("\n");for(let e=0;e<r.length;e++){if(curCtx.measureText(r[e]).width>o){var c=r[e].split(" "),i="",u=0;r.splice(e,1);for(let t=0;t<c.length;t++){curCtx.measureText(i+c[t]+" ").width<o?i+=c[t]+" ":(0==t&&(i+=c[t]),r.splice(e+u,0,i),u++,i="",c.splice(0,0==t?1:t),t=-1)}0!=i.length&&r.splice(e+u,0,i)}}for(let e=0;e<r.length;e++){curCtx.fillText(r[e],t+camera.x+difx,a+camera.y+dify+(8*(e+(drawMode?1:0))*s+s*e))}}function textWidth(e,t=1){return e=e.toString(),curCtx.font=`${8*Math.round(t)}px PixelArial11`,curCtx.measureText(e).width}function centerCameraOn(e,t){camera.x=-e+canvases.cvs.width/2,camera.y=-t+canvases.cvs.height/2}function moveCamera(e,t){camera.x-=t*Math.sin(camera.angle),camera.y-=t*Math.cos(camera.angle),camera.x-=e*Math.sin(camera.angle+1.57079632),camera.y-=e*Math.cos(camera.angle+1.57079632)}function imgRotScale(e,t,a,n,s,o){o.setTransform(n,0,0,n,e,t),o.rotate(a),o.drawImage(s,-s.width/2,-s.height/2),o.setTransform(1,0,0,1,0,0)}function drawCursor(){cursor.sprite&&mouseOnCanvas?(cursor.alignment?canvases.ctx.drawImage(cursor.sprite.spr,mousePos.x-Math.round(cursor.sprite.spr.width/2),mousePos.y-Math.round(cursor.sprite.spr.height/2)):canvases.ctx.drawImage(cursor.sprite.spr,mousePos.x,mousePos.y),cursor.show=!1):cursor.show=!0}function render(){1===drawMode&&imgRotScale(canvases.cvs.width/2,canvases.cvs.height/2,0,camera.zoom,canvases.buffer1cvs,canvases.ctx),2===drawMode&&(imgRotScale(canvases.cvs.width/2,canvases.cvs.height/2,camera.angle,1,canvases.buffer2cvs,canvases.buffer1ctx),imgRotScale(canvases.cvs.width/2,canvases.cvs.height/2,0,camera.zoom,canvases.buffer1cvs,canvases.ctx))}function clearCanvases(){canvases.ctx.clearRect(0,0,canvases.cvs.width,canvases.cvs.height),canvases.buffer1ctx.clearRect(0,0,canvases.buffer1cvs.width,canvases.buffer1cvs.height),canvases.buffer2ctx.clearRect(0,0,canvases.buffer2cvs.width,canvases.buffer2cvs.height)}function switchDrawMode(){switch(camera.zoom<1&&(camera.zoom=1),drawMode=0!=camera.angle?2:1!=camera.zoom?1:0){case 0:curCtx=canvases.ctx;break;case 1:curCtx=canvases.buffer1ctx;break;case 2:curCtx=canvases.buffer2ctx}}function resizeBuffers(){var e=maxCvsSize/camera.zoom,t=e+e/2;canvases.buffer2cvs.width=t,canvases.buffer2cvs.height=t,2===drawMode?(difx=(canvases.buffer2cvs.width-canvases.cvs.width)/2,dify=(canvases.buffer2cvs.height-canvases.cvs.height)/2):(difx=0,dify=0),canvases.buffer2ctx.imageSmoothingEnabled=!1}function scaleCanvases(){var e=document.getElementById("gamejsstyle");if(0==canvasScale){var t=Math.min(Math.floor(window.innerWidth/canvases.cvs.width),Math.floor(window.innerHeight/canvases.cvs.height));autoScale=t=t<1?1:t,e.innerHTML=`#game {image-rendering:pixelated;image-rendering: crisp-edges;width:${t*canvases.cvs.width}px;cursor: ${cursor.show?"crosshair":"none"};}`}else{e.innerHTML=`#game {image-rendering:pixelated;image-rendering: crisp-edges;width:${Math.floor(canvasScale*canvases.cvs.width)}px;cursor: ${cursor.show?"crosshair":"none"};}`}}function drawButtons(){let e={x:cw-16,y:16};rect(e.x,e.y,34,34,"#9c9c9c");let t=optionsHover+45;rect(e.x,e.y,32,32,`rgb(${t},${t},${t})`);let a=`rgb(${t=optionsHover+69},${t},${t})`;rect(e.x,e.y-6,26,4,a),rect(e.x-6,e.y-6,4,8,a),rect(e.x,e.y+6,26,4,a),rect(e.x+11,e.y+6,4,8,a),e.x-=33,rect(e.x,e.y,34,34,"#9c9c9c"),t=pauseHover+45,rect(e.x,e.y,32,32,`rgb(${t},${t},${t})`),a=`rgb(${t=pauseHover+69},${t},${t})`,paused?shape(e.x,e.y,[{x:-7,y:-10},{x:-7,y:10},{x:10,y:0}],a):(rect(e.x+6,e.y,6,20,a),rect(e.x-6,e.y,6,20,a))}function drawOptionsMenu(){if(optionsMenu){let e={x:cw/2-100,y:ch/2-100};rect(cw/2,ch/2,200,200,"#242424"),text("Screen Size:",e.x+2,e.y+2,"white",2);let t=optionsButtons.screenSize;rect(t.x,t.y,t.w,t.h,"#444444"),text(screenSize,e.x+145,e.y+4,"white",2),text("sfx",e.x+2,e.y+30,"white",2),rect((t=optionsButtons.sfx).x,t.y,t.w,t.h-10,"#444444"),rect(t.x-60+120*volume.sfx,t.y,8,20,"#444444"),text("bmg",e.x+2,e.y+60,"white",2),rect((t=optionsButtons.bmg).x,t.y,t.w,t.h-10,"#444444"),rect(t.x-60+120*volume.bgm,t.y,8,20,"#444444")}}var k={a:65,b:66,c:67,d:68,e:69,f:70,g:71,h:72,i:73,j:74,k:75,l:76,m:77,n:78,o:79,p:80,q:81,r:82,s:83,t:84,u:85,v:86,w:87,x:88,y:89,z:90,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57,BACKTICK:192,MINUS:189,EQUALS:187,OPENSQUARE:219,ENDSQUARE:221,SEMICOLON:186,SINGLEQUOTE:222,BACKSLASH:220,COMMA:188,PERIOD:190,SLASH:191,ENTER:13,BACKSPACE:8,TAB:9,CAPSLOCK:20,SHIFT:16,CONTROL:17,ALT:18,META:91,LEFTBACKSLASH:226,ESCAPE:27,HOME:36,END:35,PAGEUP:33,PAGEDOWN:34,DELETE:46,INSERT:45,PAUSE:19,UP:38,DOWN:40,LEFT:37,RIGHT:39,CONTEXT:93,SPACE:32,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123},keyPress=[],keyDown=[],mousePress=[],mouseDown=[],scroll=0,mousePos={x:0,y:0},preventedEvents=[!1,!0,!0];function addListenersTo(e){window.addEventListener("keydown",kdown),window.addEventListener("keyup",kup),e.addEventListener("mousedown",mdown),e.addEventListener("mouseup",mup),e.addEventListener("mousemove",mmove),e.addEventListener("contextmenu",cmenu),e.addEventListener("wheel",scrl)}function removeListenersFrom(e){window.removeEventListener("keydown",kdown),window.removeEventListener("keyup",kup),e.removeEventListener("mousedown",mdown),e.removeEventListener("mouseup",mup),e.removeEventListener("mousemove",mmove),e.removeEventListener("contextmenu",cmenu),e.removeEventListener("wheel",scrl)}function resetInput(){for(var e=0;e<keyPress.length;e++){keyPress[e]&&(keyPress[e]=0)}for(e=0;e<mousePress.length;e++){mousePress[e]&&(mousePress[e]=0)}scroll=0}function kdown(e){var t=e.keyCode;keyPress[t]=keyPress[t]==[][[]]?1:0,keyDown[t]=1,preventedEvents[0]&&e.preventDefault()}function kup(e){var t=e.keyCode;delete keyPress[t],delete keyDown[t]}function mdown(e){var t=e.button;mousePress[t]=mousePress[t]==[][[]]?1:0,mouseDown[t]=1,preventedEvents[1]&&e.preventDefault()}function mup(e){var t=e.button;delete mousePress[t],delete mouseDown[t]}function mmove(e){mousePos.x=e.offsetX/(canvasScale||autoScale),mousePos.y=e.offsetY/(canvasScale||autoScale)}function cmenu(e){preventedEvents[1]&&e.preventDefault()}function scrl(e){scroll+=e.deltaY/100*-1,preventedEvents[2]&&e.preventDefault()}function dist(e,t){let a=t.x-e.x,n=t.y-e.y;return Math.sqrt(a*a+n*n)}function circlecircle(e,t){return dist(e,t)<e.r+t.r}function circlepoint(e,t){return dist(e,t)<e.r}function rectrect(e,t){return e.x+e.w/2>=t.x-t.w/2&&e.x-e.w/2<=t.x+t.w/2&&e.y+e.h/2>=t.y-t.h/2&&e.y-e.h/2<=t.y+t.h/2}function rectpoint(e,t){return e.x+e.w/2>=t.x&&e.x-e.w/2<=t.x&&e.y+e.h/2>=t.y&&e.y-e.h/2<=t.y}function circlerect(e,t){let a=t.w/2,n=t.h/2,s=e.x-Math.max(t.x-a,Math.min(e.x,t.x+a)),o=e.y-Math.max(t.y-n,Math.min(e.y,t.y+n));return s*s+o*o<e.r*e.r}function circleOnSideRect(e,t){let a=t.w/2,n=t.h/2,s=t.x-a,o=t.x+a,r=t.y-n,c=t.y+n,i=e.x,u=e.y;if(u<r&&i>s&&i<o){return 0}if(u>c&&i>s&&i<o){return 2}if(i<s&&u>r&&u<c){return 3}if(i>o&&u>r&&u<c){return 1}{let a=0,n=dist(e,{x:s,y:r}),u=dist(e,{x:o,y:r}),l=dist(e,{x:s,y:c}),x=dist(e,{x:o,y:c});switch(Math.min(n,u,l,x)){case n:var d=-1/(m=slope(t,{x:s,y:r}));a=i<POI(m,yIntercept(t,m),d,yIntercept(e,d))?3:0;break;case u:d=-1/(m=slope(t,{x:o,y:r}));a=i<POI(m,yIntercept(t,m),d,yIntercept(e,d))?0:1;break;case l:d=-1/(m=slope(t,{x:s,y:c}));a=i<POI(m,yIntercept(t,m),d,yIntercept(e,d))?3:2;break;case x:var m;d=-1/(m=slope(t,{x:o,y:c}));a=i<POI(m,yIntercept(t,m),d,yIntercept(e,d))?2:1}return a}}function rectOnSideRect(e,t){let a=t.w/2,n=t.h/2,s=t.x-a,o=t.x+a,r=t.y-n,c=t.y+n,i=e.w/2,u=e.h/2,d=e.x,m=e.y,l=d-i,x=d+i,h=m-u,f=m+u,v=dist(t,{x:l,y:h}),p=dist(t,{x:x,y:h}),g=dist(t,{x:l,y:f}),y=dist(t,{x:x,y:f}),w=dist(t,{x:d,y:h}),A=dist(t,{x:x,y:m}),C=dist(t,{x:d,y:f}),b=dist(t,{x:l,y:m}),P=d,S=m;switch(Math.min(v,p,g,y,w,A,C,b)){case v:P-=e.w/2,S-=e.h/2;break;case p:P+=e.w/2,S-=e.h/2;break;case g:P-=e.w/2,S+=e.h/2;break;case y:P+=e.w/2,S+=e.h/2;break;case w:S-=e.h/2;break;case A:P+=e.w/2;break;case C:S+=e.h/2;break;case b:P-=e.w/2}if(S<r&&P>s&&P<o){return 0}if(S>c&&P>s&&P<o){return 2}if(P<s&&S>r&&S<c){return 3}if(P>o&&S>r&&S<c){return 1}{let e=0,a={x:P,y:S},n=dist(a,{x:s,y:r}),i=dist(a,{x:o,y:r}),u=dist(a,{x:s,y:c}),d=dist(a,{x:o,y:c});switch(Math.min(n,i,u,d)){case n:var L=-1/(M=slope(t,{x:s,y:r}));e=P<POI(M,yIntercept(t,M),L,yIntercept(a,L))?3:0;break;case i:L=-1/(M=slope(t,{x:o,y:r}));e=P<POI(M,yIntercept(t,M),L,yIntercept(a,L))?0:1;break;case u:L=-1/(M=slope(t,{x:s,y:c}));e=P<POI(M,yIntercept(t,M),L,yIntercept(a,L))?3:2;break;case d:var M;L=-1/(M=slope(t,{x:o,y:c}));e=P<POI(M,yIntercept(t,M),L,yIntercept(a,L))?2:1}return e}}function slope(e,t){return(t.y-e.y)/(t.x-e.x)}function yIntercept(e,t){return e.y-t*e.x}function POI(e,t,a,n){return x=(n-t)/(e-a),x}function ifRectOnEdgeBounce(e){let t=e.x,a=e.y,n=e.w/2,s=e.h/2;t+n>edge.right&&(e.v.x*=-1,e.x=edge.right-n),t-n<edge.left&&(e.v.x*=-1,e.x=edge.left+n),a+s>edge.bottom&&(e.v.y*=-1,e.y=edge.bottom-s),a-s<edge.top&&(e.v.y*=-1,e.y=edge.top+s)}function ifCircleOnEdgeBounce(e){let t=e.x,a=e.y,n=e.r;t+n>edge.right&&(e.v.x*=-1,e.x=edge.right-n),t-n<edge.left&&(e.v.x*=-1,e.x=edge.left+n),a+n>edge.bottom&&(e.v.y*=-1,e.y=edge.bottom-n),a-n<edge.top&&(e.v.y*=-1,e.y=edge.top+n)}var cw,ch,curCtx,maxCvsSize,drawLimitLeft,drawLimitRight,drawLimitTop,drawLimitBottom,sizeDif,loadingCircle,clickSound,canvases={cvs:null,ctx:null,buffer1cvs:null,buffer1ctx:null,buffer2cvs:null,buffer2ctx:null},camera={zoom:1,angle:0,x:0,y:0},updateFPS=60,gameStarted=!1,drawMode=0,absDraw=!1,canvasScale=1,difx=0,dify=0,seperateInputLoop=!0,edge={top:null,bottom:null,left:null,right:null},bug="🐛",loadAng=0,optionsHover=0,pauseHover=0,optionsMenu=!1,optionsButtons={},paused=!1,screenSize="1:1",autoScale=1,images=[],imagePaths=[],imgs=[],sprites={},audio=[],audioPaths=[],sounds={},abuffer=[],volumeList=[],audioLoadedLength=0,volume={sfx:1,bgm:1};cursor={sprite:null,alignment:1,show:!0},mouseOnCanvas=!1;const acceptableChars="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890_-. ",AudioContext=window.AudioContext||window.webkitAudioContext;var context,sfxVolumeNode,bmgVolumeNode;function setup(e){updateFPS=e,canvases.cvs=document.getElementById("game"),canvases.ctx=canvases.cvs.getContext("2d",{alpha:!1}),canvases.cvs.onmousedown=function(){gameStarted||(loadImagesAndSounds(),gameStarted=!0)},createCanvas("buffer1"),createCanvas("buffer2"),canvases.ctx.imageSmoothingEnabled=!1,canvases.buffer1ctx.imageSmoothingEnabled=!1,canvases.buffer2ctx.imageSmoothingEnabled=!1,maxCvsSize=Math.max(canvases.cvs.width,canvases.cvs.height),sizeDif=maxCvsSize-Math.min(canvases.cvs.width,canvases.cvs.height),cw=canvases.cvs.width,ch=canvases.cvs.height,edge={top:0,bottom:ch,left:0,right:cw},addFont(),addStyle(),addListenersTo(canvases.cvs),curCtx=canvases.ctx,requestAnimationFrame(function e(){curCtx.fillStyle="#2d2d2d";curCtx.fillRect(0,0,cw,ch);circle(cw/2,ch/2,27,"#066312");circle(cw/2,ch/2,23,"#149124");shape(cw/2,ch/2,[{x:-7,y:-15},{x:-7,y:15},{x:15,y:0}],"#47f55d");gameStarted||requestAnimationFrame(e)})}function drawLoop(){cw=canvases.cvs.width,ch=canvases.cvs.height,scaleCanvases(),switchDrawMode(),resizeBuffers(),clearCanvases();var e=0;2==drawMode&&(e=canvases.buffer2cvs.width-maxCvsSize),drawLimitLeft=-camera.x-(2==drawMode?sizeDif:0)-e,drawLimitRight=-camera.x+maxCvsSize+(2==drawMode?sizeDif:0)+e,drawLimitTop=-camera.y-(2==drawMode?sizeDif:0)-e,drawLimitBottom=-camera.y+maxCvsSize+(2==drawMode?sizeDif:0)+e,draw(),render(),curCtx=canvases.ctx,difx=0,dify=0;var t={x:camera.x,y:camera.y},a=drawMode;camera.x=0,camera.y=0,drawMode=0,absDraw=!0;try{absoluteDraw()}catch(e){}absDraw=!1,drawButtons(),drawOptionsMenu(),drawCursor(),drawMode=a,camera.x=t.x,camera.y=t.y,requestAnimationFrame(drawLoop)}function updateLoop(){0==seperateInputLoop&&handleOptionsInput(),sfxVolumeNode.gain.value=volume.sfx,bmgVolumeNode.gain.value=volume.bgm,paused||update(),0==seperateInputLoop&&resetInput()}function inputLoop(){handleOptionsInput(),paused||input(),resetInput()}document.getElementById("game").onmouseout=function(){mouseOnCanvas=!1},document.getElementById("game").onmouseover=function(){mouseOnCanvas=!0};