Code viewer for World: Project (clone by David L)

// Cloned by David L on 30 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/duarte/",OBJPATH2="/uploads/starter/",OBJNAME="merc.obj",MTLNAME="Peter_Parker.mtl",SCALE_HERO=70,SKYCOLOR=16777164,LIGHTCOLOR=16777215,MAZESIZE=[21,21],BOXHEIGHT=500,MAXPOSX=MAZESIZE[0]*BOXHEIGHT,MAXPOSY=MAZESIZE[1]*BOXHEIGHT,MAXPOS=(MAXPOSX+MAXPOSY)/2,startRadiusConst=.8*MAXPOS,skyboxConst=5*MAXPOS,maxRadiusConst=10*MAXPOS;var ENDMAZEX=0+.5*BOXHEIGHT,ENDMAZEY=0;const 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/2;var ROTATE_TIMES=2;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=Math.PI;function loadResources(){THREE.DefaultLoadingManager.addHandler(/\.tga$/i,new THREE.TGALoader);var t=new THREE.MTLLoader;t.setResourcePath(OBJPATH2),t.setPath(OBJPATH2),t.load(MTLNAME,function(t){t.preload();var o=new THREE.OBJLoader;o.setMaterials(t),o.setPath(OBJPATH),o.load(OBJNAME,function(t){theagent=t,asynchFinished()&&initScene()})})}function asynchFinished(){return!!theagent}function initScene(){theagent.position.y=-250,theagent.position.x=250,theagent.position.z=MAXPOSY/2-350,theagent.scale.multiplyScalar(SCALE_HERO),theagent.rotation.set(0,agentRotation,0),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-270,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+2*startRadiusConst*Math.sin(agentRotation),ABWorld.lookat.z=ABWorld.lookat.z+2*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_A,KEY_W,KEY_D];function ourKeys(t){return OURKEYS.includes(t.keyCode)}function keyHandler(t){if(!AB.runReady)return!0;if(!ourKeys(t))return!0;console.log("==============================================================================================================================================================================================PRESSED");var o=Math.round(Math.sin(agentRotation)),e=Math.round(Math.cos(agentRotation)),n=!1,a=translateX(theagent.position.x),i=(translateY(theagent.position.z),translateX(theagent.position.x+AGENT_STEP*o)),r=translateY(theagent.position.z+AGENT_STEP*e);if(threeworld.scene.traverse(function(t){if(theagent.position.x+3*AGENT_STEP>t.position.x&&theagent.position.x-3*AGENT_STEP<t.position.x&&theagent.position.z-3*AGENT_STEP<t.position.z&&theagent.position.z+3*AGENT_STEP>t.position.z&&(theagent.position.x!=t.position.x||theagent.position.y!=t.position.y||theagent.position.z!=t.position.z)){var o=Math.round(translateX(t.position.x)),e=Math.round(translateY(t.position.z));0===ROTATE_TIMES&&((r-e>=0||r-e<-50)&&(i-o>=0||i-o<=-50)||(n=!0)),2!=ROTATE_TIMES&&-2!=ROTATE_TIMES||(r-e<=0||r-e>50)&&(i-o<=0||i-o>=-50)||(n=!0),1!=ROTATE_TIMES&&-3!=ROTATE_TIMES||50==a&&i-o==-50||(i-o>=0||i-o<-50)&&(r-e<=0||r-e>=-50)||(n=!0),3!=ROTATE_TIMES&&-1!=ROTATE_TIMES||(i-o>=0||i-o<-50)&&(r-e<=0||r-e>=-50)||(n=!0)}}),t.keyCode!=KEY_LEFT&&t.keyCode!=KEY_A||(agentRotation+=ROTATE_AMOUNT,theagent.rotation.set(0,agentRotation,0),ROTATE_TIMES-=1),t.keyCode!=KEY_RIGHT&&t.keyCode!=KEY_D||(agentRotation-=ROTATE_AMOUNT,theagent.rotation.set(0,agentRotation,0),ROTATE_TIMES+=1),4!=ROTATE_TIMES&&-4!=ROTATE_TIMES||(ROTATE_TIMES=0),t.keyCode==KEY_UP||t.keyCode==KEY_W){if(n)return setLookatFollow(),!0;theagent.position.x=theagent.position.x+AGENT_STEP*Math.sin(agentRotation),theagent.position.z=theagent.position.z+AGENT_STEP*Math.cos(agentRotation)}return setLookatFollow(),t.stopPropagation(),t.preventDefault(),!1}function translateX(t){return t-MAXPOSX/2}function translateY(t){return t-MAXPOSY/2}function initMaze(t){function o(t,o,e,n){var a=new THREE.PlaneGeometry(BOXHEIGHT,BOXHEIGHT),i=new THREE.Mesh(a);i.material.color.setHex(n),i.material.side=THREE.DoubleSide,i.material.alphaTest=.8,i.position.x=translateX((t+(e?-.5:0))*BOXHEIGHT),i.position.z=translateY((o+(e?-.5:0))*BOXHEIGHT),e&&(i.rotation.y=Math.PI/2),threeworld.scene.add(i)}t.map(function(e,n){t[n][0].door[0].open||o(n,-1,0,16755200),t[n].map(function(e,a){t[n][a].door[3].open||o(n,a,1,65280),t[n][a].door[2].open||o(n,a,0,255)})}),t[0].map(function(e,n){t[t.length-1][n].door[1].open||o(t.length,n,1,16579836)}),o(11,21,0,11372973),o(11,21,1,11372973),o(12,21,1,11372973);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(10027008),a.material.side=THREE.DoubleSide,a.position.x=0+.5*BOXHEIGHT,a.position.z=0,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]),MAZE[11][20].door[2].open=!0,loadResources(),initMaze(MAZE);var t=new THREE.AmbientLight;ABWorld.scene.add(t);var o=new THREE.DirectionalLight(16777215,3);o.position.set(startRadiusConst,startRadiusConst,startRadiusConst),ABWorld.scene.add(o),document.onkeydown=keyHandler},AB.world.nextStep=function(){};var labyrinthe={axis:[[0,-1],[1,0],[0,1],[-1,0]],create:function(t,o){for(var e=new Array,n=0;n<t;n++){e[n]=Array();for(var a=0;a<o;a++)e[n][a]={door:[Object({open:!1}),Object({open:!1}),Object({open:!1}),Object({open:!1})],boundDoor:[]}}this.setRandomValue(e);for(var i=0;i<e.length*e[0].length-1;i+=labyrinthe.generate(e,Math.floor(Math.random()*e.length),Math.floor(Math.random()*e[0].length))?1:0);return e},propagate:function(t,o,e,n){t[o][e].value=n,this.axis.forEach(function(a,i){var r={x:o+a[0],y:e+a[1]};void 0!==t[o][e].door[i]&&t[o][e].door[i].open&&r.x>=0&&r.x<t.length&&r.y>=0&&r.y<t[0].length&&!t[r.x][r.y].visited&&t[r.x][r.y].value!=t[o][e].value&&this.propagate(t,r.x,r.y,n)},this)},generate:function(t,o,e,n){t[o][e].visited=!0;var a=Array(),i=Array();if(this.axis.forEach(function(n,r){var s=o+n[0],E=e+n[1];void 0!==t[o][e].door[r]&&s>=0&&s<t.length&&E>=0&&E<t[0].length&&!t[s][E].visited&&(t[o][e].door[r].open?a.push(r):t[s][E].value!==t[o][e].value&&i.push(r))}),a.length>=1&&Math.floor(Math.random()*(a.length+i.length))<=a.length)for(;a.length;){var r=Math.floor(Math.random()*a.length);if(this.generate(t,this.axis[a[r]][0]+o,this.axis[a[r]][1]+e))return t[o][e].visited=!1,!0;a=a.slice(0,r).concat(a.slice(r+1))}if(i.length){var s=Math.floor(Math.random()*i.length);return this.propagate(t,this.axis[i[s]][0]+o,this.axis[i[s]][1]+e,t[o][e].value),t[o][e].door[i[s]].open=!0,t[o+this.axis[i[s]][0]][e+this.axis[i[s]][1]].door[(i[s]+2)%4].open=!0,t[o][e].visited=!1,!0}return t[o][e].visited=!1,!1},setRandomValue:function(t){for(var o=Array(),e=0;e<t.length*t[0].length;e++)o.push(e);t.forEach(function(t){t.forEach(function(t){var e=Math.floor(Math.random()*o.length);t.value=o[e],t.visited=!1,o=o.slice(0,e).concat(o.slice(e+1))})})},print:function(t){var o="n";return t[0].map(function(e,n){o+=t[n][0].door[0].open?"  ":" _"}),o+="n",t.map(function(e,n){t[n].map(function(e,a){o+=t[a][n].door[3].open?" ":"|",o+=t[a][n].door[2].open?" ":"_"}),o+=t[t.length-1][n].door[1].open?" ":"|n"}),o}};