Code viewer for World: Project (clone by Przemysl...

// Cloned by Przemyslaw Majda on 29 Nov 2022 from World "Project" by Duarte Martinho 
// Please leave this clone trail here.
 
var EnforceCameraMove=!1;AB.clockTick=100,AB.maxSteps=1e4,AB.screenshotStep=100,AB.drawRunControls=!1,ABWorld.drawCameraControls=!0;const OBJPATH="/uploads/starter/",OBJNAME="Peter_Parker.obj",MTLNAME="Peter_Parker.mtl",SCALE_HERO=70,SKYCOLOR=16777164,LIGHTCOLOR=16777215,MAZESIZE=[25,25],BOXHEIGHT=500,MAXPOSX=MAZESIZE[0]*BOXHEIGHT,MAXPOSY=MAZESIZE[1]*BOXHEIGHT,MAXPOS=(MAXPOSX+MAXPOSY)/2,startRadiusConst=.8*MAXPOS,skyboxConst=3*MAXPOS,maxRadiusConst=10*MAXPOS,AGENT_STEP=100,FOLLOW_Y=4*SCALE_HERO,LOOKAT_Y=40,CAMERASHIFT=2*-SCALE_HERO;ABHandler.MAXCAMERAPOS=maxRadiusConst,ABHandler.GROUNDZERO=!1;const ROTATE_AMOUNT=Math.PI/4;var ROTATE_TIMES=0;const SKYBOX_ARRAY=["/uploads/duarte/px_skybox.png","/uploads/duarte/nx_skybox.png","/uploads/duarte/py_skybox.png","/uploads/duarte/ny_skybox.png","/uploads/duarte/pz_skybox.png","/uploads/duarte/nz_skybox.png"];var theagent,agentRotation=0;function loadResources(){THREE.DefaultLoadingManager.addHandler(/\.tga$/i,new THREE.TGALoader);var o=new THREE.MTLLoader;o.setResourcePath(OBJPATH),o.setPath(OBJPATH),o.load(MTLNAME,function(o){o.preload();var t=new THREE.OBJLoader;t.setMaterials(o),t.setPath(OBJPATH),t.load(OBJNAME,function(o){theagent=o,asynchFinished()&&initScene()})})}function asynchFinished(){return!!theagent}function initScene(){theagent.position.y=-250,theagent.position.x=250,theagent.position.z=0,theagent.scale.multiplyScalar(SCALE_HERO),ABWorld.scene.add(theagent),setLookatFollow(),EnforceCameraMove&&ABWorld.cameraMove(),ABWorld.scene.background=(new THREE.CubeTextureLoader).load(SKYBOX_ARRAY,function(){ABWorld.render(),AB.removeLoading(),AB.runReady=!0})}function setLookatFollow(){ABWorld.follow.copy(theagent.position),ABWorld.follow.y=FOLLOW_Y-250,ABWorld.follow.x=ABWorld.follow.x+CAMERASHIFT*Math.sin(agentRotation),ABWorld.follow.z=ABWorld.follow.z+CAMERASHIFT*Math.cos(agentRotation),ABWorld.lookat.copy(theagent.position),ABWorld.lookat.y=LOOKAT_Y,ABWorld.lookat.x=ABWorld.lookat.x+3*startRadiusConst*Math.sin(agentRotation),ABWorld.lookat.z=ABWorld.lookat.z+3*startRadiusConst*Math.cos(agentRotation)}const KEY_UP=38,KEY_LEFT=37,KEY_RIGHT=39,KEY_DOWN=40,KEY_A=65,KEY_W=87,KEY_S=83,KEY_D=68;var OURKEYS=[KEY_UP,KEY_LEFT,KEY_RIGHT,KEY_DOWN,KEY_A,KEY_W,KEY_S,KEY_D];function ourKeys(o){return OURKEYS.includes(o.keyCode)}function distanceVectorMoveW(o,t){var e=Math.round(Math.sin(agentRotation)),n=Math.round(Math.cos(agentRotation)),a=t.x-o.x+1.2*AGENT_STEP*e,r=t.y-o.y,i=t.z-o.z+1.2*AGENT_STEP*n;return Math.round(Math.sqrt(a*a+r*r+i*i)*Math.sqrt(a*a+r*r+i*i)/1e3)}function keyHandler(o){if(!AB.runReady)return!0;if(!ourKeys(o))return!0;console.log("PRESSED"),console.log("BEFORE"),console.log(ROTATE_TIMES),console.log(ROTATE_TIMES%6);return threeworld.scene.traverse(function(o){theagent.position.x+1.5*AGENT_STEP>o.position.x&&theagent.position.x-1.5*AGENT_STEP<o.position.x&&theagent.position.z-1.5*AGENT_STEP<o.position.z&&theagent.position.z+1.5*AGENT_STEP>o.position.z&&(theagent.position.x!=o.position.x||theagent.position.y!=o.position.y||(theagent.position.z,o.position.z))}),setLookatFollow(),o.keyCode!=KEY_LEFT&&o.keyCode!=KEY_A||(agentRotation+=ROTATE_AMOUNT,theagent.rotation.set(0,agentRotation,0),ROTATE_TIMES-=1),o.keyCode!=KEY_RIGHT&&o.keyCode!=KEY_D||(agentRotation-=ROTATE_AMOUNT,theagent.rotation.set(0,agentRotation,0),ROTATE_TIMES+=1),8!=ROTATE_TIMES&&-8!=ROTATE_TIMES||(ROTATE_TIMES=0),console.log("AFTER"),console.log(ROTATE_TIMES),console.log(ROTATE_TIMES%8),o.keyCode!=KEY_UP&&o.keyCode!=KEY_W||(theagent.position.x=theagent.position.x+AGENT_STEP*Math.sin(agentRotation),theagent.position.z=theagent.position.z+AGENT_STEP*Math.cos(agentRotation)),o.keyCode!=KEY_DOWN&&o.keyCode!=KEY_S||(theagent.position.x=theagent.position.x-AGENT_STEP*Math.sin(agentRotation),theagent.position.z=theagent.position.z-AGENT_STEP*Math.cos(agentRotation)),o.stopPropagation(),o.preventDefault(),!1}function translateX(o){return o-MAXPOSX/2}function translateY(o){return o-MAXPOSY/2}function initMaze(o){function t(o,t,e,n){var a=new THREE.PlaneGeometry(BOXHEIGHT,BOXHEIGHT),r=new THREE.Mesh(a);r.material.color.setHex(n),r.material.side=THREE.DoubleSide,r.material.alphaTest=.8,r.position.x=translateX((o+(e?-.5:0))*BOXHEIGHT),r.position.z=translateY((t+(e?-.5:0))*BOXHEIGHT),e&&(r.rotation.y=Math.PI/2),threeworld.scene.add(r)}o.map(function(e,n){o[n][0].door[0].open||t(n,-1,0,16755200),o[n].map(function(e,a){o[n][a].door[3].open||t(n,a,1,65280),o[n][a].door[2].open||t(n,a,0,255)})}),o[0].map(function(e,n){o[o.length-1][n].door[1].open||t(o.length,n,1,16579836)});var e=new THREE.PlaneGeometry(BOXHEIGHT*MAZESIZE[0],BOXHEIGHT*MAZESIZE[1]),n=new THREE.Mesh(e);n.material.color.setHex(16777215),n.material.side=THREE.DoubleSide,n.position.x=-.5*BOXHEIGHT,n.position.z=-BOXHEIGHT,n.position.y=.5*-BOXHEIGHT,n.rotation.x=Math.PI/2,e=new THREE.PlaneGeometry(BOXHEIGHT,BOXHEIGHT);var a=new THREE.Mesh(e);a.material.color.setHex(65280),a.material.side=THREE.DoubleSide,a.position.x=translateX(o.end.x*BOXHEIGHT),a.position.z=translateY((o.end.y-.5)*BOXHEIGHT),a.position.y=.5*-BOXHEIGHT,a.rotation.x=Math.PI/2,threeworld.scene.add(a)}AB.world.newRun=function(){AB.runReady=!1,AB.loadingScreen(),ABWorld.init3d(startRadiusConst,maxRadiusConst,16777164),MAZE=labyrinthe.create(MAZESIZE[0],MAZESIZE[1]);var o=Math.random()>.5;MAZE.end={x:o?Math.random()>.5?MAZESIZE[0]:-1:Math.floor(Math.random()*MAZESIZE[0]),y:o?Math.floor(Math.random()*MAZESIZE[1]):Math.random()>.5?MAZESIZE[1]:-1},MAZE[o?-1==MAZE.end.x?0:MAZESIZE[0]-1:MAZE.end.x][o?MAZE.end.y:-1==MAZE.end.y?0:MAZESIZE[1]-1].door[o?-1==MAZE.end.x?3:1:-1==MAZE.end.y?0:2].open=!0,initMaze(MAZE),loadResources();var t=new THREE.AmbientLight;ABWorld.scene.add(t);var e=new THREE.DirectionalLight(16777215,3);e.position.set(startRadiusConst,startRadiusConst,startRadiusConst),ABWorld.scene.add(e),document.onkeydown=keyHandler},AB.world.nextStep=function(){};var labyrinthe={axis:[[0,-1],[1,0],[0,1],[-1,0]],create:function(o,t){for(var e=new Array,n=0;n<o;n++){e[n]=Array();for(var a=0;a<t;a++)e[n][a]={door:[Object({open:!1}),Object({open:!1}),Object({open:!1}),Object({open:!1})],boundDoor:[]}}this.setRandomValue(e);for(var r=0;r<e.length*e[0].length-1;r+=labyrinthe.generate(e,Math.floor(Math.random()*e.length),Math.floor(Math.random()*e[0].length))?1:0);return e},propagate:function(o,t,e,n){o[t][e].value=n,this.axis.forEach(function(a,r){var i={x:t+a[0],y:e+a[1]};void 0!==o[t][e].door[r]&&o[t][e].door[r].open&&i.x>=0&&i.x<o.length&&i.y>=0&&i.y<o[0].length&&!o[i.x][i.y].visited&&o[i.x][i.y].value!=o[t][e].value&&this.propagate(o,i.x,i.y,n)},this)},generate:function(o,t,e,n){o[t][e].visited=!0;var a=Array(),r=Array();if(this.axis.forEach(function(n,i){var s=t+n[0],E=e+n[1];void 0!==o[t][e].door[i]&&s>=0&&s<o.length&&E>=0&&E<o[0].length&&!o[s][E].visited&&(o[t][e].door[i].open?a.push(i):o[s][E].value!==o[t][e].value&&r.push(i))}),a.length>=1&&Math.floor(Math.random()*(a.length+r.length))<=a.length)for(;a.length;){var i=Math.floor(Math.random()*a.length);if(this.generate(o,this.axis[a[i]][0]+t,this.axis[a[i]][1]+e))return o[t][e].visited=!1,!0;a=a.slice(0,i).concat(a.slice(i+1))}if(r.length){var s=Math.floor(Math.random()*r.length);return this.propagate(o,this.axis[r[s]][0]+t,this.axis[r[s]][1]+e,o[t][e].value),o[t][e].door[r[s]].open=!0,o[t+this.axis[r[s]][0]][e+this.axis[r[s]][1]].door[(r[s]+2)%4].open=!0,o[t][e].visited=!1,!0}return o[t][e].visited=!1,!1},setRandomValue:function(o){for(var t=Array(),e=0;e<o.length*o[0].length;e++)t.push(e);o.forEach(function(o){o.forEach(function(o){var e=Math.floor(Math.random()*t.length);o.value=t[e],o.visited=!1,t=t.slice(0,e).concat(t.slice(e+1))})})},print:function(o){var t="n";return o[0].map(function(e,n){t+=o[n][0].door[0].open?"  ":" _"}),t+="n",o.map(function(e,n){o[n].map(function(e,a){t+=o[a][n].door[3].open?" ":"|",t+=o[a][n].door[2].open?" ":"_"}),t+=o[o.length-1][n].door[1].open?" ":"|n"}),t}};