Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AroriaNetwork
GitHub Repository: AroriaNetwork/3kho-backup
Path: blob/main/projects/n-gon/js/simulation.js
1834 views
1
const simulation={loop(){},normalLoop(){simulation.gravity(),Engine.update(engine,simulation.delta),simulation.wipe(),simulation.textLog(),m.onGround?m.groundControl():m.airControl(),m.move(),m.look(),simulation.checks(),simulation.camera(),level.custom(),powerUps.do(),mobs.draw(),simulation.draw.cons(),simulation.draw.body(),mobs.loop(),mobs.healthBar(),m.draw(),m.hold(),level.customTopLayer(),simulation.draw.drawMapPath(),b.fire(),b.bulletRemove(),b.bulletDraw(),b.bulletDo(),simulation.drawCircle(),ctx.restore(),simulation.drawCursor()},testingLoop(){if(simulation.gravity(),Engine.update(engine,simulation.delta),simulation.wipe(),simulation.textLog(),m.onGround?m.groundControl():m.airControl(),m.move(),m.look(),simulation.checks(),simulation.camera(),level.custom(),m.draw(),m.hold(),level.customTopLayer(),simulation.draw.wireFrame(),input.fire&&m.fireCDcycle<m.cycle){m.fireCDcycle=m.cycle+15;for(let e=0,t=mob.length;e<t;e++)Vector.magnitudeSquared(Vector.sub(mob[e].position,simulation.mouseInGame))<mob[e].radius*mob[e].radius&&console.log(mob[e])}simulation.draw.cons(),simulation.draw.testing(),simulation.drawCircle(),simulation.constructCycle(),ctx.restore(),simulation.testingOutput(),simulation.drawCursor()},isTimeSkipping:!1,timeSkip(e=60){simulation.isTimeSkipping=!0;for(let t=0;t<e;t++)simulation.cycle++,m.cycle++,simulation.gravity(),Engine.update(engine,simulation.delta),m.onGround?m.groundControl():m.airControl(),m.move(),simulation.checks(),mobs.loop(),m.walk_cycle+=m.flipLegs*m.Vx,m.hold(),b.fire(),b.bulletRemove(),b.bulletDo();simulation.isTimeSkipping=!1},mouse:{x:canvas.width/2,y:canvas.height/2},mouseInGame:{x:0,y:0},g:.0024,onTitlePage:!0,isCheating:!1,isTraining:!1,paused:!1,isChoosing:!1,testing:!1,cycle:0,fpsCap:null,fpsCapDefault:72,isCommunityMaps:!1,cyclePaused:0,fallHeight:5e3,lastTimeStamp:0,delta:1e3/60,buttonCD:0,isHorizontalFlipped:!1,levelsCleared:0,difficultyMode:2,difficulty:0,dmgScale:null,healScale:1,accelScale:null,CDScale:null,isNoPowerUps:!1,pixelGraphics(){let e=ctx.getImageData(0,0,canvas.width,canvas.height),t=e.data;for(let e=t.length/2;e<t.length;e+=4)index=e%(canvas.width*canvas.height*2),t[e+0]=t[index+0],t[e+1]=t[index+1],t[e+2]=t[index+2],t[e+3]=t[index+3];for(let e=0;e<len;e++);ctx.putImageData(e,0,0)},drawCursor(){ctx.beginPath(),ctx.moveTo(simulation.mouse.x-10,simulation.mouse.y),ctx.lineTo(simulation.mouse.x+10,simulation.mouse.y),ctx.moveTo(simulation.mouse.x,simulation.mouse.y-10),ctx.lineTo(simulation.mouse.x,simulation.mouse.y+10),ctx.lineWidth=2,ctx.strokeStyle="#000",ctx.stroke()},drawList:[],drawTime:8,mobDmgColor:"rgba(255,0,0,0.7)",playerDmgColor:"rgba(0,0,0,0.7)",drawCircle(){let e=simulation.drawList.length;for(;e--;)ctx.beginPath(),ctx.arc(simulation.drawList[e].x,simulation.drawList[e].y,simulation.drawList[e].radius,0,2*Math.PI),ctx.fillStyle=simulation.drawList[e].color,ctx.fill(),simulation.drawList[e].time?simulation.drawList[e].time--:m.isBodiesAsleep||simulation.drawList.splice(e,1)},circleFlare(e,t=100){boltNum=300*e;const o=[];colors=[powerUps.research.color,powerUps.ammo.color,powerUps.heal.color,powerUps.tech.color,powerUps.field.color,powerUps.gun.color];for(let e=0;e<boltNum;++e){const e=6+20*Math.random(),t=2*Math.PI*Math.random();o.push({x:m.pos.x,y:m.pos.y,Vx:e*Math.cos(t),Vy:e*Math.sin(t),color:colors[Math.floor(Math.random()*colors.length)]})}let i=0;loop=()=>{i++<t&&requestAnimationFrame(loop);for(let e=0,t=o.length;e<t;++e)o[e].x+=o[e].Vx,o[e].y+=o[e].Vy,Math.random()<.2&&simulation.drawList.push({x:o[e].x,y:o[e].y,radius:1.5+5*Math.random(),color:o[e].color,time:Math.floor(9+25*Math.random()*Math.random())})},requestAnimationFrame(loop)},boldActiveGunHUD(){if(b.inventory.length>0){for(let e=0,t=b.inventory.length;e<t;++e)document.getElementById(b.inventory[e]).style.opacity="0.3";document.getElementById(b.activeGun)&&(document.getElementById(b.activeGun).style.opacity="1")}if(tech.isEntanglement&&document.getElementById("tech-entanglement"))if(b.inventory[0]===b.activeGun){let e=1;for(let t=0,o=b.inventory.length;t<o;t++)e*=.87;document.getElementById("tech-entanglement").innerHTML=" "+(100*(1-e)).toFixed(0)+"%"}else document.getElementById("tech-entanglement").innerHTML=" 0%"},updateGunHUD(){for(let e=0,t=b.inventory.length;e<t;++e)document.getElementById(b.inventory[e]).innerHTML=b.guns[b.inventory[e]].name+" - "+b.guns[b.inventory[e]].ammo},makeGunHUD(){const e=document.getElementById("guns");for(;e.firstChild;)e.removeChild(e.firstChild);for(let e=0,t=b.inventory.length;e<t;++e){const t=document.createElement("div");t.setAttribute("id",b.inventory[e]);let o=document.createTextNode(b.guns[b.inventory[e]].name+" - "+b.guns[b.inventory[e]].ammo);t.appendChild(o),document.getElementById("guns").appendChild(t)}simulation.boldActiveGunHUD()},updateTechHUD(){let e="";for(let t=0,o=tech.tech.length;t<o;t++)tech.tech[t].isLost?(e&&(e+="<br>"),e+=`<span style="text-decoration: line-through;">${tech.tech[t].name}</span>`):tech.tech[t].count>0&&!tech.tech[t].isNonRefundable&&(e&&(e+="<br>"),e+=tech.tech[t].name,tech.tech[t].nameInfo&&(e+=tech.tech[t].nameInfo,tech.tech[t].addNameInfo()),tech.tech[t].count>1&&(e+=` (${tech.tech[t].count}x)`));document.getElementById("tech").innerHTML=e},lastLogTime:0,isTextLogOpen:!0,makeTextLog(e,t=240){simulation.isTextLogOpen&&!build.isExperimentSelection&&(simulation.lastLogTime>m.cycle?(document.getElementById("text-log").innerHTML=document.getElementById("text-log").innerHTML+"<br>"+e,simulation.lastLogTime=m.cycle+t):(document.getElementById("text-log").innerHTML=e,document.getElementById("text-log").style.opacity=1,simulation.lastLogTime=m.cycle+t))},textLog(){simulation.lastLogTime&&simulation.lastLogTime<m.cycle&&(simulation.lastLogTime=0,document.getElementById("text-log").style.opacity=0)},nextGun(){b.inventory.length>1&&!tech.isGunCycle&&(b.inventoryGun++,b.inventoryGun>b.inventory.length-1&&(b.inventoryGun=0),simulation.switchGun())},previousGun(){b.inventory.length>1&&!tech.isGunCycle&&(b.inventoryGun--,b.inventoryGun<0&&(b.inventoryGun=b.inventory.length-1),simulation.switchGun())},switchGun(){if(tech.isLongitudinal&&"matter wave"===b.guns[b.activeGun].name)for(i=0,len=b.guns.length;i<len;i++)if("matter wave"===b.guns[i].name){b.guns[i].waves=[];break}tech.isCrouchAmmo&&(tech.isCrouchAmmo=1),b.activeGun=b.inventory[b.inventoryGun],b.guns[b.activeGun].charge&&(b.guns[b.activeGun].charge=0),simulation.updateGunHUD(),simulation.boldActiveGunHUD()},zoom:null,zoomScale:1e3,isAutoZoom:!0,setZoom(e=simulation.zoomScale){simulation.zoomScale=e,simulation.zoom=canvas.height/e},zoomTransition(e,t=2){if(simulation.isAutoZoom){const o=e-simulation.zoomScale>0;requestAnimationFrame((function n(){if(i!==level.onLevel||!1===simulation.isAutoZoom)return;if(o){if(simulation.zoomScale+=t,simulation.zoomScale>=e)return void simulation.setZoom(e)}else if(simulation.zoomScale-=t,simulation.zoomScale<=e)return void simulation.setZoom(e);simulation.setZoom(),requestAnimationFrame(n)}));const i=level.onLevel}},zoomInFactor:0,startZoomIn(e=180){simulation.zoom=0;let t=0;requestAnimationFrame((function o(){simulation.zoom+=canvas.height/simulation.zoomScale/e,t++,t<e?requestAnimationFrame(o):simulation.setZoom()}))},noCameraScroll(){m.pos.x=player.position.x,m.pos.y=playerBody.position.y-m.yOff;m.transSmoothX=canvas.width2-m.pos.x-.8*(simulation.mouse.x-canvas.width2),m.transSmoothY=canvas.height2-m.pos.y-.8*(simulation.mouse.y-canvas.height2),m.transX+=1*(m.transSmoothX-m.transX),m.transY+=1*(m.transSmoothY-m.transY)},edgeZoomOutSmooth:1,camera(){const e=simulation.mouse.x/window.innerWidth-.5,t=simulation.mouse.y/window.innerHeight-.5,o=Math.max(e*e,t*t);simulation.edgeZoomOutSmooth=.04*(1+4*o*o)+.96*simulation.edgeZoomOutSmooth,ctx.save(),ctx.translate(canvas.width2,canvas.height2),ctx.scale(simulation.zoom/simulation.edgeZoomOutSmooth,simulation.zoom/simulation.edgeZoomOutSmooth),ctx.translate(-canvas.width2+m.transX,-canvas.height2+m.transY),simulation.mouseInGame.x=(simulation.mouse.x-canvas.width2)/simulation.zoom*simulation.edgeZoomOutSmooth+canvas.width2-m.transX,simulation.mouseInGame.y=(simulation.mouse.y-canvas.height2)/simulation.zoom*simulation.edgeZoomOutSmooth+canvas.height2-m.transY},restoreCamera(){ctx.restore()},trails(){for(let e=0;e<30;e++)setTimeout((function(){simulation.wipe=function(){ctx.fillStyle=`rgba(221,221,221,${e*e*5e-4+.0025})`,ctx.fillRect(0,0,canvas.width,canvas.height)}}),150*e);setTimeout((function(){simulation.wipe=function(){ctx.clearRect(0,0,canvas.width,canvas.height)}}),4500)},wipe(){ctx.clearRect(0,0,canvas.width,canvas.height)},gravity(){function e(e,t){for(var o=0;o<e.length;o++)e[o].force.y+=e[o].mass*t}e(powerUp,simulation.g),e(body,simulation.g),player.force.y+=player.mass*simulation.g},firstRun:!0,splashReturn(){simulation.clearTimeouts(),simulation.onTitlePage=!0,document.getElementById("splash").onclick=function(){simulation.startGame()},document.getElementById("choose-grid").style.visibility="hidden",document.getElementById("choose-grid").style.opacity="0",document.getElementById("choose-background").style.visibility="hidden",document.getElementById("choose-background").style.opacity="0",document.getElementById("info").style.display="inline",document.getElementById("info").style.opacity="0",document.getElementById("experiment-button").style.display="inline",document.getElementById("experiment-button").style.opacity="0",document.getElementById("training-button").style.display="inline",document.getElementById("training-button").style.opacity="0",document.getElementById("experiment-grid").style.display="none",document.getElementById("pause-grid-left").style.display="none",document.getElementById("pause-grid-right").style.display="none",document.getElementById("splash").style.display="inline",document.getElementById("splash").style.opacity="0",document.getElementById("dmg").style.display="none",document.getElementById("health-bg").style.display="none",document.body.style.cursor="auto",setTimeout((()=>{document.getElementById("experiment-button").style.opacity="1",document.getElementById("training-button").style.opacity="1",document.getElementById("info").style.opacity="1",document.getElementById("splash").style.opacity="1"}),200)},fpsInterval:0,then:null,introPlayer(){setTimeout((()=>{document.getElementById("info").style.display="none",document.getElementById("splash").style.display="none",simulation.clearMap(),m.draw=m.drawDefault,m.spawn(),m.look=m.lookDefault,level.testing(),simulation.setZoom(),level.addToWorld(),simulation.draw.setPaths(),requestAnimationFrame((function e(){simulation.gravity(),Engine.update(engine,simulation.delta),simulation.wipe(),m.onGround?m.groundControl():m.airControl(),m.move(),m.draw(),m.hold(),simulation.draw.drawMapPath(),ctx.restore(),simulation.onTitlePage&&requestAnimationFrame(e)}))}),1e3)},startGame(e=!1,t=!1){for(simulation.isTextLogOpen=!0,simulation.clearMap(),e||(document.body.style.cursor="none",document.body.style.overflow="hidden"),t?(simulation.isTraining=!0,simulation.isNoPowerUps=!0):(simulation.isTraining=!1,simulation.isNoPowerUps=!1),simulation.onTitlePage=!1,document.getElementById("choose-grid").style.visibility="hidden",document.getElementById("choose-grid").style.opacity="0",document.getElementById("experiment-grid").style.display="none",document.getElementById("info").style.display="none",document.getElementById("experiment-button").style.display="none",document.getElementById("training-button").style.display="none",document.getElementById("splash").onclick=null,document.getElementById("splash").style.display="none",document.getElementById("dmg").style.display="inline",document.getElementById("health-bg").style.display="inline",ctx.globalCompositeOperation="source-over",ctx.shadowBlur=0,m.isShipMode?Composite.add(engine.world,[player]):(m.draw=m.drawDefault,m.spawn(),m.look=m.lookDefault),level.populateLevels(),input.endKeySensing(),b.removeAllGuns(),tech.setupAllTech(),tech.cancelCount=0,i=0,len=b.guns.length;i<len;i++)"laser"===b.guns[i].name&&b.guns[i].chooseFireMethod(),"nail gun"===b.guns[i].name&&b.guns[i].chooseFireMethod(),"super balls"===b.guns[i].name&&b.guns[i].chooseFireMethod();tech.dynamoBotCount=0,tech.nailBotCount=0,tech.laserBotCount=0,tech.orbitBotCount=0,tech.foamBotCount=0,tech.boomBotCount=0,tech.plasmaBotCount=0,tech.missileBotCount=0,simulation.isChoosing=!1,b.setFireMethod(),b.setFireCD(),powerUps.tech.choiceLog=[],powerUps.totalPowerUps=0,powerUps.research.count=0,m.setFillColors(),input.isPauseKeyReady=!0,simulation.wipe=function(){ctx.clearRect(0,0,canvas.width,canvas.height)},m.hole.isOn=!1,simulation.paused=!1,engine.timing.timeScale=1,simulation.fpsCap=simulation.fpsCapDefault,simulation.isAutoZoom=!0,simulation.makeGunHUD(),simulation.lastLogTime=0,level.onLevel=0,level.levelsCleared=0,level.setDifficulty(),simulation.difficultyMode=Number(document.getElementById("difficulty-select").value),simulation.clearNow=!0,document.getElementById("text-log").style.opacity=0,document.getElementById("fade-out").style.opacity=0,document.title="n-gon",simulation.makeTextLog("<span class='color-var'>const</span> engine <span class='color-symbol'>=</span> Engine.create(); <em>//simulation begin</em>"),simulation.makeTextLog("engine.timing.timeScale <span class='color-symbol'>=</span> 1"),document.getElementById("health").style.display="inline",document.getElementById("health-bg").style.display="inline",m.alive=!0,m.setMaxHealth(),m.health=0,m.addHealth(.25),m.drop(),m.holdingTarget=null,tech.healMaxEnergyBonus=0,m.setMaxEnergy(),m.energy=0,m.immuneCycle=0,m.setField(0),simulation.testing&&(simulation.testing=!1,simulation.loop=simulation.normalLoop,simulation.isConstructionMode&&(document.getElementById("construct").style.display="none")),simulation.isCheating=!1,simulation.firstRun=!1,build.hasExperimentalMode=!1,build.isExperimentSelection=!1,build.isExperimentRun=!1,simulation.fpsInterval=1e3/simulation.fpsCap,simulation.then=Date.now(),requestAnimationFrame(cycle)},clearTimeouts(){let e=window.setTimeout((function(){}),0);for(;e--;)window.clearTimeout(e)},clearNow:!1,clearMap(){if(m.alive){if(tech.isLongitudinal)for(i=0,len=b.guns.length;i<len;i++)if("matter wave"===b.guns[i].name){b.guns[i].waves=[];break}let e=0;for(i=0,len=bullet.length;i<len;i++)"mine"!==bullet[i].bulletType&&"laser mine"!==bullet[i].bulletType||e++;for(i=0,len=b.guns.length;i<len;i++)if("mine"===b.guns[i].name){tech.isCrouchAmmo&&(e=Math.ceil(e/2)),b.guns[i].ammo+=e,tech.ammoCap&&(b.guns[i].ammo=Math.min(tech.ammoCap,b.guns[i].ammo)),simulation.updateGunHUD();break}if(tech.isMutualism&&!tech.isEnergyHealth)for(let e=0;e<bullet.length;e++)bullet[e].isMutualismActive&&(m.health+=.005+.005*tech.isSporeWorm,m.health>m.maxHealth&&(m.health=m.maxHealth),m.displayHealth());if(tech.isEndLevelPowerUp)for(let e=0;e<powerUp.length;e++)"tech"===powerUp[e].name?tech.giveTech():"gun"===powerUp[e].name?tech.isOneGun||b.giveGuns("random"):"field"===powerUp[e].name?0===m.fieldMode&&m.setField(Math.ceil(Math.random()*(m.fieldUpgrades.length-1))):powerUp[e].effect()}simulation.lastLogTime=0,powerUps.totalPowerUps=powerUp.length;let e=m.holdingTarget?m.holdingTarget:void 0;function t(e){for(let t=0;t<e.length;++t)Matter.Composite.remove(engine.world,e[t])}tech.deathSpawnsFromBoss=0,simulation.fallHeight=3e3,m.fireCDcycle=0,m.drop(),m.hole.isOn=!1,level.zones=[],simulation.drawList=[],t(map),map=[],t(body),body=[],t(mob),mob=[],t(powerUp),powerUp=[],t(cons),cons=[],t(consBB),consBB=[],t(bullet),bullet=[],t(composite),composite=[],e&&m.alive&&(len=body.length,body[len]=Matter.Bodies.fromVertices(0,0,e.vertices,{friction:e.friction,frictionAir:e.frictionAir,frictionStatic:e.frictionStatic}),Matter.Body.setPosition(body[len],m.pos),m.isHolding=!0,m.holdingTarget=body[len],m.holdingTarget.collisionFilter.category=0,m.holdingTarget.collisionFilter.mask=0,m.definePlayerMass(m.defaultMass+m.holdingTarget.mass*m.holdingMassScale)),simulation.fpsCap=simulation.fpsCapDefault,simulation.fpsInterval=1e3/simulation.fpsCap},checks(){if(!(simulation.cycle%60||m.isBodiesAsleep)){if(m.energy>m.maxEnergy&&(m.energy=m.maxEnergy+(m.energy-m.maxEnergy)*tech.overfillDrain),tech.isFlipFlopEnergy&&m.immuneCycle<m.cycle&&(tech.isFlipFlopOn?m.immuneCycle<m.cycle&&(m.energy+=.2):(m.energy-=.01,m.energy<0&&(m.energy=0))),tech.relayIce&&tech.isFlipFlopOn)for(let e=0;e<tech.relayIce;e++)for(let e=0,t=3+Math.ceil(9*Math.random());e<t;e++)b.iceIX(2);if(m.pos.y>simulation.fallHeight){Matter.Body.setVelocity(player,{x:0,y:0}),Matter.Body.setPosition(player,{x:level.enter.x+50,y:level.enter.y-20});for(let e=0;e<bullet.length;e++)bullet[e].botType&&(Matter.Body.setPosition(bullet[e],Vector.add(player.position,{x:250*(Math.random()-.5),y:250*(Math.random()-.5)})),Matter.Body.setVelocity(bullet[e],{x:0,y:0}));m.damage(.1*simulation.difficultyMode),m.energy-=.1*simulation.difficultyMode}m.lastKillCycle+300>simulation.cycle&&(tech.isEnergyRecovery&&m.immuneCycle<m.cycle&&(m.energy+=.05*m.maxEnergy),tech.isHealthRecovery&&m.addHealth(.01*m.maxHealth)),simulation.cycle%420||(tech.isZeno&&(m.health*=.9,m.displayHealth()),tech.cyclicImmunity&&m.immuneCycle<m.cycle+tech.cyclicImmunity&&(m.immuneCycle=m.cycle+tech.cyclicImmunity),fallCheck=function(e,t=!1){let o=e.length;for(;o--;)e[o].position.y>simulation.fallHeight&&(t?(Matter.Body.setVelocity(e[o],{x:0,y:0}),Matter.Body.setPosition(e[o],{x:level.exit.x+30*(Math.random()-.5),y:level.exit.y+30*(Math.random()-.5)})):(Matter.Composite.remove(engine.world,e[o]),e.splice(o,1)))},fallCheck(mob),fallCheck(body),fallCheck(powerUp,!0))}},testingOutput(){ctx.fillStyle="#000",ctx.textAlign="center",ctx.fillText(`(${simulation.mouseInGame.x.toFixed(1)}, ${simulation.mouseInGame.y.toFixed(1)})`,simulation.mouse.x,simulation.mouse.y-20)},draw:{mapPath:null,setPaths(){simulation.draw.mapPath=new Path2D;for(let e=0,t=map.length;e<t;++e){let t=map[e].vertices;simulation.draw.mapPath.moveTo(t[0].x,t[0].y);for(let e=1;e<t.length;e+=1)simulation.draw.mapPath.lineTo(t[e].x,t[e].y);simulation.draw.mapPath.lineTo(t[0].x,t[0].y)}},drawMapPath(){ctx.fillStyle=color.map,ctx.fill(simulation.draw.mapPath)},body(){ctx.beginPath();for(let e=0,t=body.length;e<t;++e){let t=body[e].vertices;ctx.moveTo(t[0].x,t[0].y);for(let e=1;e<t.length;e++)ctx.lineTo(t[e].x,t[e].y);ctx.lineTo(t[0].x,t[0].y)}ctx.lineWidth=2,ctx.fillStyle=color.block,ctx.fill(),ctx.strokeStyle=color.blockS,ctx.stroke()},cons(){ctx.beginPath();for(let e=0,t=cons.length;e<t;++e)ctx.moveTo(cons[e].pointA.x,cons[e].pointA.y),ctx.lineTo(cons[e].bodyB.position.x+cons[e].pointB.x,cons[e].bodyB.position.y+cons[e].pointB.y);for(let e=0,t=consBB.length;e<t;++e)ctx.moveTo(consBB[e].bodyA.position.x,consBB[e].bodyA.position.y),ctx.lineTo(consBB[e].bodyB.position.x,consBB[e].bodyB.position.y);ctx.lineWidth=2,ctx.strokeStyle="rgba(0,0,0,0.15)",ctx.stroke()},wireFrame(){const e=Composite.allBodies(engine.world);ctx.beginPath();for(let t=0;t<e.length;++t){let o=e[t].vertices;ctx.moveTo(o[0].x,o[0].y);for(let e=1;e<o.length;e++)ctx.lineTo(o[e].x,o[e].y);ctx.lineTo(o[0].x,o[0].y)}ctx.lineWidth=1,ctx.strokeStyle="#000",ctx.stroke()},testing(){ctx.beginPath();let e=jumpSensor.vertices;ctx.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;++t)ctx.lineTo(e[t].x,e[t].y);ctx.lineTo(e[0].x,e[0].y),ctx.fillStyle="rgba(255, 0, 0, 0.5)",ctx.fill(),ctx.beginPath(),e=playerBody.vertices,ctx.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;++t)ctx.lineTo(e[t].x,e[t].y);ctx.lineTo(e[0].x,e[0].y),ctx.fillStyle="rgba(0, 255, 255, 0.25)",ctx.fill(),ctx.beginPath(),e=playerHead.vertices,ctx.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;++t)ctx.lineTo(e[t].x,e[t].y);ctx.lineTo(e[0].x,e[0].y),ctx.fillStyle="rgba(255, 255, 0, 0.4)",ctx.fill(),ctx.beginPath(),e=headSensor.vertices,ctx.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;++t)ctx.lineTo(e[t].x,e[t].y);ctx.lineTo(e[0].x,e[0].y),ctx.fillStyle="rgba(0, 0, 255, 0.25)",ctx.fill()}},checkLineIntersection(e,t,o,i){let n,l,a,s,m,c={x:null,y:null,onLine1:!1,onLine2:!1};return n=(i.y-o.y)*(t.x-e.x)-(i.x-o.x)*(t.y-e.y),0==n||(l=e.y-o.y,a=e.x-o.x,s=(i.x-o.x)*l-(i.y-o.y)*a,m=(t.x-e.x)*l-(t.y-e.y)*a,l=s/n,a=m/n,c.x=e.x+l*(t.x-e.x),c.y=e.y+l*(t.y-e.y),l>0&&l<1&&(c.onLine1=!0),a>0&&a<1&&(c.onLine2=!0)),c},constructMouseDownPosition:{x:0,y:0},constructMapString:[],constructCycle(){if(simulation.isConstructionMode&&simulation.constructMouseDownPosition){function e(e,t=25){return Math.ceil(e/t)*t}const t=e(simulation.constructMouseDownPosition.x),o=e(simulation.constructMouseDownPosition.y),i=Math.max(25,e(simulation.mouseInGame.x)-t),n=Math.max(25,e(simulation.mouseInGame.y)-o);ctx.strokeStyle="#000",ctx.lineWidth=2,ctx.strokeRect(t,o,i,n)}},enableConstructMode(){level.isProcedural=!1,simulation.isConstructionMode=!0,simulation.isHorizontalFlipped=!1,simulation.isAutoZoom=!1,simulation.zoomScale=2600,simulation.setZoom(),document.body.addEventListener("mouseup",(e=>{if(simulation.testing&&simulation.constructMouseDownPosition){function t(e,t=25){return Math.ceil(e/t)*t}const o=t(simulation.constructMouseDownPosition.x),i=t(simulation.constructMouseDownPosition.y),n=Math.max(25,t(simulation.mouseInGame.x)-o),l=Math.max(25,t(simulation.mouseInGame.y)-i);2===e.which?level.isProcedural?simulation.outputMapString(`spawn.randomMob(x+${o}, y+${i}, 0);`):simulation.outputMapString(`spawn.randomMob(${o}, ${i}, 0);`):simulation.mouseInGame.x>simulation.constructMouseDownPosition.x&&simulation.mouseInGame.y>simulation.constructMouseDownPosition.y&&(1===e.which?(level.isProcedural?simulation.outputMapString(`spawn.mapRect(x+${o}, y+${i}, ${n}, ${l});`):simulation.outputMapString(`spawn.mapRect(${o}, ${i}, ${n}, ${l});`),spawn.mapRect(o,i,n,l),len=map.length-1,map[len].collisionFilter.category=cat.map,map[len].collisionFilter.mask=cat.player|cat.map|cat.body|cat.bullet|cat.powerUp|cat.mob|cat.mobBullet,Matter.Body.setStatic(map[len],!0),Composite.add(engine.world,map[len]),simulation.draw.setPaths()):3===e.which&&(level.isProcedural?simulation.outputMapString(`spawn.bodyRect(x+${o}, y+${i}, ${n}, ${l});`):simulation.outputMapString(`spawn.bodyRect(${o}, ${i}, ${n}, ${l});`),spawn.bodyRect(o,i,n,l),len=body.length-1,body[len].collisionFilter.category=cat.body,body[len].collisionFilter.mask=cat.player|cat.map|cat.body|cat.bullet|cat.mob|cat.mobBullet,Composite.add(engine.world,body[len]),body[len].classType="body"))}simulation.constructMouseDownPosition.x=void 0,simulation.constructMouseDownPosition.y=void 0})),simulation.constructMouseDownPosition.x=void 0,simulation.constructMouseDownPosition.y=void 0,document.body.addEventListener("mousedown",(e=>{simulation.testing&&(simulation.constructMouseDownPosition.x=simulation.mouseInGame.x,simulation.constructMouseDownPosition.y=simulation.mouseInGame.y)})),document.body.addEventListener("keydown",(e=>{if(simulation.testing&&90===e.keyCode&&simulation.constructMapString.length){if("m"===simulation.constructMapString[simulation.constructMapString.length-1][6]){const e=map.length-1;Matter.Composite.remove(engine.world,map[e]),map.splice(e,1),simulation.draw.setPaths()}else if("b"===simulation.constructMapString[simulation.constructMapString.length-1][6]){const e=body.length-1;Matter.Composite.remove(engine.world,body[e]),body.splice(e,1)}simulation.constructMapString.pop(),simulation.outputMapString()}}))},outputMapString(e){e&&simulation.constructMapString.push(e);let t="",o="";for(let e=0,i=simulation.constructMapString.length;e<i;e++)t+=simulation.constructMapString[e],o+="<div>"+simulation.constructMapString[e]+"</div>";console.log(t),navigator.clipboard.writeText(t).then((function(){}),(function(){console.log("copy failed")})),document.getElementById("construct").innerHTML=o}};
2
3