Code viewer for World: 3D Platform Game (clone by...

// Cloned by Lilly Onilenla on 8 Dec 2022 from World "3D Platform Game (clone by Lilly Onilenla)" by Lilly Onilenla 
// Please leave this clone trail here.
 


// Cloned by Lilly Onilenla on 8 Dec 2022 from World "3D Platform Game" by Ronghui 
// Please leave this clone trail here.
 
ABWorld,AB.clockTick=100,AB.maxSteps=1e4,AB.screenshotStep=50,AB.drawRunControls=!0;const show3d=!0,OBJPATH="/uploads/linr2/",PLAYER1OBJ="Quigon.obj",PLAYER1MTL="Quigon.mtl",WALLOBJ="farm_type_wall.obj",WALLMTL="farm_type_wall.mtl",WALL_TEXTURE="/uploads/linr2/farm_type_wall_wall_Height.png";var cam,meshFloor,updatedPosX,updatedPosZ,play,keyboard={},player={height:2,speed:.3,turnSpeed:.09},playerspeed=0,scene=new THREE.Scene,sky_texture=(new THREE.TextureLoader).load("uploads/linr2/milky.jpg");scene.background=sky_texture;var wall_texture,startTime=performance.now(),renderer=new THREE.WebGLRenderer;function render(){renderer.setSize(window.innerWidth,window.innerHeight),document.body.appendChild(renderer.domElement)}function camera(){(cam=new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,.1,1e3)).position.set(0,3.5,-90),cam.lookAt(scene.position)}function create_player(){THREE.DefaultLoadingManager.addHandler(/\.tga$/i,new THREE.TGALoader);var e=new THREE.MTLLoader;e.setResourcePath(OBJPATH),e.setPath(OBJPATH),e.load(PLAYER1MTL,function(e){e.preload();var o=new THREE.OBJLoader;o.setMaterials(e),o.setPath(OBJPATH),o.load(PLAYER1OBJ,function(e){(play=e).scale.multiplyScalar(.05),play.position.set(0,player.height,-160),scene.add(play)})})}function loadtextures(){(new THREE.TextureLoader).load(WALL_TEXTURE,function(e){e.minFilter=THREE.LinearFilter,wall_texture=e})}function generateWall(){THREE.DefaultLoadingManager.addHandler(/\.tga$/i,new THREE.TGALoader);var e=new THREE.MTLLoader;e.setResourcePath(OBJPATH),e.setPath(OBJPATH),e.load(WALLMTL,function(e){e.preload();var o=new THREE.OBJLoader;o.setMaterials(e),o.setPath(OBJPATH),o.load(WALLOBJ,function(e){Wall=e,Wall.scale.multiplyScalar(.1),Wall.position.set(-10,0,100),scene.add(Wall)})}),e.load(WALLMTL,function(e){e.preload();var o=new THREE.OBJLoader;o.setMaterials(e),o.setPath(OBJPATH),o.load(WALLOBJ,function(e){Wall2=e,Wall2.scale.multiplyScalar(.1),Wall2.position.set(10,0,50),Wall2.rotation.y=330,scene.add(Wall2)})}),e.load(WALLMTL,function(e){e.preload();var o=new THREE.OBJLoader;o.setMaterials(e),o.setPath(OBJPATH),o.load(WALLOBJ,function(e){Wall3=e,Wall3.scale.multiplyScalar(.1),Wall3.position.set(-10,0,30),Wall3.rotation.y=0,scene.add(Wall3)})}),e.load(WALLMTL,function(e){e.preload();var o=new THREE.OBJLoader;o.setMaterials(e),o.setPath(OBJPATH),o.load(WALLOBJ,function(e){Wall4=e,Wall4.scale.multiplyScalar(.15),Wall4.position.set(10,0,-15),Wall4.rotation.y=330,scene.add(Wall4)})}),e.load(WALLMTL,function(e){e.preload();var o=new THREE.OBJLoader;o.setMaterials(e),o.setPath(OBJPATH),o.load(WALLOBJ,function(e){Wall5=e,Wall5.scale.multiplyScalar(.1),Wall5.position.set(-10,0,-60),Wall5.rotation.y=0,scene.add(Wall5);var o=new THREE.DirectionalLight("#3fe293",5);o.position.set(0,10,-180),scene.add(o)})}),e.load(WALLMTL,function(e){e.preload();var o=new THREE.OBJLoader;o.setMaterials(e),o.setPath(OBJPATH),o.load(WALLOBJ,function(e){Wall6=e,Wall6.scale.multiplyScalar(.1),Wall6.position.set(10,0,-125),Wall6.rotation.y=330,scene.add(Wall6)})})}function collisionCheck(){var e=play,o=Wall,a=Wall2,t=Wall3,n=Wall4,l=Wall5,i=Wall6;firstBB=(new THREE.Box3).setFromObject(e,!0),secondBB=(new THREE.Box3).setFromObject(o,!0),thirdBB=(new THREE.Box3).setFromObject(a,!0),fourthBB=(new THREE.Box3).setFromObject(t,!0),fifthBB=(new THREE.Box3).setFromObject(n,!0),sixthBB=(new THREE.Box3).setFromObject(l,!0),seventBB=(new THREE.Box3).setFromObject(i,!0);secondBB.intersectsBox(firstBB);fourthBB.intersectsBox(firstBB),fifthBB.intersectsBox(firstBB),sixthBB.intersectsBox(firstBB),seventBB.intersectsBox(firstBB)&&play.position.set(0,player.height,-160)}function floor(){var e=(new THREE.TextureLoader).load("uploads/linr2/ground.jpeg");e.wrapS=e.wrapT=THREE.RepeatWrapping,e.offset.set(2,2),e.repeat.set(10,10),(meshFloor=new THREE.Mesh(new THREE.PlaneGeometry(100,400),new THREE.MeshBasicMaterial({map:e}))).rotation.x-=Math.PI/2,scene.add(meshFloor)}function checkLocation(){if(play.position.z>=160){const e=Math.floor((performance.now()-startTime)/1e3);AB.newSplash(),AB.splashHtml(`<h1>It took you ${e} seconds to reach the end!</h1>`),AB.socketOut({data:{time:e}}),AB.socket.destroy(),GameOver()}}function AddFinishLine(){var e=new THREE.BoxGeometry(100,70,25),o=new THREE.Mesh(e);o.material.color.setHex(16723200),o.position.x=0,o.position.z=180,o.position.y=0,scene.add(o);var a=new THREE.DirectionalLight("#7fe093",4);a.position.set(0,1,0),scene.add(a)}function movement(){requestAnimationFrame(movement),(keyboard[87]||keyboard[38])&&(play.position.x<=180&&play.position.x>=-180?(play.position.x-=Math.sin(play.rotation.y)*player.speed/1.5,play.position.z-=-Math.cos(play.rotation.y)*player.speed/1.5,collisionCheck()):(play.position.x+=Math.sin(play.rotation.y)*player.speed/1.5,collisionCheck()),play.position.z<=180&&play.position.z>=-180?(play.position.x-=Math.sin(play.rotation.y)*player.speed/1.5,play.position.z-=-Math.cos(play.rotation.y)*player.speed/1.5,collisionCheck()):(play.position.z+=-Math.cos(play.rotation.y)*player.speed/1.5,collisionCheck()),playerspeed++,checkLocation(),collisionCheck()),(keyboard[83]||keyboard[40])&&(play.position.x<=160&&play.position.x>=-160?(play.position.x+=Math.sin(play.rotation.y)*player.speed/1.5,play.position.z+=-Math.cos(play.rotation.y)*player.speed/1.5,collisionCheck()):play.position.x-=Math.sin(play.rotation.y)*player.speed/1.5,play.position.z<=200&&play.position.z>=-160?(play.position.x+=Math.sin(play.rotation.y)*player.speed/1.5,play.position.z+=-Math.cos(play.rotation.y)*player.speed/1.5,collisionCheck()):(play.position.z-=-Math.cos(play.rotation.y)*player.speed/1.5,collisionCheck()),playerspeed++,checkLocation(),collisionCheck()),(keyboard[65]||keyboard[37])&&(play.position.x<=50&&play.position.x>=-50?(play.position.x+=Math.sin(play.rotation.y+Math.PI/2)*player.speed/1.5,play.position.z+=-Math.cos(play.rotation.y+Math.PI/2)*player.speed/1.5,collisionCheck()):(play.position.x=Math.sin(play.rotation.y-Math.PI/2)*player.speed/1.5,collisionCheck()),play.position.z<=200&&play.position.z>=-200?(play.position.x+=Math.sin(play.rotation.y+Math.PI/2)*player.speed/1.5,play.position.z+=-Math.cos(play.rotation.y+Math.PI/2)*player.speed,collisionCheck()):(play.position.z=-Math.cos(play.rotation.y-Math.PI/2)*player.speed/1.5,collisionCheck()),playerspeed++,checkLocation(),collisionCheck()),(keyboard[68]||keyboard[39])&&(play.position.x<=50&&play.position.x>=-50?(play.position.x+=Math.sin(play.rotation.y-Math.PI/2)*player.speed/1.5,play.position.z+=-Math.cos(play.rotation.y-Math.PI/2)*player.speed/1.5,collisionCheck()):(play.position.x=Math.sin(play.rotation.y+Math.PI/2)*player.speed/1.5,collisionCheck()),play.position.z<=200&&play.position.z>=-200?(play.position.x+=Math.sin(play.rotation.y-Math.PI/2)*player.speed/1.5,play.position.z+=-Math.cos(play.rotation.y-Math.PI/2)*player.speed,collisionCheck()):(play.position.z=-Math.cos(play.rotation.y+Math.PI/2)*player.speed/1.5,collisionCheck()),playerspeed++,checkLocation(),collisionCheck()),cam.position.x=play.position.x,cam.position.z=play.position.z-5,cam.position.y=4,renderer.render(scene,cam)}function keyDown(e){keyboard[e.keyCode]=!0}function keyUp(e){keyboard[e.keyCode]=!1}function welcome(){AB.newSplash(),AB.runReady=!1,AB.splashHtml(" \n    <h1> Welcome to 3D Platformer! </h1>  \n    The Goal is to reach the Finish line in the fastest time.  <br>\n    Press WASD to move, If you touch any of the obstacles you get reset to the beginning (not working)!\n    <p>\n    <button onclick='AB.removeSplash();'  class=ab-largenormbutton >Start</button>\n    <p>  ")}startTime=performance.now(),window.addEventListener("keydown",keyDown),window.addEventListener("keyup",keyUp),AB.world.newRun=function(){AB.socketStart(),loadtextures(),render(),create_player(),camera(),floor(),AddFinishLine(),generateWall(),movement(),AB.showRunHeader(),welcome()},AB.socketIn=function(e){if(AB.newSplash(),AB.splashHtml(" <h1> Game Over!<h1> <p>Other player finished in: "+e.data.time+" seconds. </p>"),1!=playonce){var o=new Audio("/uploads/linr2/congratulations.mp3");backgroundM.volume=0,o.volume=.04,o.play(),playonce+=1,Object.freeze(play)}};var playonce=0;function GameOver(){if(1!=playonce){var e=new Audio("/uploads/linr2/congratulations.mp3");backgroundM.volume=0,e.volume=.04,e.play(),playonce+=1,Object.freeze(play)}}welcome();var backgroundM=new Audio("/uploads/linr2/background.mp3");backgroundM.volume=.025,backgroundM.play();