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++){C[e]=new Array(gridsize);for(var r=0;r<gridsize;r++){C[e][r]=new Array(gridsize);for(var a=0;a<gridsize;a++)C[e][r][a]=y}}}function r(e,r){return N==e&&I==r||(b==e&&_==r||(C[e][r][1]==x||C[e][r][1]==k))}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,M.material=new THREE.MeshLambertMaterial({map:e})});var a=new THREE.TextureLoader;a.load("/uploads/seanhutchinson/golfBall2.jpg",function(e){e.minFilter=THREE.LinearFilter,O.material=new THREE.MeshLambertMaterial({map:e})});var i=new THREE.TextureLoader;i.load("/uploads/seanhutchinson/grass.jpg",function(e){e.minFilter=THREE.LinearFilter,T(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);C[r][a][1]=k;var i=randomintAtoB(5,15),n=randomintAtoB(1,2);if(1==n)for(var o=r;o<i;o++)o<gridsize&&o>0&&(C[o][a][1]=k);else for(var o=a;o<i;o++)o<gridsize&&o>0&&(C[r][o][1]=k)}}function t(){for(var e=0,r=0;r<gridsize;r++)for(var i=0;i<gridsize;i++)if(C[r][i][1]==k){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),L[e]=o,e++}}function s(e){for(var r=0;r<L.length;r++)L[r]&&(L[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||(C[e][r][1]=x)}function u(){for(var e=0,r=0;r<gridsize;r++)for(var i=0;i<gridsize;i++)if(1==C[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),A[e]=o,e++}}function E(e){for(var r=0;r<A.length;r++)A[r]&&(A[r].material=e)}function c(){for(var e=0;e<gridsize;e++)for(var r=0;r<gridsize;r++)C[e][r][0]=q}function l(){for(var e=0,r=0;r<gridsize;r++)for(var i=0;i<gridsize;i++)if(C[r][i][0]==q){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.receiveShadow=!0,threeworld.scene.add(o),B[e]=o,e++}}function T(e){for(var r=0;r<B.length;r++)B[r]&&(B[r].material=e)}function h(){var e=new THREE.DirectionalLight(16777215,1);e.position.set(4e3,6e3,2e3),e.CameraLightHelper=!0,threeworld.scene.add(e);var r=new THREE.AmbientLight(1710618);threeworld.scene.add(r);var a=new THREE.SpotLight(16777215,0,6e3,75,10);a.position.set(2e3,2e3,2e3),a.castShadow=!0;var i=new THREE.Object3D;threeworld.scene.add(a),i.position.set(0,0,0),a.target=i,threeworld.scene.add(a)}function H(){var e=a(N*squaresize),r=a(I*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 R(){N=Math.trunc(10),I=Math.trunc(10)}function w(){var e=new THREE.SphereGeometry(50,50,50);O=new THREE.Mesh(e),O.material.color.setHex(BLANKCOLOR),O.castShadow=!0,O.recieveShadow=!0,H()}function f(){var e=randomintAtoB(N-1,N+1),a=randomintAtoB(I-1,I+1);r(e,a)||(N<e?O.rotation.z+=15:N>e&&(O.rotation.z-=15),I<a?O.rotation.x+=15:I>a&&(O.rotation.x-=15),N=e,I=a)}function m(){var e=a(b*squaresize),r=a(_*squaresize),i=squaresize;M.position.x=e,M.position.y=i,M.position.z=r,threeworld.scene.add(M),threeworld.follow.copy(M.position)}function p(){b=Math.trunc(10)+1,_=Math.trunc(10)+1}function z(){var e=new THREE.BoxGeometry(squaresize,squaresize,squaresize);M=new THREE.Mesh(e),M.material.color.setHex(BLANKCOLOR),M.castShadow=!0,M.recieveShadow=!0,m()}function v(e){var a=b,i=_;e==ACTION_LEFT?a--:e==ACTION_RIGHT?a++:e==ACTION_UP?i++:e==ACTION_DOWN&&i--,r(a,i)||(b=a,_=i)}function S(){return Math.abs(N-b)<2&&Math.abs(I-_)<2}function g(){var e=U.getScore(),r="   Step: "+K+" out of "+MAXSTEPS+". Score: "+e;$("#user_span1").html(r)}var M,O,C=new Array(gridsize),A=new Array(80),B=new Array(gridsize),L=new Array(NOBOXES);const y=0,x=1,k=2,q=3;var N,I,b,_,F,G,K,U=this;this.endCondition,this.keyHandler=function(e){37==e.keyCode&&v(ACTION_LEFT),39==e.keyCode&&v(ACTION_RIGHT),38==e.keyCode&&v(ACTION_DOWN),40==e.keyCode&&v(ACTION_UP)},this.newRun=function(){document.onkeydown=this.keyHandler,this.endCondition=!1,F=0,G=0,K=0,e(),d(),c(),o(),p(),R(),true&&(BOXHEIGHT=squaresize,threeworld.init3d(startRadiusConst,maxRadiusConst,SKYCOLOR),i(),threeworld.renderer.shadowMap.enabled=!0,threeworld.renderer.shadowMapSoft=!1,console.log(threeworld.renderer),h(),u(),l(),t(),z(),w(),n())},this.getState=function(){var e=[b,_,N,I];return e},this.takeAction=function(e){K++,v(e),f(),S()?F++:G++,true&&(m(),H(),g())},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;