Code viewer for World: Cloned Two Player Tron
function randomfloatAtoB(e,a){return e+Math.random()*(a-e)}function randomintAtoB(e,a){return Math.round(randomfloatAtoB(e,a))}function randomBoolean(){return!(Math.random()<.5)}function World(){function e(){for(var e=0;e<gridsize;e++){W[e]=new Array(gridsize);for(var a=0;a<gridsize;a++)W[e][a]=GRID_BLANK}}function a(e,a){return y==e&&w==a||(g==e&&B==a||(W[e][a]==GRID_WALL||W[e][a]==GRID_MAZE))}function n(e){return e-40}function i(){var e=[new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/smythc44/blackngreen.jpg"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/smythc44/blackngreen.jpg"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/smythc44/blackngreen.jpg"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/smythc44/floor.jpg"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/smythc44/blackngreen.jpg"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/smythc44/blackngreen.jpg"),side:THREE.BackSide})],a=new THREE.CubeGeometry(skyboxConst,skyboxConst,skyboxConst),n=new THREE.MeshFaceMaterial(e),i=new THREE.Mesh(a,n);threeworld.scene.add(i)}function t(){var e=new THREE.TextureLoader;e.load("/uploads/starter/door.jpg",function(e){e.minFilter=THREE.LinearFilter,s(new THREE.MeshBasicMaterial({map:e}))});var a=new THREE.TextureLoader;a.load("/uploads/starter/latin.jpg",function(e){e.minFilter=THREE.LinearFilter,paintMaze(new THREE.MeshBasicMaterial({map:e}))});var n=new THREE.TextureLoader;n.load("/uploads/smythc44/tronwhite.jpg",function(e){e.minFilter=THREE.LinearFilter,f.material=new THREE.MeshBasicMaterial({map:e})});var i=new THREE.TextureLoader;i.load("/uploads/smythc44/tronorange.png",function(e){e.minFilter=THREE.LinearFilter,L.material=new THREE.MeshBasicMaterial({map:e})})}function r(){for(var e=0;e<gridsize;e++)for(var a=0;a<gridsize;a++)0!=e&&39!=e&&0!=a&&39!=a||(W[e][a]=GRID_WALL)}function o(){for(var e=0,a=0;a<gridsize;a++)for(var i=0;i<gridsize;i++)if(W[a][i]==GRID_WALL){var t=new THREE.BoxGeometry(squaresize,H,squaresize),r=new THREE.Mesh(t);r.material.color.setHex(BLANKCOLOR),r.position.x=n(a*squaresize),r.position.z=n(i*squaresize),r.position.y=0,threeworld.scene.add(r),D[e]=r,e++}}function s(e){for(var a=0;a<D.length;a++)D[a]&&(D[a].material=e)}function T(e,a){var i=new THREE.BoxGeometry(squaresize,H,squaresize),t=new THREE.Mesh(i);t.material.color.setHex(16777215),t.position.x=n(e*squaresize),t.position.z=n(a*squaresize),t.position.y=0,threeworld.scene.add(t)}function u(e,a){var i=new THREE.BoxGeometry(squaresize,H,squaresize),t=new THREE.Mesh(i);t.material.color.setHex(16737792),t.position.x=n(e*squaresize),t.position.z=n(a*squaresize),t.position.y=0,threeworld.scene.add(t)}function d(){var e=n(y*squaresize),a=n(w*squaresize),i=0;L.position.x=e,L.position.y=i,L.position.z=a,threeworld.scene.add(L),threeworld.lookat.copy(L.position)}function c(){y=4,w=20,v=y-1,x=w}function E(){var e=new THREE.BoxGeometry(squaresize,H,squaresize);L=new THREE.Mesh(e),L.material.color.setHex(BLANKCOLOR),d()}function l(e){var n=y,i=w;e==ACTION_LEFT&&n--,e==ACTION_RIGHT&&n++,e==ACTION_UP&&i++,e==ACTION_DOWN&&i--,a(n,i)||(v=y,x=w,y=n,w=i,W[v][x]=GRID_MAZE,u(v,x))}function h(){var e=ACTION_STAYSTILL;v<y&&(e=ACTION_RIGHT),x<w&&(e=ACTION_UP),y<v&&(e=ACTION_LEFT),w<x&&(e=ACTION_DOWN),l(e)}function R(){var e=n(g*squaresize),a=n(B*squaresize),i=0;f.position.x=e,f.position.y=i,f.position.z=a,threeworld.scene.add(f),threeworld.follow.copy(f.position)}function I(){g=35,B=20,M=g+1,z=B}function O(){var e=new THREE.BoxGeometry(squaresize,H,squaresize);f=new THREE.Mesh(e),f.material.color.setHex(BLANKCOLOR),R()}function A(e){var n=g,i=B;e==ACTION_LEFT&&n--,e==ACTION_RIGHT&&n++,e==ACTION_UP&&i++,e==ACTION_DOWN&&i--,a(n,i)||(M=g,z=B,g=n,B=i,W[M][z]=GRID_MAZE,T(M,z))}function C(){var e=ACTION_STAYSTILL;M<g&&(e=ACTION_RIGHT),z<B&&(e=ACTION_UP),g<M&&(e=ACTION_LEFT),B<z&&(e=ACTION_DOWN),A(e)}function m(e){var a=ACTION_STAYSTILL,n=ACTION_STAYSTILL;37==e.keyCode&&(a=ACTION_LEFT),38==e.keyCode&&(a=ACTION_DOWN),39==e.keyCode&&(a=ACTION_RIGHT),40==e.keyCode&&(a=ACTION_UP),A(a),83==e.keyCode&&(n=ACTION_UP),65==e.keyCode&&(n=ACTION_LEFT),87==e.keyCode&&(n=ACTION_DOWN),68==e.keyCode&&(n=ACTION_RIGHT),l(n)}function N(){return Math.abs(y-g)<2&&Math.abs(w-B)<2}function p(){var e=ACTION_STAYSTILL;v<y&&(e=ACTION_RIGHT),x<w&&(e=ACTION_UP),y<v&&(e=ACTION_LEFT),w<x&&(e=ACTION_DOWN);var n=y,i=w;return e==ACTION_LEFT&&n--,e==ACTION_RIGHT&&n++,e==ACTION_UP&&i++,e==ACTION_DOWN&&i--,!!a(n,i)}function _(){var e=ACTION_STAYSTILL;M<g&&(e=ACTION_RIGHT),z<B&&(e=ACTION_UP),g<M&&(e=ACTION_LEFT),B<z&&(e=ACTION_DOWN);var n=g,i=B;return e==ACTION_LEFT&&n--,e==ACTION_RIGHT&&n++,e==ACTION_UP&&i++,e==ACTION_DOWN&&i--,!!a(n,i)}var H,f,L,y,w,g,B,M,z,v,x,S,k,G,W=new Array(gridsize),D=new Array(160);new Array(NOBOXES);this.endCondition,this.crashedOrange,this.crashedWhite,this.newRun=function(){this.endCondition=!1,this.crashedOrange=!1,this.crashedWhite=!1,S=0,k=0,G=0;var a=" Dont crash! <BR>";$("#user_span2").html(a);var a=" --- Orange use wasd to play --- <BR>";$("#user_span4").html(a);var a=" --- White use arrow keys to play --- <BR>";$("#user_span6").html(a),e(),r(),I(),c(),true&&(H=1,threeworld.init2d(startRadiusConst,maxRadiusConst,SKYCOLOR),i(),initMusic(),o(),O(),E(),t(),document.onkeydown=m)},this.getState=function(){var e=[g,B,y,w];return e},this.takeAction=function(e){G++,true&&h(),C(),N()?S++:k++,true&&(R(),d()),p()&&(soundAlarm(),this.crashedOrange=!0,this.endCondition=!0,this.endRun()),_()&&(soundAlarm(),this.crashedWhite=!0,this.endCondition=!0,this.endRun())},this.endRun=function(){true&&(musicPause(),this.crashedWhite?$("#user_span7").html(" &nbsp; <font color=red> <B> White crashed - Orange Wins </B> </font>   "):this.crashedOrange?$("#user_span7").html(" &nbsp; <font color=red> <B> Orange crashed - White wins. </B> </font>   "):$("#user_span7").html(" &nbsp; <font color=red> <B> It's a tie! </B> </font>   "))},this.getScore=function(){return k/G*100}}function initMusic(){var e="<audio  id=theaudio  src=/uploads/smythc44/rockit.ogg  autoplay loop> </audio>";$("#user_span1").html(e)}function musicPlay(){document.getElementById("theaudio").play()}function musicPause(){document.getElementById("theaudio").pause()}function soundAlarm(){var e="<audio    src=/uploads/smythc44/carcrash-soundeffect.mp3   autoplay  > </audio>";$("#user_span2").html(e)}const CLOCKTICK=150,MAXSTEPS=1e3,gridsize=40,NOBOXES=0,squaresize=2,MAXPOS=80,SKYCOLOR=14548957,BLANKCOLOR=SKYCOLOR,show3d=!1,startRadiusConst=64,skyboxConst=240,maxRadiusConst=800,ACTION_LEFT=0,ACTION_RIGHT=1,ACTION_UP=2,ACTION_DOWN=3,ACTION_STAYSTILL=4,GRID_BLANK=0,GRID_WALL=1,GRID_MAZE=2;