Code viewer for World: Cloned A BEAUTIFUL WORK IN...
function randomfloatAtoB(e,r){return e+Math.random()*(r-e)}function randomintAtoB(e,r){return Math.round(randomfloatAtoB(e,r))}function randomBoolean(){return!(Math.random()<.5)}function World(){function e(){for(var e=0;e<gridsize;e++){A[e]=new Array(gridsize);for(var r=0;r<gridsize;r++){A[e][r]=new Array(gridsize);for(var a=0;a<gridsize;a++)A[e][r][a]=C}}}function r(e,r){return k==e&&b==r||(F==e&&_==r||(A[e][r][1]==q||A[e][r][1]==N))}function a(e){return e-1e3}function i(){var e=[new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/seanhutchinson/skyrender0001.bmp"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/seanhutchinson/skyrender0004.bmp"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/seanhutchinson/skyrender0003.bmp"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/seanhutchinson/skyrender0006.bmp"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/seanhutchinson/skyrender0005.bmp"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/seanhutchinson/skyrender0002.bmp"),side:THREE.BackSide})],r=new THREE.CubeGeometry(skyboxConst,skyboxConst,skyboxConst),a=new THREE.MeshFaceMaterial(e),i=new THREE.Mesh(r,a);threeworld.scene.add(i)}function n(){var e=new THREE.TextureLoader;e.load("/uploads/seanhutchinson/Brick-2378.jpg",function(e){e.minFilter=THREE.LinearFilter,E(new THREE.MeshLambertMaterial({map:e}))});var r=new THREE.TextureLoader;r.load("/uploads/starter/pacman.jpg",function(e){e.minFilter=THREE.LinearFilter,g.material=new THREE.MeshBasicMaterial({map:e})});var a=new THREE.TextureLoader;a.load("/uploads/starter/ghost.3.png",function(e){e.minFilter=THREE.LinearFilter,O.material=new THREE.MeshBasicMaterial({map:e})});var i=new THREE.TextureLoader;i.load("/uploads/seanhutchinson/grass.jpg",function(e){e.minFilter=THREE.LinearFilter,h(new THREE.MeshLambertMaterial({map:e}))});var i=new THREE.TextureLoader;i.load("/uploads/seanhutchinson/Brick-2378.jpg",function(e){e.minFilter=THREE.LinearFilter,s(new THREE.MeshLambertMaterial({map:e}))})}function o(){for(var e=1;e<=NOBOXES;e++){var r=randomintAtoB(1,19),a=randomintAtoB(1,19);A[r][a][1]=N;var i=randomintAtoB(5,15),n=randomintAtoB(1,2);if(1==n)for(var o=r;o<i;o++)o<gridsize&&o>0&&(A[o][a][1]=N);else for(var o=a;o<i;o++)o<gridsize&&o>0&&(A[r][o][1]=N)}}function t(){for(var e=0,r=0;r<gridsize;r++)for(var i=0;i<gridsize;i++)if(A[r][i][1]==N){var n=new THREE.BoxGeometry(squaresize,BOXHEIGHT,squaresize),o=new THREE.Mesh(n);o.material.color.setHex(BLANKCOLOR),o.position.x=a(r*squaresize),o.position.z=a(i*squaresize),o.position.y=squaresize,o.castShadow=!0,o.receiveShadow=!0,threeworld.scene.add(o),y[e]=o,e++}}function s(e){for(var r=0;r<y.length;r++)y[r]&&(y[r].material=e)}function d(){for(var e=0;e<gridsize;e++)for(var r=0;r<gridsize;r++)0!=e&&19!=e&&0!=r&&19!=r||(A[e][r][1]=q)}function u(){for(var e=0,r=0;r<gridsize;r++)for(var i=0;i<gridsize;i++)if(1==A[r][i][1]){var n=new THREE.BoxGeometry(squaresize,squaresize,squaresize),o=new THREE.Mesh(n);o.material.color.setHex(BLANKCOLOR),o.position.x=a(r*squaresize),o.position.z=a(i*squaresize),o.position.y=squaresize,o.castShadow=!0,o.receiveShadow=!0,threeworld.scene.add(o),L[e]=o,e++}}function E(e){for(var r=0;r<L.length;r++)L[r]&&(L[r].material=e)}function c(){for(var e=0;e<gridsize;e++)for(var r=0;r<gridsize;r++)A[e][r][0]=I}function l(){for(var e=0,r=0;r<gridsize;r++)for(var i=0;i<gridsize;i++)if(A[r][i][0]==I){var n=new THREE.BoxGeometry(squaresize,squaresize,squaresize),o=new THREE.Mesh(n);o.material.color.setHex(BLANKCOLOR),o.position.x=a(r*squaresize),o.position.z=a(i*squaresize),o.position.y=0,o.castShadow=!0,o.receiveShadow=!0,threeworld.scene.add(o),x[e]=o,e++}}function h(e){for(var r=0;r<x.length;r++)x[r]&&(x[r].material=e)}function T(){var e=new THREE.SpotLight(16777215);e.position.set(100,1500,100),e.castShadow=!0,threeworld.renderer.shadowMap.enabled=!0,e.shadow.mapSize.width=1024,e.shadow.mapSize.height=1024,e.shadow.camera.near=500,e.shadow.camera.far=4e3,e.shadow.camera.fov=30,threeworld.scene.add(e)}function H(){var e=new THREE.JSONLoader;e.load("/uploads/seanhutchinson/Sporty_Man.json",function(e){var r=new THREE.Mesh(e,new THREE.MeshBasicMaterial);r.position.x=g.position.x,r.position.y=g.position.y,r.position.z=g.position.z,r.scale.set(10,10,10),threeworld.scene.add(r)})}function p(){var e=a(k*squaresize),r=a(b*squaresize),i=squaresize;O.position.x=e,O.position.y=i,O.position.z=r,threeworld.scene.add(O),threeworld.lookat.copy(O.position)}function w(){k=Math.trunc(10),b=Math.trunc(10)}function R(){var e=new THREE.BoxGeometry(squaresize,squaresize,squaresize);O=new THREE.Mesh(e),O.material.color.setHex(BLANKCOLOR),p()}function f(){var e=randomintAtoB(k-1,k+1),a=randomintAtoB(b-1,b+1);r(e,a)||(k=e,b=a)}function m(){var e=a(F*squaresize),r=a(_*squaresize),i=squaresize;g.position.x=e,g.position.y=i,g.position.z=r,threeworld.scene.add(g),threeworld.follow.copy(g.position)}function z(){F=Math.trunc(10)+1,_=Math.trunc(10)+1}function M(){var e=new THREE.BoxGeometry(squaresize,squaresize,squaresize);g=new THREE.Mesh(e),g.material.color.setHex(BLANKCOLOR),m()}function v(e){var a=F,i=_;e==ACTION_LEFT?a--:e==ACTION_RIGHT?a++:e==ACTION_UP?i++:e==ACTION_DOWN&&i--,r(a,i)||(F=a,_=i)}function S(){return Math.abs(k-F)<2&&Math.abs(b-_)<2}function B(){var e=X.getScore(),r="   Step: "+U+" out of "+MAXSTEPS+". Score: "+e;$("#user_span1").html(r)}var g,O,A=new Array(gridsize),L=new Array(80),x=new Array(gridsize),y=new Array(NOBOXES);const C=0,q=1,N=2,I=3;var k,b,F,_,K,G,U,X=this;this.endCondition,this.newRun=function(){this.endCondition=!1,K=0,G=0,U=0,e(),d(),c(),o(),z(),w(),true&&(BOXHEIGHT=squaresize,threeworld.init3d(startRadiusConst,maxRadiusConst,SKYCOLOR),i(),threeworld.renderer.shadowMap.enabled=!0,threeworld.renderer.shadowMapSoft=!0,console.log(THREE),T(),u(),l(),t(),M(),R(),H(),n())},this.getState=function(){var e=[F,_,k,b];return e},this.takeAction=function(e){U++,v(e),f(),S()?K++:G++,true&&(m(),p(),B())},this.endRun=function(){},this.getScore=function(){return G}}const CLOCKTICK=100,MAXSTEPS=1e3,gridsize=20,NOBOXES=Math.trunc(28),squaresize=100,MAXPOS=2e3,SKYCOLOR=16777164,BLANKCOLOR=SKYCOLOR,startRadiusConst=1600,skyboxConst=2e5,maxRadiusConst=2e5,show3d=!0,ACTION_LEFT=0,ACTION_RIGHT=1,ACTION_UP=2,ACTION_DOWN=3,ACTION_STAYSTILL=4;