Code viewer for World: Mighty Spread (clone by Va...

// Cloned by Vaidas Buzas on 2 Dec 2022 from World "Mighty Spread" by Gareth Hogan 
// Please leave this clone trail here.
 
AB.clockTick=100,AB.maxSteps=300,AB.screenshotStep=100;const FILE_ARRAY=["/uploads/gareth22/dirt.jpg","/uploads/gareth22/diamond.jpg","/uploads/gareth22/redstone.jpg","/uploads/gareth22/redglass.jpg","/uploads/gareth22/blueglass.jpg","/uploads/gareth22/blorb.jpg","/uploads/gareth22/rorb.jpg"],SKYBOX_ARRAY=["/uploads/gareth22/px-min.png","/uploads/gareth22/nx-min.png","/uploads/gareth22/py-min.png","/uploads/gareth22/ny-min.png","/uploads/gareth22/pz-min.png","/uploads/gareth22/nz-min.png"],SKYCOLOR=0,gridsize=10,objectsize=100,NumBoxes=gridsize*gridsize,MAXPOS=gridsize*objectsize,startRadiusConst=MAXPOS,maxRadiusConst=5*MAXPOS,GRID_BLANK=0,GRID_USER1=1,GRID_USER2=4,GRID_COLOUR1=2,GRID_COLOUR2=3,ACTION_LEFT=0,ACTION_RIGHT=1,ACTION_UP=2,ACTION_DOWN=3;var step;ABHandler.MAXCAMERAPOS=MAXPOS,ABWorld.drawCameraControls=!1,AB.drawRunControls=!1,ABHandler.GROUNDZERO=!0;var ai,aj,bi,bj,player1,player2,textureArray=new Array(FILE_ARRAY.length),GRID=new Array(gridsize);function loadResources(){for(var e=0;e<FILE_ARRAY.length;e++)startFileLoad(e)}function startFileLoad(e){(new THREE.TextureLoader).load(FILE_ARRAY[e],function(r){r.minFilter=THREE.LinearFilter,textureArray[e]=r,asynchFinished()&&initScene()})}function asynchFinished(){for(var e=0;e<FILE_ARRAY.length;e++)if(!textureArray[e])return!1;return!0}function splashHTML(){return string="Colour the floor, QUICKLY! <br><font color=red><b>Red is the arrow keys</b></font> <br><font color=blue><b>Blue is WASD</b></font><br>  Colour the most squares before time is up to win!",string}function initScene(){var e,r,t,o,n,a;for(e=0;e<gridsize;e++)GRID[e]=new Array(gridsize);for(e=0;e<gridsize;e++)for(r=0;r<gridsize;r++)GRID[e][r]=GRID_BLANK,t=new THREE.BoxGeometry(objectsize,objectsize,objectsize),(o=new THREE.Mesh(t)).material=new THREE.MeshBasicMaterial({map:textureArray[0]}),o.position.copy(translate(e,r)),ABWorld.scene.add(o);n=new THREE.SphereGeometry(50,32,16),a=new THREE.SphereGeometry(50,32,16),player1=new THREE.Mesh(n),player2=new THREE.Mesh(a),player1.material=new THREE.MeshBasicMaterial({map:textureArray[5]}),player2.material=new THREE.MeshBasicMaterial({map:textureArray[6]}),position1=translateOrb(0,0),player1.position.copy(position1),position2=translateOrb(9,9),player2.position.copy(position2),ABWorld.scene.add(player1),ABWorld.scene.add(player2),aj=0,bi=9,bj=9,GRID[ai=0][aj]=GRID_USER1,GRID[bi][bj]=GRID_USER2,ABWorld.scene.background=(new THREE.CubeTextureLoader).load(SKYBOX_ARRAY,function(){ABWorld.render()}),AB.removeLoading()}function translate(e,r){var t=new THREE.Vector3;return t.y=0,t.x=e*objectsize-MAXPOS/2,t.z=r*objectsize-MAXPOS/2,t}function translateOrb(e,r){var t=new THREE.Vector3;return t.y=100,t.x=e*objectsize-MAXPOS/2,t.z=r*objectsize-MAXPOS/2,t}function occupied(e,r){return GRID[e][r]==GRID_USER1||GRID[e][r]==GRID_USER2}AB.newSplash(splashHTML()),AB.splashClick(function(){AB.removeSplash(),splashClicked=!0,step=0,ABWorld.render(),AB.runReady=!0,AB.socketOut("Start"),asynchFinished()&&(AB.runReady=!0)});var OURKEYS=[37,38,39,40,65,87,68,83];function ourKeys(e){return OURKEYS.includes(e.keyCode)}function keyHandler(e){return!AB.runReady||(!ourKeys(e)||(65==e.keyCode&&socketSender(ACTION_LEFT,1),87==e.keyCode&&socketSender(ACTION_DOWN,1),68==e.keyCode&&socketSender(ACTION_RIGHT,1),83==e.keyCode&&socketSender(ACTION_UP,1),37==e.keyCode&&socketSender(ACTION_LEFT,2),38==e.keyCode&&socketSender(ACTION_DOWN,2),39==e.keyCode&&socketSender(ACTION_RIGHT,2),40==e.keyCode&&socketSender(ACTION_UP,2),e.stopPropagation(),e.preventDefault(),!1))}function moveUser(e,r){if(1==r)var t=ai,o=aj;else if(2==r)o=bj,t=bi;if(e==ACTION_LEFT){if(!(t>0))return;t--}else if(e==ACTION_RIGHT){if(!(t<9))return;t++}else if(e==ACTION_UP){if(!(o<9))return;o++}else if(e==ACTION_DOWN){if(!(o>0))return;o--}occupied(t,o)||(1==r?(GRID[ai][aj]=GRID_COLOUR1,shape=new THREE.BoxGeometry(objectsize,objectsize,objectsize),theobject=new THREE.Mesh(shape),theobject.material=new THREE.MeshBasicMaterial({map:textureArray[1]}),theobject.position.copy(translate(ai,aj)),ABWorld.scene.add(theobject),position=translateOrb(t,o),player1.position.copy(position),GRID[t][o]=GRID_USER1,shape=new THREE.BoxGeometry(objectsize,objectsize,objectsize),theobject=new THREE.Mesh(shape),theobject.material=new THREE.MeshBasicMaterial({map:textureArray[4]}),theobject.position.copy(translate(t,o)),ABWorld.scene.add(theobject)):2==r&&(GRID[bi][bj]=GRID_COLOUR2,shape=new THREE.BoxGeometry(objectsize,objectsize,objectsize),theobject=new THREE.Mesh(shape),theobject.material=new THREE.MeshBasicMaterial({map:textureArray[2]}),theobject.position.copy(translate(bi,bj)),ABWorld.scene.add(theobject),position=translateOrb(t,o),player2.position.copy(position),GRID[t][o]=GRID_USER2,shape=new THREE.BoxGeometry(objectsize,objectsize,objectsize),theobject=new THREE.Mesh(shape),theobject.material=new THREE.MeshBasicMaterial({map:textureArray[3]}),theobject.position.copy(translate(t,o)),ABWorld.scene.add(theobject)),1==r?(ai=t,aj=o):2==r&&(bi=t,bj=o))}function updatestatus(){var e="<font size=5 face=verdana> Time: <br>"+step+"</font>";$("#user_span3").html(e)}function countScore(){for(scoreP1=1,scoreP2=1,i=0;i<gridsize;i++)for(j=0;j<gridsize;j++)2==GRID[i][j]?scoreP1+=1:3==GRID[i][j]&&(scoreP2+=1);return console.log(scoreP1),console.log(scoreP2),scoreP1>scoreP2?winner="<br> <font color=blue> <B> The winner is ... PLAYER 1 </B> </font>":scoreP2>scoreP1?winner="<br> <font color=red> <B> The winner is ... PLAYER 2 </B> </font>":winner="<br> <font color=green> <B> The game was a Draw</B> </font>",winner}function socketSender(e,r){data=[e,r],AB.socketOut(data),moveUser(e,r)}AB.world.newRun=function(){AB.loadingScreen(),AB.runReady=!1,ABWorld.init3d(startRadiusConst,maxRadiusConst,0),loadResources(),document.onkeydown=keyHandler,step=0},AB.world.nextStep=function(){step++,updatestatus()},AB.world.endRun=function(){300==step&&$("#user_span4").html("<font size=5 face=verdana> <B>TIME UP</B> </font>"),winner=countScore(),AB.msg(winner,7)},AB.socketStart(),AB.socketIn=function(e){"string"==typeof e?(AB.removeSplash(),splashClicked=!0,step=0,ABWorld.render(),AB.runReady=!0):(action=e[0],player=e[1],moveUser(action,player))};