Code viewer for World: Hunting Season (clone by S...

// Cloned by Scott Brady on 1 Dec 2022 from World "Hunting Season" by Niall Kelly 
// Please leave this clone trail here.
 
var start_r=100,max_r=300,p1score=0,p2score=0,max_targets=3,alltargets=new Array(0);const mixers=[],animClock=new THREE.Clock,birdClock=new THREE.Clock,gameClock=new THREE.Clock;var bird,hitbox,dir;const SKYBOX_ARRAY=["/uploads/kellyn88/sbleft.jpg","/uploads/kellyn88/sbr.png","/uploads/kellyn88/test.png","/uploads/kellyn88/skybox_base.png","/uploads/kellyn88/test.png","/uploads/kellyn88/test.png"];var gridSetup=[[-160,-100,70],[-80,-100,70],[0,-100,70],[80,-100,70],[160,-100,70],[-160,-100,-10],[-80,-100,-10],[0,-100,-10],[80,-100,-10],[160,-100,-10],[-160,-100,-90],[-80,-100,-90],[0,-100,-90],[80,-100,-90],[160,-100,-90]];const MUSICFILE="/uploads/kellyn88/ambience.mp3";AB.backgroundMusic(MUSICFILE);const shoot_short="uploads/kellyn88/shoot_short.wav",shoot_long="uploads/kellyn88/shoot_long.wav",squak="uploads/kellyn88/eagle_call.wav";function initScene(){var e=new THREE.Color;ABWorld.init2d(start_r,max_r,e),ABWorld.scene.background=(new THREE.CubeTextureLoader).load(SKYBOX_ARRAY);var o=new THREE.AmbientLight("white",.8);ABWorld.scene.add(o)}function spawnTarget(){var e=(new THREE.TextureLoader).load("/uploads/kellyn88/target.png"),o=new THREE.CylinderGeometry(30,30,5,32),t=new THREE.MeshBasicMaterial({map:e}),n=new THREE.Mesh(o,t),r=AB.randomIntAtoB(0,gridSetup.length),a=gridSetup[r];n.position.set(a[0],a[1],a[2]),ABWorld.scene.add(n),gridSetup.splice(r,1),alltargets.push(n)}function cameraControls(){ABHandler.initTouchDrag=mouseClick,ABHandler.touchDrag=mouseDrag,ABHandler.touchZoom=mouseZoom,ABHandler.initMouseDrag=mouseClick,ABHandler.mouseDrag=mouseDrag,ABHandler.mouseZoom=mouseZoom}function mouseClick(e,o){audioHandler("shoot"),targetHit(e,o)}function mouseDrag(e,o){}function mouseZoom(e){}function targetHit(e,o){if(alltargets.length>0)for(var t=0;t<alltargets.length;t++){var n=alltargets[t];if(ABWorld.hitsObject(e,o,n)){if("bird"!=n.name){var r=[n.position.x,n.position.y,n.position.z];gridSetup.push(r),ABWorld.scene.remove(n),alltargets.splice(t,1),p1score++}else ABWorld.scene.remove(bird)&&ABWorld.scene.remove(n),bird=null,alltargets.splice(t,1),max_targets=3,p1score+=10;break}}}function audioHandler(e){"shoot"==e?new Audio(shoot_short).play():"bird"==e&&new Audio(squak).play()}function loadBird(){var e,o=AB.randomIntAtoB(-5,5),t=new Array(0);ran=AB.randomIntAtoB(0,1),0===ran?(dir=-.5,t=[0,Math.PI,Math.PI/2],e=20):(dir=.5,t=[Math.PI,0,Math.PI/2],e=-20);const n=new THREE.GLTFLoader,r=new THREE.Vector3(e,start_r-.1*start_r,o);audioHandler("bird"),n.load("/uploads/kellyn88/simple_bird.glb",e=>((e,o)=>{const n=e.scene.children[0];n.position.copy(o);const r=e.animations[0],a=new THREE.AnimationMixer(n);mixers.push(a),a.clipAction(r).play(),n.rotation.set(t[0],t[1],t[2]),loadHitbox(o),ABWorld.scene.add(n),bird=n})(e,r))}function loadHitbox(e){var o=new THREE.BoxGeometry(2,2,.7),t=new THREE.MeshBasicMaterial(4095),n=new THREE.Mesh(o,t);max_targets=4,n.visible=!1,n.name="bird",n.position.set(e.x,e.y,e.z-.1),ABWorld.scene.add(n),hitbox=n,alltargets.push(n)}function anim_bird(){const e=animClock.getDelta();mixers.forEach(o=>{o.update(e)})}function splashScreenStart(){var e="<p>Shoot targets as they appear to earn points.</p>";return AB.onDesktop()?e+="<p>Desktop instructions: Use your mouse to aim and click to shoot.</p>":e+="<p>Mobile instructions: Tap to shoot.</p>",e+="<p>1 point is awarded for each target destroyed. Keep an eye out for Hawks. They are more difficult to hit but are worth 10 points. Earn more points than your opponent to win!</p>"}function splashScreenEnd(){var e="<h2>Game Over!</h2>";return p1score>p2score?e=e+"<p>p1 won with a score of:</p>"+p1score:p1score<p2score?e=e+"<p>p2 won with a score of:</p>"+p2score:p1score==p2score&&(e=e+"<p>Draw! Both players had a score of:</p>"+p1score),e=e+"<p>Your score:</p>"+p1score}function gameFull(){return"<p>Game session is currently full. Please try again later.</p>"}function reload(){window.location.reload()}AB.newSplash(splashScreenStart()),document.getElementById("splashbutton").id="startsplash",AB.world.newRun=function(){if(AB.onMobile()&&(start_r=500,max_r=1e3),AB.socketStart(),initScene(),AB.runReady=!1,cameraControls(),AB.onMobile()){AB.headerLHS(),AB.runheaderNormal(),document.getElementById("ab-runheaderbox").style.height="250px",document.getElementById("w2m_loggedin").remove(),document.getElementsByTagName("b")[0].remove(),document.getElementsByTagName("a")[1].remove()}else document.getElementById("ab-runheaderbox").style.width="200px"},AB.world.nextStep=function(){if(60==Math.trunc(gameClock.getElapsedTime())&&(AB.runReady=!1,AB.newSplash(splashScreenEnd()),document.getElementById("splashbutton").innerHTML="Play Again",document.getElementById("splashbutton").onclick=reload),alltargets.length<max_targets&&spawnTarget(),AB.socket&&AB.socket.connected&&(AB.socketOut(p1score),AB.msg("P1 Score = "+p1score+" P2 score = "+p2score+"\n Time remaining: "+Math.trunc(60-gameClock.getElapsedTime()))),bird)if(25==bird.position.x||-25==bird.position.x){for(var e=0;e<alltargets.length;e++)"bird"==alltargets[e].name&&alltargets.splice(e,1);ABWorld.scene.remove(bird)&&ABWorld.scene.remove(hitbox),bird=null,max_targets=3}else anim_bird(),bird.translateY(-.5)&&hitbox.translateX(dir);else birdClock.getElapsedTime()>=15&&25==AB.randomIntAtoB(1,50)&&(loadBird(),birdClock.start())},AB.world.endRun=function(){},$("#startsplash").click(function(){AB.socket&&AB.socket.connected&&AB.socketOut("ready"),AB.runReady=!0,AB.removeSplash()}),AB.socketIn=function(e){"ready"==e?(AB.runReady=!0,AB.removeSplash()):p2score=e},AB.socketUserlist=function(e){e.length>2&&(AB.runReady=!1,AB.newSplash(gameFull()),document.getElementById("splashbutton").innerHTML="Try Again",document.getElementById("splashbutton").onclick=reload),AB.socketUserlist=function(){}};