// Cloned by Lorcan Dunne on 1 Dec 2022 from World "escape... (clone by user three)" by user three
// Please leave this clone trail here.
// Cloned by user three on 1 Dec 2022 from World "escape..." by Jon Bryan Ortiz
// Please leave this clone trail here.
function World(){
AB.clockTick=1e3;
var o=new THREE.Scene,t=(new THREE.TextureLoader).load("uploads/dannydevito/night.png");
o.background=t;
var e=.001;
o.fog=new THREE.FogExp2(9530988,e);
var n,a=new THREE.WebGLRenderer;
var p,s,l={height:2,speed:.3,turnSpeed:.09};
keyboard={},window.addEventListener("keydown",function(o){keyboard[o.keyCode]=!0}),window.addEventListener("keyup",function(o){keyboard[o.keyCode]=!1});
var y=.1;
function d()
{
var t,e;
requestAnimationFrame(d),t=Math.abs(parseInt(play.position.x-enemy.position.x)),e=Math.abs(parseInt(play.position.z-enemy.position.z)),t<=1&&e<=1&&(play.position.set(0,l.height,-160),collisionFlag=!0,g()),p<enemy.position.x&&(enemy.position.x-=l.speed+y),p>enemy.position.x&&(enemy.position.x+=l.speed+y),s<enemy.position.z&&(enemy.position.z-=l.speed+y),s>enemy.position.z&&(enemy.position.z+=l.speed+y),keyboard[87]&&(play.position.x<=200&&play.position.x>=-460?(play.position.x-=Math.sin(play.rotation.y)*l.speed,play.position.z-=-Math.cos(play.rotation.y)*l.speed,p=play.position.x,s=play.position.z):play.position.x+=Math.sin(play.rotation.y)*l.speed,play.position.z<=463&&play.position.z>=-193?(play.position.x-=Math.sin(play.rotation.y)*l.speed,play.position.z-=-Math.cos(play.rotation.y)*l.speed,p=play.position.x,s=play.position.z):play.position.z+=-Math.cos(play.rotation.y)*l.speed,c()),keyboard[83]&&(play.position.x<=200&&play.position.x>=-460?(play.position.x+=Math.sin(play.rotation.y)*l.speed,play.position.z+=-Math.cos(play.rotation.y)*l.speed,p=play.position.x,s=play.position.z):play.position.x-=Math.sin(play.rotation.y)*l.speed,play.position.z<=463&&play.position.z>=-193?(play.position.x+=Math.sin(play.rotation.y)*l.speed,play.position.z+=-Math.cos(play.rotation.y)*l.speed,p=play.position.x,s=play.position.z):play.position.z-=-Math.cos(play.rotation.y)*l.speed,c()),keyboard[65]&&(play.position.x<=200&&play.position.x>=-460?(play.position.x+=Math.sin(play.rotation.y+Math.PI/2)*l.speed,play.position.z+=-Math.cos(play.rotation.y+Math.PI/2)*l.speed,p=play.position.x,s=play.position.z):play.position.x=Math.sin(play.rotation.y-Math.PI/2)*l.speed,play.position.z<=463&&play.position.z>=-193?(play.position.x+=Math.sin(play.rotation.y+Math.PI/2)*l.speed,play.position.z+=-Math.cos(play.rotation.y+Math.PI/2)*l.speed):play.position.z=-Math.cos(play.rotation.y-Math.PI/2)*l.speed,c()),keyboard[68]&&(play.position.x<=200&&play.position.x>=-460?(play.position.x+=Math.sin(play.rotation.y-Math.PI/2)*l.speed,play.position.z+=-Math.cos(play.rotation.y-Math.PI/2)*l.speed,p=play.position.x,s=play.position.z):play.position.x=Math.sin(play.rotation.y+Math.PI/2)*l.speed,play.position.z<=463&&play.position.z>=-193?(play.position.x+=Math.sin(play.rotation.y-Math.PI/2)*l.speed,play.position.z+=-Math.cos(play.rotation.y-Math.PI/2)*l.speed):play.position.z=-Math.cos(play.rotation.y+Math.PI/2)*l.speed,c()),keyboard[37]&&(n.rotation.y-=l.turnSpeed,play.rotation.y-=l.turnSpeed,n.position.z=play.position.z),keyboard[39]&&(n.rotation.y+=l.turnSpeed,play.rotation.y+=l.turnSpeed,n.position.z=play.position.z),n.position.x=play.position.x,n.position.z=play.position.z,n.position.y=3.5,a.render(o,n)}var r=[];
var h=0;
function c(){
for(i=0;i<r.length;i++)
pagePlayerX=Math.abs(parseInt(p)-r[i].position.x),pagePlayerZ=Math.abs(parseInt(s)-r[i].position.z),pagePlayerX<=2&&pagePlayerZ<=2&&(r[i].position.set(-50,-50,-50),h++,e+=.003,o.fog=new THREE.FogExp2(9530988,e),l.speed-=.005,y+=.01)}AB.socketUserlist=function(o){console.log(JSON.stringify(o,null," "))},AB.socketStart();
var m=0;
function x(){
AB.socketIn=function(o){m=o},AB.socket&&AB.socket.connected&&AB.socketOut(h)}var u=document.getElementById("ab-threepage"),E=document.createElement("p"),M=document.createElement("p");
function g(){
AB.abortRun=!0,AB.newSplash(),oldSplash=document.getElementById("splash"),oldSplash.remove(),splashBG=document.getElementById("splashblock"),splashBG.style="background:black",endTitle=document.createElement("h2"),h>=10?endTitle.innerText="you escaped":m>=10?endTitle.innerText="you have been left behind...":collisionFlag&&(endTitle.innerText="you have been captured"),endTitle.style="color:red;
left:0; line-height: 200px; margin-top: -100px; position: absolute; text-align: center; top: 50%; width: 100%; font-size:100px;",splashBG.appendChild(endTitle)}this.newRun=function(){var t,e,p,s;!function(){AB.newSplash(),AB.splashClick(function(){d(),AB.removeSplash()});let o=document.getElementById("splash-inner");const t=document.createElement("h1"),e=document.createElement("p");t.innerHTML="find the pages and keep running",e.innerHTML="W A S D & ARROW LEFT + ARROW RIGHT TO MOVE",o.appendChild(t),o.appendChild(e)}(),a.setSize(window.innerWidth,window.innerHeight),document.body.appendChild(a.domElement),t=new THREE.BoxGeometry(1,1,1),e=new THREE.MeshBasicMaterial({color:16777215,transparent:!0,opacity:0}),play=new THREE.Mesh(t,e),play.scale.multiplyScalar(2),play.position.set(0,l.height,-160),o.add(play),function(){var t=new THREE.BoxGeometry(5,7,1),e=new THREE.TextureLoader;thetexture=e.load("/uploads/dannydevito/tate.jpg");var n=new THREE.MeshBasicMaterial({map:thetexture});enemy=new THREE.Mesh(t,n),enemy.position.set(5,2,160),enemy.scale.multiplyScalar(2),o.add(enemy)}(),(n=new THREE.PerspectiveCamera(90,window.innerWidth/window.innerHeight,.1,1e3)).position.set(0,3.5,-160),n.lookAt(o.position),x(),(p=new THREE.MTLLoader).setResourcePath("uploads/dannydevito/"),p.setPath("uploads/dannydevito/"),p.load("lowpoly.mtl",function(t){t.preload();var e=new THREE.OBJLoader;e.setMaterials(t),e.setPath("uploads/dannydevito/"),e.load("lowpoly.obj",function(t){t.scale.set(.3,.3,.3),t.position.set(0,37,0),o.add(t)})}),s=new THREE.AmbientLight(11382189,.5),o.add(s),function(){for(i=0;i<11;i++){var t=new THREE.SphereGeometry(1),e=new THREE.MeshBasicMaterial({color:16729156});page=new THREE.Mesh(t,e);var n=AB.randomIntAtoB(1,6);1==n?(page.position.z+=AB.randomIntAtoB(-190,-110),page.position.x+=AB.randomIntAtoB(-458,195)):2==n?(page.position.z+=AB.randomIntAtoB(-190,460),page.position.x+=AB.randomIntAtoB(195,112)):3==n?(page.position.z+=AB.randomIntAtoB(-190,460),page.position.x+=AB.randomIntAtoB(-100,-172)):4==n?(page.position.z+=AB.randomIntAtoB(-190,460),page.position.x+=AB.randomIntAtoB(-385,-458)):5==n?(page.position.z+=AB.randomIntAtoB(105,177),page.position.x+=AB.randomIntAtoB(195,-458)):(page.position.z+=AB.randomIntAtoB(385,460),page.position.x+=AB.randomIntAtoB(195,-458)),page.position.y+=2,page.scale.multiplyScalar(1.5),r.push(page),o.add(page)}}(),u.appendChild(E),E.style="color:white; text-align:center; font-size:50px;",u.appendChild(M),M.style="color:white; text-align:center; font-size:50px;"},this.nextStep=function(){x(),E.innerText="you "+h,M.innerText="them "+m,(h>=10||m>=10)&&g()}}