diff --git a/docs/assets/index-AyFofirk.js b/docs/assets/index-FUWxvTOp.js similarity index 99% rename from docs/assets/index-AyFofirk.js rename to docs/assets/index-FUWxvTOp.js index bfa76bb..e8bf294 100644 --- a/docs/assets/index-AyFofirk.js +++ b/docs/assets/index-FUWxvTOp.js @@ -11730,4 +11730,4 @@ __p += '`),$i&&(tt+=`' + function print() { __p += __j.call(arguments, '') } `:`; `)+tt+`return __p -}`;var Oi=BS(function(){return os(J,kt+"return "+tt).apply(t,pe)});if(Oi.source=tt,qg(Oi))throw Oi;return Oi}function kO(m){return fs(m).toLowerCase()}function GO(m){return fs(m).toUpperCase()}function zO(m,x,y){if(m=fs(m),m&&(y||x===t))return YT(m);if(!m||!(x=ga(x)))return m;var F=co(m),z=co(x),J=$T(F,z),pe=KT(F,z)+1;return zl(F,J,pe).join("")}function WO(m,x,y){if(m=fs(m),m&&(y||x===t))return m.slice(0,jT(m)+1);if(!m||!(x=ga(x)))return m;var F=co(m),z=KT(F,co(x))+1;return zl(F,0,z).join("")}function HO(m,x,y){if(m=fs(m),m&&(y||x===t))return m.replace(Wt,"");if(!m||!(x=ga(x)))return m;var F=co(m),z=$T(F,co(x));return zl(F,z).join("")}function XO(m,x){var y=L,F=B;if(Js(x)){var z="separator"in x?x.separator:z;y="length"in x?Ai(x.length):y,F="omission"in x?ga(x.omission):F}m=fs(m);var J=m.length;if(uc(m)){var pe=co(m);J=pe.length}if(y>=J)return m;var xe=y-dc(F);if(xe<1)return F;var Pe=pe?zl(pe,0,xe).join(""):m.slice(0,xe);if(z===t)return Pe+F;if(pe&&(xe+=Pe.length-xe),jg(z)){if(m.slice(xe).search(z)){var Ke,je=Pe;for(z.global||(z=dg(z.source,fs(ct.exec(z))+"g")),z.lastIndex=0;Ke=z.exec(je);)var tt=Ke.index;Pe=Pe.slice(0,tt===t?xe:tt)}}else if(m.indexOf(ga(z),xe)!=xe){var At=Pe.lastIndexOf(z);At>-1&&(Pe=Pe.slice(0,At))}return Pe+F}function YO(m){return m=fs(m),m&&da.test(m)?m.replace(Qr,ER):m}var $O=xc(function(m,x,y){return m+(y?" ":"")+x.toUpperCase()}),Jg=VE("toUpperCase");function LS(m,x,y){return m=fs(m),x=y?t:x,x===t?mR(m)?bR(m):oR(m):m.match(x)||[]}var BS=Fi(function(m,x){try{return _a(m,t,x)}catch(y){return qg(y)?y:new mi(y)}}),KO=cl(function(m,x){return Wa(x,function(y){y=Oo(y),ll(m,y,$g(m[y],m))}),m});function qO(m){var x=m==null?0:m.length,y=si();return m=x?Ys(m,function(F){if(typeof F[1]!="function")throw new Ha(n);return[y(F[0]),F[1]]}):[],Fi(function(F){for(var z=-1;++zae)return[];var y=w,F=Sn(m,w);x=si(x),m-=w;for(var z=hg(F,x);++y0||x<0)?new Wi(y):(m<0?y=y.takeRight(-m):m&&(y=y.drop(m)),x!==t&&(x=Ai(x),y=x<0?y.dropRight(-x):y.take(x-m)),y)},Wi.prototype.takeRightWhile=function(m){return this.reverse().takeWhile(m).reverse()},Wi.prototype.toArray=function(){return this.take(w)},Mo(Wi.prototype,function(m,x){var y=/^(?:filter|find|map|reject)|While$/.test(x),F=/^(?:head|last)$/.test(x),z=Y[F?"take"+(x=="last"?"Right":""):x],J=F||/^find/.test(x);z&&(Y.prototype[x]=function(){var pe=this.__wrapped__,xe=F?[1]:arguments,Pe=pe instanceof Wi,Ke=xe[0],je=Pe||xi(pe),tt=function(Ui){var $i=z.apply(Y,Ll([Ui],xe));return F&&At?$i[0]:$i};je&&y&&typeof Ke=="function"&&Ke.length!=1&&(Pe=je=!1);var At=this.__chain__,kt=!!this.__actions__.length,ni=J&&!At,Oi=Pe&&!kt;if(!J&&je){pe=Oi?pe:new Wi(this);var ai=m.apply(pe,xe);return ai.__actions__.push({func:qp,args:[tt],thisArg:t}),new Xa(ai,At)}return ni&&Oi?m.apply(this,xe):(ai=this.thru(tt),ni?F?ai.value()[0]:ai.value():ai)})}),Wa(["pop","push","shift","sort","splice","unshift"],function(m){var x=Ep[m],y=/^(?:push|sort|unshift)$/.test(m)?"tap":"thru",F=/^(?:pop|shift)$/.test(m);Y.prototype[m]=function(){var z=arguments;if(F&&!this.__chain__){var J=this.value();return x.apply(xi(J)?J:[],z)}return this[y](function(pe){return x.apply(xi(pe)?pe:[],z)})}}),Mo(Wi.prototype,function(m,x){var y=Y[x];if(y){var F=y.name+"";xs.call(mc,F)||(mc[F]=[]),mc[F].push({name:x,func:y})}}),mc[zp(t,v).name]=[{name:"wrapper",func:t}],Wi.prototype.clone=YR,Wi.prototype.reverse=$R,Wi.prototype.value=KR,Y.prototype.at=CM,Y.prototype.chain=bM,Y.prototype.commit=yM,Y.prototype.next=AM,Y.prototype.plant=IM,Y.prototype.reverse=PM,Y.prototype.toJSON=Y.prototype.valueOf=Y.prototype.value=MM,Y.prototype.first=Y.prototype.head,Ou&&(Y.prototype[Ou]=RM),Y},fc=yR();Ch?((Ch.exports=fc)._=fc,tg._=fc):pn._=fc}).call(Yu)})(q_,q_.exports);var i6=q_.exports;class s6 extends Error{constructor(e){super(`[DomSetup] ${e}`)}}class kC extends Error{constructor(e){super(`[AppError] ${e}`)}}class GC{constructor(e){Nt(this,"key");Nt(this,"used");this.key=e.key,this.used=e.used||!1}}class r6{constructor(){Nt(this,"singletonInstance",null);Nt(this,"keyState",new Map);Nt(this,"keyDownHandler",e=>{const{key:t}=e;this.keyState.set(t,new GC({key:t}))});Nt(this,"keyUpHandler",e=>{const{key:t}=e;this.keyState.has(t)&&this.keyState.delete(t)});if(this.singletonInstance)return this.singletonInstance;this.keyState=new Map,addEventListener("keydown",this.keyDownHandler),addEventListener("keyup",this.keyUpHandler),this.singletonInstance=this}clear(){removeEventListener("keydown",this.keyDownHandler),removeEventListener("keyup",this.keyUpHandler)}wasPressedOnce(e){var i;let t=!1;return this.keyState.has(e)&&(t=!((i=this.keyState.get(e))!=null&&i.used),this.keyState.set(e,new GC({key:e,used:!0}))),t}isBeingPressed(e){return!!this.keyState.has(e)}}class n6{constructor(e){Nt(this,"input",{keyboardHandler:new r6});Nt(this,"currentScene");Nt(this,"allScenes",new Map);this.engine=e}createScene(e,t){this.allScenes.set(e,t),this.currentScene||(this.currentScene=t)}goToScene(e){this.allScenes.has(e)?this.currentScene=this.allScenes.get(e):console.warn(`The scene with key ${e} was not found! Keeping previous scene!`)}runRenderLoop(){if(!this.currentScene)throw new kC("No default scene was configured!");this.engine.runRenderLoop(()=>{const e=this.engine.getDeltaTime();if(!this.currentScene)throw new kC("Trying to render undefined scene!");this.currentScene.update(e),this.currentScene.render(!0)})}}class a6 extends Qe{constructor(t,i){super(t.engine);Nt(this,"entities",[]);Nt(this,"_camera");Nt(this,"_light");this.app=t,this.enablePhysics(i!=null&&i.gravity?i.gravity:T.Down().scale(9.8),new U_),this._camera=new zn("BASE-CAMERA",T.Up().scale(50),this),this._camera.attachControl(t.engine.getRenderingCanvas(),!0),this._light=new ro("BASE-LIGHT",T.Down(),this)}update(t){this.entities.forEach(i=>this.entities.forEach(s=>{i!==s&&i.collisionType!=="none"&&s.collisionType!=="none"&&i.mesh.intersectsMesh(s.mesh)&&(i.onCollision(s,this.app),s.onCollision(i,this.app))})),this.entities.forEach(i=>i.update(this.app,t)),this.entities=this.entities.filter(i=>i.isAlive)}addEntity(t){this.entities.push(t),t.onEnterScene(this)}set camera(t){this._camera.detachControl(),this._camera.dispose(),this._camera=t,this._camera.attachControl(this.app.engine.getRenderingCanvas(),!0)}get camera(){return this._camera}set light(t){this._light.dispose(),this._light=t}get light(){return this._light}}class rl{constructor(e){Nt(this,"_mesh");Nt(this,"isAlive",!0);Nt(this,"collisionType","none");Nt(this,"meshChildren",[]);this.scene=e,this._mesh=new se("BASE-MESH")}update(e,t){}onCollision(e,t){}onEnterScene(e){}kill(){this.isAlive=!1,this.mesh&&this.scene.removeMesh(this.mesh),this.meshChildren.forEach(e=>this.scene.removeMesh(e.mesh))}set mesh(e){this._mesh=e}get mesh(){return this._mesh}}class o6{static useParabolaCurve(e){const t=e.min?e.min:0,i=e.max,s=i-t,r=t+s/2;return a=>{a=Math.min(i,Math.max(a,t));let l=0;return a<=r?l=a/r:l=1-(a-r)/r,Math.min(1,Math.max(l,0))}}}class NA{static useLinearPath(e){const t=e.start,i=e.end;return r=>{const n=Math.min(1,Math.max(r,0)),a=t.x+(i.x-t.x)*n,l=t.y+(i.y-t.y)*n,h=t.z+(i.z-t.z)*n;return new T(a,l,h)}}}class l6{static findRotationAngleBasedOnDirection(e){return e==="top"?0:e==="right"?Math.PI/2:e==="bottom"?Math.PI:Math.PI*3/2}}class h6 extends rl{constructor(t,i){super(t);Nt(this,"direction");Nt(this,"start");Nt(this,"end");Nt(this,"velocity");Nt(this,"pathProgress");Nt(this,"previousPathProgress",0);Nt(this,"width");Nt(this,"height");Nt(this,"depth");Nt(this,"pathMap");this.width=i.width,this.height=i.height,this.depth=i.depth,this.direction=i.direction,this.start=i.start,this.end=i.end,this.pathProgress=i.pathProgress,this.velocity=i.velocity,this.pathMap=NA.useLinearPath({start:this.start,end:this.end}),this.collisionType="dynamic";const s=new Te(.15,.15,.15);this.mesh=an.CreateBox("CAR-MESH",{width:this.width,depth:this.depth,height:this.height/2},t),this.mesh.position=i.start,this.mesh.material=new De("CAR-MESH-MATERIAL",t),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=Te.Random());const r=T.Down().scale(30),n=an.CreateBox("CAR-MESH",{width:this.width,depth:this.depth/2,height:this.height/2},t);n.position=r,n.material=new De("CAR-MESH-MATERIAL",t),n.material instanceof De&&(n.material.diffuseColor=s),this.meshChildren.push({mesh:n,anchorToParent:new T(0,this.height/2,0)});const a=an.CreateCylinder("CAR-MESH",{height:this.width*1.1,diameter:this.height*5/8});a.position=r,a.rotation=new T(0,0,Math.PI/2),a.material=new De("CAR-MESH-MATERIAL",t),a.material instanceof De&&(a.material.diffuseColor=s),this.meshChildren.push({mesh:a,anchorToParent:new T(0,-this.height/6,this.depth/3)});const l=an.CreateCylinder("CAR-MESH",{height:this.width*1.1,diameter:this.height*5/8});l.position=r,l.rotation=new T(0,0,Math.PI/2),l.material=new De("CAR-MESH-MATERIAL",t),l.material instanceof De&&(l.material.diffuseColor=s),this.meshChildren.push({mesh:l,anchorToParent:new T(0,-this.height/6,-this.depth/3)})}update(t,i){const s=this.direction==="right"?1:-1,r=this.velocity*i*s;this.pathProgress=(this.pathProgress+r*s+1)%1,(this.direction==="right"?this.pathProgress{n.position=this._mesh.position.add(a)}),this.previousPathProgress=this.pathProgress}}class c6 extends rl{constructor(t,i){super(t);Nt(this,"direction");Nt(this,"start");Nt(this,"end");Nt(this,"pathProgress");Nt(this,"velocity");Nt(this,"pathMap");this.mesh=an.CreateBox("LOG-MESH",{width:i.width,depth:i.depth,height:i.height},t),this.mesh.position=i.start,this.mesh.material=new De("LOG-MESH-MATERIAL",t),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=new Te(.6,.5,.3)),this.direction=i.direction;const s=this.direction==="right"?1:-1;this.start=i.start.clone().add(new T(0,0,i.depth*-s)),this.end=i.end.clone().add(new T(0,0,i.depth*s)),this.pathProgress=i.pathProgress,this.velocity=i.velocity,this.pathMap=NA.useLinearPath({start:this.start,end:this.end}),this.collisionType="platform"}update(t,i){const s=this.direction==="right"?1:-1,r=this.velocity*i*s;this.pathProgress=(this.pathProgress+r*s+1)%1,this._mesh.position=this.pathMap(this.pathProgress)}}const Ss=16;class u6{constructor(e){this.scene=e}getClosestTile(e,t){return this.scene.tiles.find(i=>Math.abs(e-i.x)<=t)}}const d6=()=>{const o=new Map;let e="idle";return{state:()=>e,transition:i=>{const s=e;switch(e){case"idle":switch(i){case"move":e="moving";break;case"stop":e="idle";break;case"bind-to-platform":e="on-platform";break;case"move-back":break;case"die":e="dead";break}break;case"moving":switch(i){case"move":e="moving";break;case"stop":e="idle";break;case"move-back":e="moving-back";break;case"bind-to-platform":break;case"die":e="dead";break}break;case"moving-back":switch(i){case"stop":e="idle";break;case"move-back":e="moving-back";break;case"move":case"bind-to-platform":break;case"die":e="dead";break}break;case"on-platform":switch(i){case"stop":e="idle";break;case"move":e="moving";break;case"move-back":case"bind-to-platform":break;case"die":e="dead";break}break}s!==e&&(o.get(e)||[]).forEach(n=>n())},registerCallback:(i,s)=>{o.has(i)?o.set(i,[...o.get(i),s]):o.set(i,[s])}}},Sd=class Sd extends rl{constructor(t,i){super(t);Nt(this,"scene");Nt(this,"particles",[]);Nt(this,"life",0);const s=20;for(let r=0;rSd.TTL){this.kill(),this.scene.restart();return}this.life+=i}kill(){super.kill(),this.particles.forEach(t=>t.kill())}};Nt(Sd,"TTL",1e3);let tx=Sd;class f6 extends rl{constructor(t,i){super(t);Nt(this,"pointingTo");Nt(this,"ttl");Nt(this,"life",0);this._mesh=an.CreateBox("PARTICLE-MESH",{size:Ss/16},t),this.mesh.material=new De("PLAYER-MESH-MATERIAL",t),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=Math.random()<.5?Te.White():Te.Red()),this.mesh.position=i.start,this.ttl=i.TTL;const s=()=>-1+Math.floor(3*Math.random());this.pointingTo=new T(s(),s(),s())}update(t,i){this.life+=i,this.mesh.position=this.mesh.position.add(this.pointingTo.scale(.01*i)),this.mesh.material&&(this.mesh.material.alpha=1-this.life/this.ttl)}}const Q_=class Q_ extends rl{constructor(t,i){super(t);Nt(this,"stateMachine");Nt(this,"jumpCurrDistance",0);Nt(this,"direction","top");Nt(this,"width");Nt(this,"depth");Nt(this,"height");Nt(this,"platform");Nt(this,"platformCenterOffset");Nt(this,"tiledSceneNavigator");Nt(this,"scene");this.scene=t;const s=i!=null&&i.size?i.size:Ss,r=Te.Red();this.width=s,this.height=s*2,this.depth=s,this.mesh=an.CreateBox("PLAYER-MESH",{height:this.height,depth:this.depth,width:this.width},t),i!=null&&i.position&&(this.mesh.position=i.position),this.mesh.material=new De("PLAYER-MESH-MATERIAL",t),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=Te.White());const n=T.Down().scale(30),a=an.CreateBox("PLAYER-MESH",{height:this.height/2,depth:this.depth,width:this.width/2},t);a.position=n,a.material=new De("PLAYER-MESH-MATERIAL",t),a.material instanceof De&&(a.material.diffuseColor=Te.White()),this.meshChildren.push({mesh:a,anchorToParent:new T(-this.width*3/4,-this.height/4,0)});const l=an.CreateBox("PLAYER-MESH",{height:this.height/8,depth:this.depth/4,width:this.width/2},t);l.position=n,l.material=new De("PLAYER-MESH-MATERIAL",t),l.material instanceof De&&(l.material.diffuseColor=r),this.meshChildren.push({mesh:l,anchorToParent:new T(0,this.height*9/16,0)});const h=an.CreateBox("PLAYER-MESH",{height:this.height/8,depth:this.depth/2,width:this.width/4},t);h.position=n,h.material=new De("PLAYER-MESH-MATERIAL",t),h.material instanceof De&&(h.material.diffuseColor=new Te(.95,.65,.2)),this.meshChildren.push({mesh:h,anchorToParent:new T(this.width*5/8,this.height/4,0)});const c=an.CreateBox("PLAYER-MESH",{height:this.height/8,depth:this.depth/4,width:this.width/4},t);c.position=n,c.material=new De("PLAYER-MESH-MATERIAL",t),c.material instanceof De&&(c.material.diffuseColor=r),this.meshChildren.push({mesh:c,anchorToParent:new T(this.width*5/8,this.height/8,0)}),this.stateMachine=d6(),this.stateMachine.registerCallback("moving",()=>this.jumpCurrDistance=0),this.stateMachine.registerCallback("idle",()=>{this._mesh.position=new T(Math.round(this._mesh.position.x),Math.round(this._mesh.position.y),Math.round(this._mesh.position.z))}),this.collisionType="dynamic",t instanceof j_&&(this.tiledSceneNavigator=new u6(t))}updateJump(t,i){const s=this.stateMachine.state();if(s==="moving-back"&&this.jumpCurrDistance<=0||s==="moving"&&this.jumpCurrDistance>=Ss){this.stateMachine.transition("stop");return}const r=.08*i,n=this.direction==="top"||this.direction==="bottom"?"x":(this.direction==="right"||this.direction==="left","z");let a=this.direction==="top"||this.direction==="left"?1:-1;if(s==="moving"){const l=Math.min(r,Ss-this.jumpCurrDistance);this.mesh.position[n]+=l*a,this.jumpCurrDistance+=l}else if(s==="moving-back"){const l=Math.min(r,this.jumpCurrDistance);a*=-1,this.mesh.position[n]+=l*a,this.jumpCurrDistance-=l}this.mesh.position.y=this.height/2+Q_.jumpVerticalDistanceCurve(this.jumpCurrDistance)*Ss}updatePlatform(t,i){this.platform&&this.platformCenterOffset&&(this._mesh.position=this.platform._mesh.position.add(this.platformCenterOffset))}handleIdle(t,i){var r;const s=(r=this.tiledSceneNavigator)==null?void 0:r.getClosestTile(this._mesh.position._x,this.depth);(s==null?void 0:s.tile.collisionType)==="dynamic"&&s.x>0&&this.handleDeath()}onCollision(t,i){i.engine.getFps()!==1/0&&(t.collisionType==="static"&&this.stateMachine.transition("move-back"),t.collisionType==="dynamic"&&this.scene&&this.handleDeath(),t.collisionType==="platform"&&(this.stateMachine.state()==="idle"&&(this.platform=t,this.platformCenterOffset=this._mesh.position.subtract(t._mesh.position)),this.stateMachine.transition("bind-to-platform")))}updateMesh(t,i){const s=l6.findRotationAngleBasedOnDirection(this.direction),r=new T(0,s,0);this._mesh.rotation=r,this.meshChildren.forEach(({mesh:n,anchorToParent:a})=>{n.rotation=r;const l=Se.FromEulerAngles(0,s,0),h=a.applyRotationQuaternion(l);n.position=this._mesh.position.add(h)})}handleDeath(){if(this.stateMachine.state()==="dead")return;this.stateMachine.transition("die"),this.mesh.material&&(this.mesh.material.alpha=0),this.meshChildren.forEach(s=>{s.mesh.material&&(s.mesh.material.alpha=0)});const t=this._mesh.position.clone(),i=new tx(this.scene,{start:t});this.scene.addEntity(i)}update(t,i){if(t.engine.getFps()===1/0)return;const{input:{keyboardHandler:s}}=t,r=this.stateMachine.state();switch(r){case"idle":case"on-platform":s.wasPressedOnce("ArrowUp")||s.wasPressedOnce(" ")?(this.direction="top",this.stateMachine.transition("move")):s.wasPressedOnce("ArrowDown")&&(this.direction="bottom",this.stateMachine.transition("move")),s.wasPressedOnce("ArrowRight")?(this.direction="right",this.stateMachine.transition("move")):s.wasPressedOnce("ArrowLeft")&&(this.direction="left",this.stateMachine.transition("move")),r==="on-platform"&&this.updatePlatform(t,i),r==="idle"&&this.handleIdle(t,i);break;case"moving":case"moving-back":this.updateJump(t,i);break}this.updateMesh(t,i)}};Nt(Q_,"jumpVerticalDistanceCurve",o6.useParabolaCurve({min:0,max:Ss}));let ix=Q_;class Pv extends rl{constructor(t,i){super(t);Nt(this,"width");Nt(this,"depth");this.width=i.width,this.depth=i.depth;const s=Ss;this.mesh=an.CreateBox("LIMIT-MESH",{width:this.width,height:s*1.1,depth:this.depth},t),this._mesh.position=new T(i.x,-Ss/2,i.z),this._mesh.material=new De("TILE-MESH-MATERIAL",t),this._mesh.material instanceof De&&(this._mesh.material.diffuseColor=new Te(.05,.05,.05)),this.collisionType="static"}}class p6 extends rl{constructor(e,t){super(e);const i=Ss/2,s=new Te(.45,.45,.45);this.mesh=an.CreateBox("STONE-MESH",{size:i},e),this.mesh.position=new T(t.x,i/2,t.z),this.mesh.material=new De("STONE-MESH-MATERIAL",e),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=s);const r=an.CreateBox("STONE-MESH",{size:i/2},e);r.position=new T(t.x,i*5/4,t.z),r.material=new De("STONE-MESH-MATERIAL",e),r.material instanceof De&&(r.material.diffuseColor=s),this.meshChildren.push({mesh:r,anchorToParent:T.Zero()}),this.collisionType="static"}}class _6 extends rl{constructor(e,t){super(e);const i=Ss*1/4,s=Ss*2;this.mesh=an.CreateBox("TREE-MESH",{width:i,depth:i,height:s},e),this.mesh.position=new T(t.x,s/2,t.z),this.mesh.material=new De("TREE-MESH-MATERIAL",e),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=new Te(.55,.45,.3));const r=an.CreateBox("TREE-MESH",{size:Ss},e);r.position=new T(t.x,s,t.z),r.material=new De("TREE-MESH-MATERIAL",e),r.material instanceof De&&(r.material.diffuseColor=new Te(.5,.7,.4)),this.meshChildren.push({mesh:r,anchorToParent:T.Zero()}),this.collisionType="static"}}const zC=["nature","empty","track","river"],WC=[p6,_6],HC=(o,e,t)=>{const i=[],s=t._mesh.position.z-t.depth/2,r=t._mesh.position.z+t.depth/2;for(let n=0;n[],XC=[h6],g6=(o,e,t)=>{const i=[],s=Math.random()<.5?"right":"left";e=Math.min(2,e);const r=t._mesh.position.z-t.depth/2,n=t._mesh.position.z+t.depth/2,a=Ss*3/4,l=a,h=new T(t._mesh.position.x,l/2,s==="right"?r:n),c=new T(t._mesh.position.x,l/2,s==="right"?n:r),u=12e-5+Math.random()*6e-5;h.y+=l/8,c.y+=l/8;let d=Math.random();const f=XC[Math.floor(XC.length*Math.random())];for(let p=0;p<=e;p++){const _=new f(o,{direction:s,start:h,end:c,width:a,depth:a*3,height:l,pathProgress:d,velocity:u});i.push(_),d=(d+1/e)%1}return i},YC=[c6],v6=(o,e,t)=>{e=Math.max(2,e);const i=[],s=Math.random()<.5?"right":"left",r=5e-5+Math.random()*3e-5,n=t._mesh.position.z-t.depth/2,a=t._mesh.position.z+t.depth/2,l=Ss*3/4,h=l,c=new T(t._mesh.position.x,-h/2,s==="right"?n:a),u=new T(t._mesh.position.x,-h/2,s==="right"?a:n);let d=Math.random();const f=YC[Math.floor(YC.length*Math.random())];for(let p=0;p<=e;p++){const _=new f(o,{direction:s,start:c,end:u,width:l,depth:l*4,height:h,velocity:r,pathProgress:d});i.push(_),d=(d+1/e)%1}return i};class x6 extends rl{constructor(t,i){super(t);Nt(this,"width");Nt(this,"depth");Nt(this,"height");Nt(this,"objects",[]);Nt(this,"isEmpty");Nt(this,"tileType",zC[Math.floor(zC.length*Math.random())]);this.isEmpty=!!i.isEmpty,this.isEmpty&&(this.tileType="empty"),this.width=i.width,this.depth=i.depth,this.height=this.tileType==="river"?Ss*7/8:Ss,this.mesh=an.CreateBox("TILE-MESH",{width:this.width,height:this.height,depth:this.depth},t),this._mesh.position=new T(i.x,-Ss/2,i.z),this._mesh.material=new De("TILE-MESH-MATERIAL",t),this._mesh.material instanceof De&&(this._mesh.material.diffuseColor=this.tileType==="track"?new Te(.15,.15,.15):this.tileType==="river"?new Te(.5,.75,.85):new Te(.6,.85,.5)),this.collisionType=this.tileType==="river"?"dynamic":"none"}addWaterLimit(t){const[i,s]=[new $C(t,{position:this._mesh.position.clone().add(new T(0,this.height/2,+this.depth/2-this.width/8)),size:this.width}),new $C(t,{position:this._mesh.position.clone().add(new T(0,this.height/2,-this.depth/2+this.width/8)),size:this.width})];t.addEntity(i),this.objects.push(i),t.addEntity(s),this.objects.push(s)}onEnterScene(t){const i=1+Math.floor(3*Math.random()),s=this.isEmpty?m6:this.tileType==="nature"?HC:this.tileType==="track"?g6:this.tileType==="river"?v6:HC;switch(this.objects=s(t,i,this),this.objects.forEach(r=>t.addEntity(r)),this.tileType){case"river":this.addWaterLimit(t);break}}update(t,i){this.objects.forEach(s=>s.update(t,i))}kill(){super.kill(),this.objects.forEach(t=>{this.scene.removeMesh(t._mesh),t.kill()}),this.objects=[]}}class $C extends rl{constructor(e,t){super(e),this._mesh=an.CreateBox("WATER-LIMIT-MESH",{width:t.size,depth:t.size/4,height:t.size/4}),this._mesh.position=t.position.clone(),this.mesh.material=new De("WATER-LIMIT-MESH-MATERIAL",e),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=Te.White()),this.collisionType="dynamic"}}const xl=class xl extends a6{constructor(t,i){super(t,i);Nt(this,"player");Nt(this,"tiles",[]);Nt(this,"farthestAwayPlayerXCoordinate",0);Nt(this,"farthestAwayTileXCoordinate",0);Nt(this,"closestLimitXCoordinate",-1e4);Nt(this,"sideLimits",[]);Nt(this,"gameAreaLimits",[]);Nt(this,"updateCamera",(t,i)=>{this.farthestAwayPlayerXCoordinate=Math.max(this.farthestAwayPlayerXCoordinate,this.player._mesh.position.x);const s=new T(-90,90,-32).scale(1),r=this.player.mesh.position.multiply(new T(1,0,1));r.x=Math.max(this.farthestAwayPlayerXCoordinate,r.x),this.camera.position=r.add(s),this.camera.setTarget(r)});Nt(this,"handleTileLifeCycle",(t,i)=>{const s=Ss*15;this.farthestAwayTileXCoordinate-this.player.mesh.position.x=r;){const n=this.tiles[0].tile._mesh.position.x;if(n>this.closestLimitXCoordinate){const a=this.tiles.shift();a==null||a.tile.kill();const l=new Pv(this,{depth:xl.TILE_DEPTH,width:Ss,z:0,x:n});this.gameAreaLimits.push(l),this.addEntity(l),this.closestLimitXCoordinate=n}else break}for(;this.sideLimits[0]._mesh.position.xt.tile.kill()),this.sideLimits.forEach(t=>t.kill()),this.gameAreaLimits.forEach(t=>t.kill()),this.tiles=[],this.sideLimits=[],this.gameAreaLimits=[],this.farthestAwayPlayerXCoordinate=0,this.farthestAwayTileXCoordinate=0,this.closestLimitXCoordinate=-1e4}addTile(t,i=!1){const s=new x6(this,{depth:xl.TILE_DEPTH,width:Ss,z:0,x:t,isEmpty:i});this.tiles.push({tile:s,x:t}),this.addEntity(s),this.farthestAwayTileXCoordinate=t;const[r,n]=[new Pv(this,{depth:xl.TILE_DEPTH,width:Ss,z:-xl.TILE_DEPTH,x:t}),new Pv(this,{depth:xl.TILE_DEPTH,width:Ss,z:xl.TILE_DEPTH,x:t})];this.sideLimits.push(r),this.addEntity(r),this.sideLimits.push(n),this.addEntity(n)}setUpInitialTiles(){for(let i=-3*5;i<5*2;i++){const s=i*Ss;this.addTile(s,i<=0)}}update(t){super.update(t),this.updateHandlers.forEach(i=>i(this.app,t))}};Nt(xl,"TILE_DEPTH",Ss*20);let j_=xl;window.CANNON=BN;const wA=document.getElementsByTagName("canvas");if(i6.isEmpty(wA))throw new s6("Canvas not found");const T6=wA[0],FA=new re(T6,!0),sx=new n6(FA);sx.createScene("home",new j_(sx));sx.runRenderLoop();window.addEventListener("resize",()=>{FA.resize()}); +}`;var Oi=BS(function(){return os(J,kt+"return "+tt).apply(t,pe)});if(Oi.source=tt,qg(Oi))throw Oi;return Oi}function kO(m){return fs(m).toLowerCase()}function GO(m){return fs(m).toUpperCase()}function zO(m,x,y){if(m=fs(m),m&&(y||x===t))return YT(m);if(!m||!(x=ga(x)))return m;var F=co(m),z=co(x),J=$T(F,z),pe=KT(F,z)+1;return zl(F,J,pe).join("")}function WO(m,x,y){if(m=fs(m),m&&(y||x===t))return m.slice(0,jT(m)+1);if(!m||!(x=ga(x)))return m;var F=co(m),z=KT(F,co(x))+1;return zl(F,0,z).join("")}function HO(m,x,y){if(m=fs(m),m&&(y||x===t))return m.replace(Wt,"");if(!m||!(x=ga(x)))return m;var F=co(m),z=$T(F,co(x));return zl(F,z).join("")}function XO(m,x){var y=L,F=B;if(Js(x)){var z="separator"in x?x.separator:z;y="length"in x?Ai(x.length):y,F="omission"in x?ga(x.omission):F}m=fs(m);var J=m.length;if(uc(m)){var pe=co(m);J=pe.length}if(y>=J)return m;var xe=y-dc(F);if(xe<1)return F;var Pe=pe?zl(pe,0,xe).join(""):m.slice(0,xe);if(z===t)return Pe+F;if(pe&&(xe+=Pe.length-xe),jg(z)){if(m.slice(xe).search(z)){var Ke,je=Pe;for(z.global||(z=dg(z.source,fs(ct.exec(z))+"g")),z.lastIndex=0;Ke=z.exec(je);)var tt=Ke.index;Pe=Pe.slice(0,tt===t?xe:tt)}}else if(m.indexOf(ga(z),xe)!=xe){var At=Pe.lastIndexOf(z);At>-1&&(Pe=Pe.slice(0,At))}return Pe+F}function YO(m){return m=fs(m),m&&da.test(m)?m.replace(Qr,ER):m}var $O=xc(function(m,x,y){return m+(y?" ":"")+x.toUpperCase()}),Jg=VE("toUpperCase");function LS(m,x,y){return m=fs(m),x=y?t:x,x===t?mR(m)?bR(m):oR(m):m.match(x)||[]}var BS=Fi(function(m,x){try{return _a(m,t,x)}catch(y){return qg(y)?y:new mi(y)}}),KO=cl(function(m,x){return Wa(x,function(y){y=Oo(y),ll(m,y,$g(m[y],m))}),m});function qO(m){var x=m==null?0:m.length,y=si();return m=x?Ys(m,function(F){if(typeof F[1]!="function")throw new Ha(n);return[y(F[0]),F[1]]}):[],Fi(function(F){for(var z=-1;++zae)return[];var y=w,F=Sn(m,w);x=si(x),m-=w;for(var z=hg(F,x);++y0||x<0)?new Wi(y):(m<0?y=y.takeRight(-m):m&&(y=y.drop(m)),x!==t&&(x=Ai(x),y=x<0?y.dropRight(-x):y.take(x-m)),y)},Wi.prototype.takeRightWhile=function(m){return this.reverse().takeWhile(m).reverse()},Wi.prototype.toArray=function(){return this.take(w)},Mo(Wi.prototype,function(m,x){var y=/^(?:filter|find|map|reject)|While$/.test(x),F=/^(?:head|last)$/.test(x),z=Y[F?"take"+(x=="last"?"Right":""):x],J=F||/^find/.test(x);z&&(Y.prototype[x]=function(){var pe=this.__wrapped__,xe=F?[1]:arguments,Pe=pe instanceof Wi,Ke=xe[0],je=Pe||xi(pe),tt=function(Ui){var $i=z.apply(Y,Ll([Ui],xe));return F&&At?$i[0]:$i};je&&y&&typeof Ke=="function"&&Ke.length!=1&&(Pe=je=!1);var At=this.__chain__,kt=!!this.__actions__.length,ni=J&&!At,Oi=Pe&&!kt;if(!J&&je){pe=Oi?pe:new Wi(this);var ai=m.apply(pe,xe);return ai.__actions__.push({func:qp,args:[tt],thisArg:t}),new Xa(ai,At)}return ni&&Oi?m.apply(this,xe):(ai=this.thru(tt),ni?F?ai.value()[0]:ai.value():ai)})}),Wa(["pop","push","shift","sort","splice","unshift"],function(m){var x=Ep[m],y=/^(?:push|sort|unshift)$/.test(m)?"tap":"thru",F=/^(?:pop|shift)$/.test(m);Y.prototype[m]=function(){var z=arguments;if(F&&!this.__chain__){var J=this.value();return x.apply(xi(J)?J:[],z)}return this[y](function(pe){return x.apply(xi(pe)?pe:[],z)})}}),Mo(Wi.prototype,function(m,x){var y=Y[x];if(y){var F=y.name+"";xs.call(mc,F)||(mc[F]=[]),mc[F].push({name:x,func:y})}}),mc[zp(t,v).name]=[{name:"wrapper",func:t}],Wi.prototype.clone=YR,Wi.prototype.reverse=$R,Wi.prototype.value=KR,Y.prototype.at=CM,Y.prototype.chain=bM,Y.prototype.commit=yM,Y.prototype.next=AM,Y.prototype.plant=IM,Y.prototype.reverse=PM,Y.prototype.toJSON=Y.prototype.valueOf=Y.prototype.value=MM,Y.prototype.first=Y.prototype.head,Ou&&(Y.prototype[Ou]=RM),Y},fc=yR();Ch?((Ch.exports=fc)._=fc,tg._=fc):pn._=fc}).call(Yu)})(q_,q_.exports);var i6=q_.exports;class s6 extends Error{constructor(e){super(`[DomSetup] ${e}`)}}class kC extends Error{constructor(e){super(`[AppError] ${e}`)}}class GC{constructor(e){Nt(this,"key");Nt(this,"used");this.key=e.key,this.used=e.used||!1}}class r6{constructor(){Nt(this,"singletonInstance",null);Nt(this,"keyState",new Map);Nt(this,"keyDownHandler",e=>{e.preventDefault();const{key:t}=e;this.keyState.set(t,new GC({key:t}))});Nt(this,"keyUpHandler",e=>{e.preventDefault();const{key:t}=e;this.keyState.has(t)&&this.keyState.delete(t)});if(this.singletonInstance)return this.singletonInstance;this.keyState=new Map,addEventListener("keydown",this.keyDownHandler),addEventListener("keyup",this.keyUpHandler),this.singletonInstance=this}clear(){removeEventListener("keydown",this.keyDownHandler),removeEventListener("keyup",this.keyUpHandler)}wasPressedOnce(e){var i;let t=!1;return this.keyState.has(e)&&(t=!((i=this.keyState.get(e))!=null&&i.used),this.keyState.set(e,new GC({key:e,used:!0}))),t}isBeingPressed(e){return!!this.keyState.has(e)}}class n6{constructor(e){Nt(this,"input",{keyboardHandler:new r6});Nt(this,"currentScene");Nt(this,"allScenes",new Map);this.engine=e}createScene(e,t){this.allScenes.set(e,t),this.currentScene||(this.currentScene=t)}goToScene(e){this.allScenes.has(e)?this.currentScene=this.allScenes.get(e):console.warn(`The scene with key ${e} was not found! Keeping previous scene!`)}runRenderLoop(){if(!this.currentScene)throw new kC("No default scene was configured!");this.engine.runRenderLoop(()=>{const e=this.engine.getDeltaTime();if(!this.currentScene)throw new kC("Trying to render undefined scene!");this.currentScene.update(e),this.currentScene.render(!0)})}}class a6 extends Qe{constructor(t,i){super(t.engine);Nt(this,"entities",[]);Nt(this,"_camera");Nt(this,"_light");this.app=t,this.enablePhysics(i!=null&&i.gravity?i.gravity:T.Down().scale(9.8),new U_),this._camera=new zn("BASE-CAMERA",T.Up().scale(50),this),this._camera.attachControl(t.engine.getRenderingCanvas(),!0),this._light=new ro("BASE-LIGHT",T.Down(),this)}update(t){this.entities.forEach(i=>this.entities.forEach(s=>{i!==s&&i.collisionType!=="none"&&s.collisionType!=="none"&&i.mesh.intersectsMesh(s.mesh)&&(i.onCollision(s,this.app),s.onCollision(i,this.app))})),this.entities.forEach(i=>i.update(this.app,t)),this.entities=this.entities.filter(i=>i.isAlive)}addEntity(t){this.entities.push(t),t.onEnterScene(this)}set camera(t){this._camera.detachControl(),this._camera.dispose(),this._camera=t,this._camera.attachControl(this.app.engine.getRenderingCanvas(),!0)}get camera(){return this._camera}set light(t){this._light.dispose(),this._light=t}get light(){return this._light}}class rl{constructor(e){Nt(this,"_mesh");Nt(this,"isAlive",!0);Nt(this,"collisionType","none");Nt(this,"meshChildren",[]);this.scene=e,this._mesh=new se("BASE-MESH")}update(e,t){}onCollision(e,t){}onEnterScene(e){}kill(){this.isAlive=!1,this.mesh&&this.scene.removeMesh(this.mesh),this.meshChildren.forEach(e=>this.scene.removeMesh(e.mesh))}set mesh(e){this._mesh=e}get mesh(){return this._mesh}}class o6{static useParabolaCurve(e){const t=e.min?e.min:0,i=e.max,s=i-t,r=t+s/2;return a=>{a=Math.min(i,Math.max(a,t));let l=0;return a<=r?l=a/r:l=1-(a-r)/r,Math.min(1,Math.max(l,0))}}}class NA{static useLinearPath(e){const t=e.start,i=e.end;return r=>{const n=Math.min(1,Math.max(r,0)),a=t.x+(i.x-t.x)*n,l=t.y+(i.y-t.y)*n,h=t.z+(i.z-t.z)*n;return new T(a,l,h)}}}class l6{static findRotationAngleBasedOnDirection(e){return e==="top"?0:e==="right"?Math.PI/2:e==="bottom"?Math.PI:Math.PI*3/2}}class h6 extends rl{constructor(t,i){super(t);Nt(this,"direction");Nt(this,"start");Nt(this,"end");Nt(this,"velocity");Nt(this,"pathProgress");Nt(this,"previousPathProgress",0);Nt(this,"width");Nt(this,"height");Nt(this,"depth");Nt(this,"pathMap");this.width=i.width,this.height=i.height,this.depth=i.depth,this.direction=i.direction,this.start=i.start,this.end=i.end,this.pathProgress=i.pathProgress,this.velocity=i.velocity,this.pathMap=NA.useLinearPath({start:this.start,end:this.end}),this.collisionType="dynamic";const s=new Te(.15,.15,.15);this.mesh=an.CreateBox("CAR-MESH",{width:this.width,depth:this.depth,height:this.height/2},t),this.mesh.position=i.start,this.mesh.material=new De("CAR-MESH-MATERIAL",t),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=Te.Random());const r=T.Down().scale(30),n=an.CreateBox("CAR-MESH",{width:this.width,depth:this.depth/2,height:this.height/2},t);n.position=r,n.material=new De("CAR-MESH-MATERIAL",t),n.material instanceof De&&(n.material.diffuseColor=s),this.meshChildren.push({mesh:n,anchorToParent:new T(0,this.height/2,0)});const a=an.CreateCylinder("CAR-MESH",{height:this.width*1.1,diameter:this.height*5/8});a.position=r,a.rotation=new T(0,0,Math.PI/2),a.material=new De("CAR-MESH-MATERIAL",t),a.material instanceof De&&(a.material.diffuseColor=s),this.meshChildren.push({mesh:a,anchorToParent:new T(0,-this.height/6,this.depth/3)});const l=an.CreateCylinder("CAR-MESH",{height:this.width*1.1,diameter:this.height*5/8});l.position=r,l.rotation=new T(0,0,Math.PI/2),l.material=new De("CAR-MESH-MATERIAL",t),l.material instanceof De&&(l.material.diffuseColor=s),this.meshChildren.push({mesh:l,anchorToParent:new T(0,-this.height/6,-this.depth/3)})}update(t,i){const s=this.direction==="right"?1:-1,r=this.velocity*i*s;this.pathProgress=(this.pathProgress+r*s+1)%1,(this.direction==="right"?this.pathProgress{n.position=this._mesh.position.add(a)}),this.previousPathProgress=this.pathProgress}}class c6 extends rl{constructor(t,i){super(t);Nt(this,"direction");Nt(this,"start");Nt(this,"end");Nt(this,"pathProgress");Nt(this,"velocity");Nt(this,"pathMap");this.mesh=an.CreateBox("LOG-MESH",{width:i.width,depth:i.depth,height:i.height},t),this.mesh.position=i.start,this.mesh.material=new De("LOG-MESH-MATERIAL",t),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=new Te(.6,.5,.3)),this.direction=i.direction;const s=this.direction==="right"?1:-1;this.start=i.start.clone().add(new T(0,0,i.depth*-s)),this.end=i.end.clone().add(new T(0,0,i.depth*s)),this.pathProgress=i.pathProgress,this.velocity=i.velocity,this.pathMap=NA.useLinearPath({start:this.start,end:this.end}),this.collisionType="platform"}update(t,i){const s=this.direction==="right"?1:-1,r=this.velocity*i*s;this.pathProgress=(this.pathProgress+r*s+1)%1,this._mesh.position=this.pathMap(this.pathProgress)}}const Ss=16;class u6{constructor(e){this.scene=e}getClosestTile(e,t){return this.scene.tiles.find(i=>Math.abs(e-i.x)<=t)}}const d6=()=>{const o=new Map;let e="idle";return{state:()=>e,transition:i=>{const s=e;switch(e){case"idle":switch(i){case"move":e="moving";break;case"stop":e="idle";break;case"bind-to-platform":e="on-platform";break;case"move-back":break;case"die":e="dead";break}break;case"moving":switch(i){case"move":e="moving";break;case"stop":e="idle";break;case"move-back":e="moving-back";break;case"bind-to-platform":break;case"die":e="dead";break}break;case"moving-back":switch(i){case"stop":e="idle";break;case"move-back":e="moving-back";break;case"move":case"bind-to-platform":break;case"die":e="dead";break}break;case"on-platform":switch(i){case"stop":e="idle";break;case"move":e="moving";break;case"move-back":case"bind-to-platform":break;case"die":e="dead";break}break}s!==e&&(o.get(e)||[]).forEach(n=>n())},registerCallback:(i,s)=>{o.has(i)?o.set(i,[...o.get(i),s]):o.set(i,[s])}}},Sd=class Sd extends rl{constructor(t,i){super(t);Nt(this,"scene");Nt(this,"particles",[]);Nt(this,"life",0);const s=20;for(let r=0;rSd.TTL){this.kill(),this.scene.restart();return}this.life+=i}kill(){super.kill(),this.particles.forEach(t=>t.kill())}};Nt(Sd,"TTL",1e3);let tx=Sd;class f6 extends rl{constructor(t,i){super(t);Nt(this,"pointingTo");Nt(this,"ttl");Nt(this,"life",0);this._mesh=an.CreateBox("PARTICLE-MESH",{size:Ss/16},t),this.mesh.material=new De("PLAYER-MESH-MATERIAL",t),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=Math.random()<.5?Te.White():Te.Red()),this.mesh.position=i.start,this.ttl=i.TTL;const s=()=>-1+Math.floor(3*Math.random());this.pointingTo=new T(s(),s(),s())}update(t,i){this.life+=i,this.mesh.position=this.mesh.position.add(this.pointingTo.scale(.01*i)),this.mesh.material&&(this.mesh.material.alpha=1-this.life/this.ttl)}}const Q_=class Q_ extends rl{constructor(t,i){super(t);Nt(this,"stateMachine");Nt(this,"jumpCurrDistance",0);Nt(this,"direction","top");Nt(this,"width");Nt(this,"depth");Nt(this,"height");Nt(this,"platform");Nt(this,"platformCenterOffset");Nt(this,"tiledSceneNavigator");Nt(this,"scene");this.scene=t;const s=i!=null&&i.size?i.size:Ss,r=Te.Red();this.width=s,this.height=s*2,this.depth=s,this.mesh=an.CreateBox("PLAYER-MESH",{height:this.height,depth:this.depth,width:this.width},t),i!=null&&i.position&&(this.mesh.position=i.position),this.mesh.material=new De("PLAYER-MESH-MATERIAL",t),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=Te.White());const n=T.Down().scale(30),a=an.CreateBox("PLAYER-MESH",{height:this.height/2,depth:this.depth,width:this.width/2},t);a.position=n,a.material=new De("PLAYER-MESH-MATERIAL",t),a.material instanceof De&&(a.material.diffuseColor=Te.White()),this.meshChildren.push({mesh:a,anchorToParent:new T(-this.width*3/4,-this.height/4,0)});const l=an.CreateBox("PLAYER-MESH",{height:this.height/8,depth:this.depth/4,width:this.width/2},t);l.position=n,l.material=new De("PLAYER-MESH-MATERIAL",t),l.material instanceof De&&(l.material.diffuseColor=r),this.meshChildren.push({mesh:l,anchorToParent:new T(0,this.height*9/16,0)});const h=an.CreateBox("PLAYER-MESH",{height:this.height/8,depth:this.depth/2,width:this.width/4},t);h.position=n,h.material=new De("PLAYER-MESH-MATERIAL",t),h.material instanceof De&&(h.material.diffuseColor=new Te(.95,.65,.2)),this.meshChildren.push({mesh:h,anchorToParent:new T(this.width*5/8,this.height/4,0)});const c=an.CreateBox("PLAYER-MESH",{height:this.height/8,depth:this.depth/4,width:this.width/4},t);c.position=n,c.material=new De("PLAYER-MESH-MATERIAL",t),c.material instanceof De&&(c.material.diffuseColor=r),this.meshChildren.push({mesh:c,anchorToParent:new T(this.width*5/8,this.height/8,0)}),this.stateMachine=d6(),this.stateMachine.registerCallback("moving",()=>this.jumpCurrDistance=0),this.stateMachine.registerCallback("idle",()=>{this._mesh.position=new T(Math.round(this._mesh.position.x),Math.round(this._mesh.position.y),Math.round(this._mesh.position.z))}),this.collisionType="dynamic",t instanceof j_&&(this.tiledSceneNavigator=new u6(t))}updateJump(t,i){const s=this.stateMachine.state();if(s==="moving-back"&&this.jumpCurrDistance<=0||s==="moving"&&this.jumpCurrDistance>=Ss){this.stateMachine.transition("stop");return}const r=.08*i,n=this.direction==="top"||this.direction==="bottom"?"x":(this.direction==="right"||this.direction==="left","z");let a=this.direction==="top"||this.direction==="left"?1:-1;if(s==="moving"){const l=Math.min(r,Ss-this.jumpCurrDistance);this.mesh.position[n]+=l*a,this.jumpCurrDistance+=l}else if(s==="moving-back"){const l=Math.min(r,this.jumpCurrDistance);a*=-1,this.mesh.position[n]+=l*a,this.jumpCurrDistance-=l}this.mesh.position.y=this.height/2+Q_.jumpVerticalDistanceCurve(this.jumpCurrDistance)*Ss}updatePlatform(t,i){this.platform&&this.platformCenterOffset&&(this._mesh.position=this.platform._mesh.position.add(this.platformCenterOffset))}handleIdle(t,i){var r;const s=(r=this.tiledSceneNavigator)==null?void 0:r.getClosestTile(this._mesh.position._x,this.depth);(s==null?void 0:s.tile.collisionType)==="dynamic"&&s.x>0&&this.handleDeath()}onCollision(t,i){i.engine.getFps()!==1/0&&(t.collisionType==="static"&&this.stateMachine.transition("move-back"),t.collisionType==="dynamic"&&this.scene&&this.handleDeath(),t.collisionType==="platform"&&(this.stateMachine.state()==="idle"&&(this.platform=t,this.platformCenterOffset=this._mesh.position.subtract(t._mesh.position)),this.stateMachine.transition("bind-to-platform")))}updateMesh(t,i){const s=l6.findRotationAngleBasedOnDirection(this.direction),r=new T(0,s,0);this._mesh.rotation=r,this.meshChildren.forEach(({mesh:n,anchorToParent:a})=>{n.rotation=r;const l=Se.FromEulerAngles(0,s,0),h=a.applyRotationQuaternion(l);n.position=this._mesh.position.add(h)})}handleDeath(){if(this.stateMachine.state()==="dead")return;this.stateMachine.transition("die"),this.mesh.material&&(this.mesh.material.alpha=0),this.meshChildren.forEach(s=>{s.mesh.material&&(s.mesh.material.alpha=0)});const t=this._mesh.position.clone(),i=new tx(this.scene,{start:t});this.scene.addEntity(i)}update(t,i){if(t.engine.getFps()===1/0)return;const{input:{keyboardHandler:s}}=t,r=this.stateMachine.state();switch(r){case"idle":case"on-platform":s.wasPressedOnce("ArrowUp")||s.wasPressedOnce(" ")?(this.direction="top",this.stateMachine.transition("move")):s.wasPressedOnce("ArrowDown")&&(this.direction="bottom",this.stateMachine.transition("move")),s.wasPressedOnce("ArrowRight")?(this.direction="right",this.stateMachine.transition("move")):s.wasPressedOnce("ArrowLeft")&&(this.direction="left",this.stateMachine.transition("move")),r==="on-platform"&&this.updatePlatform(t,i),r==="idle"&&this.handleIdle(t,i);break;case"moving":case"moving-back":this.updateJump(t,i);break}this.updateMesh(t,i)}};Nt(Q_,"jumpVerticalDistanceCurve",o6.useParabolaCurve({min:0,max:Ss}));let ix=Q_;class Pv extends rl{constructor(t,i){super(t);Nt(this,"width");Nt(this,"depth");this.width=i.width,this.depth=i.depth;const s=Ss;this.mesh=an.CreateBox("LIMIT-MESH",{width:this.width,height:s*1.1,depth:this.depth},t),this._mesh.position=new T(i.x,-Ss/2,i.z),this._mesh.material=new De("TILE-MESH-MATERIAL",t),this._mesh.material instanceof De&&(this._mesh.material.diffuseColor=new Te(.05,.05,.05)),this.collisionType="static"}}class p6 extends rl{constructor(e,t){super(e);const i=Ss/2,s=new Te(.45,.45,.45);this.mesh=an.CreateBox("STONE-MESH",{size:i},e),this.mesh.position=new T(t.x,i/2,t.z),this.mesh.material=new De("STONE-MESH-MATERIAL",e),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=s);const r=an.CreateBox("STONE-MESH",{size:i/2},e);r.position=new T(t.x,i*5/4,t.z),r.material=new De("STONE-MESH-MATERIAL",e),r.material instanceof De&&(r.material.diffuseColor=s),this.meshChildren.push({mesh:r,anchorToParent:T.Zero()}),this.collisionType="static"}}class _6 extends rl{constructor(e,t){super(e);const i=Ss*1/4,s=Ss*2;this.mesh=an.CreateBox("TREE-MESH",{width:i,depth:i,height:s},e),this.mesh.position=new T(t.x,s/2,t.z),this.mesh.material=new De("TREE-MESH-MATERIAL",e),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=new Te(.55,.45,.3));const r=an.CreateBox("TREE-MESH",{size:Ss},e);r.position=new T(t.x,s,t.z),r.material=new De("TREE-MESH-MATERIAL",e),r.material instanceof De&&(r.material.diffuseColor=new Te(.5,.7,.4)),this.meshChildren.push({mesh:r,anchorToParent:T.Zero()}),this.collisionType="static"}}const zC=["nature","empty","track","river"],WC=[p6,_6],HC=(o,e,t)=>{const i=[],s=t._mesh.position.z-t.depth/2,r=t._mesh.position.z+t.depth/2;for(let n=0;n[],XC=[h6],g6=(o,e,t)=>{const i=[],s=Math.random()<.5?"right":"left";e=Math.min(2,e);const r=t._mesh.position.z-t.depth/2,n=t._mesh.position.z+t.depth/2,a=Ss*3/4,l=a,h=new T(t._mesh.position.x,l/2,s==="right"?r:n),c=new T(t._mesh.position.x,l/2,s==="right"?n:r),u=12e-5+Math.random()*6e-5;h.y+=l/8,c.y+=l/8;let d=Math.random();const f=XC[Math.floor(XC.length*Math.random())];for(let p=0;p<=e;p++){const _=new f(o,{direction:s,start:h,end:c,width:a,depth:a*3,height:l,pathProgress:d,velocity:u});i.push(_),d=(d+1/e)%1}return i},YC=[c6],v6=(o,e,t)=>{e=Math.max(2,e);const i=[],s=Math.random()<.5?"right":"left",r=5e-5+Math.random()*3e-5,n=t._mesh.position.z-t.depth/2,a=t._mesh.position.z+t.depth/2,l=Ss*3/4,h=l,c=new T(t._mesh.position.x,-h/2,s==="right"?n:a),u=new T(t._mesh.position.x,-h/2,s==="right"?a:n);let d=Math.random();const f=YC[Math.floor(YC.length*Math.random())];for(let p=0;p<=e;p++){const _=new f(o,{direction:s,start:c,end:u,width:l,depth:l*4,height:h,velocity:r,pathProgress:d});i.push(_),d=(d+1/e)%1}return i};class x6 extends rl{constructor(t,i){super(t);Nt(this,"width");Nt(this,"depth");Nt(this,"height");Nt(this,"objects",[]);Nt(this,"isEmpty");Nt(this,"tileType",zC[Math.floor(zC.length*Math.random())]);this.isEmpty=!!i.isEmpty,this.isEmpty&&(this.tileType="empty"),this.width=i.width,this.depth=i.depth,this.height=this.tileType==="river"?Ss*7/8:Ss,this.mesh=an.CreateBox("TILE-MESH",{width:this.width,height:this.height,depth:this.depth},t),this._mesh.position=new T(i.x,-Ss/2,i.z),this._mesh.material=new De("TILE-MESH-MATERIAL",t),this._mesh.material instanceof De&&(this._mesh.material.diffuseColor=this.tileType==="track"?new Te(.15,.15,.15):this.tileType==="river"?new Te(.5,.75,.85):new Te(.6,.85,.5)),this.collisionType=this.tileType==="river"?"dynamic":"none"}addWaterLimit(t){const[i,s]=[new $C(t,{position:this._mesh.position.clone().add(new T(0,this.height/2,+this.depth/2-this.width/8)),size:this.width}),new $C(t,{position:this._mesh.position.clone().add(new T(0,this.height/2,-this.depth/2+this.width/8)),size:this.width})];t.addEntity(i),this.objects.push(i),t.addEntity(s),this.objects.push(s)}onEnterScene(t){const i=1+Math.floor(3*Math.random()),s=this.isEmpty?m6:this.tileType==="nature"?HC:this.tileType==="track"?g6:this.tileType==="river"?v6:HC;switch(this.objects=s(t,i,this),this.objects.forEach(r=>t.addEntity(r)),this.tileType){case"river":this.addWaterLimit(t);break}}update(t,i){this.objects.forEach(s=>s.update(t,i))}kill(){super.kill(),this.objects.forEach(t=>{this.scene.removeMesh(t._mesh),t.kill()}),this.objects=[]}}class $C extends rl{constructor(e,t){super(e),this._mesh=an.CreateBox("WATER-LIMIT-MESH",{width:t.size,depth:t.size/4,height:t.size/4}),this._mesh.position=t.position.clone(),this.mesh.material=new De("WATER-LIMIT-MESH-MATERIAL",e),this.mesh.material instanceof De&&(this.mesh.material.diffuseColor=Te.White()),this.collisionType="dynamic"}}const xl=class xl extends a6{constructor(t,i){super(t,i);Nt(this,"player");Nt(this,"tiles",[]);Nt(this,"farthestAwayPlayerXCoordinate",0);Nt(this,"farthestAwayTileXCoordinate",0);Nt(this,"closestLimitXCoordinate",-1e4);Nt(this,"sideLimits",[]);Nt(this,"gameAreaLimits",[]);Nt(this,"updateCamera",(t,i)=>{this.farthestAwayPlayerXCoordinate=Math.max(this.farthestAwayPlayerXCoordinate,this.player._mesh.position.x);const s=new T(-90,90,-32).scale(1),r=this.player.mesh.position.multiply(new T(1,0,1));r.x=Math.max(this.farthestAwayPlayerXCoordinate,r.x),this.camera.position=r.add(s),this.camera.setTarget(r)});Nt(this,"handleTileLifeCycle",(t,i)=>{const s=Ss*15;this.farthestAwayTileXCoordinate-this.player.mesh.position.x=r;){const n=this.tiles[0].tile._mesh.position.x;if(n>this.closestLimitXCoordinate){const a=this.tiles.shift();a==null||a.tile.kill();const l=new Pv(this,{depth:xl.TILE_DEPTH,width:Ss,z:0,x:n});this.gameAreaLimits.push(l),this.addEntity(l),this.closestLimitXCoordinate=n}else break}for(;this.sideLimits[0]._mesh.position.xt.tile.kill()),this.sideLimits.forEach(t=>t.kill()),this.gameAreaLimits.forEach(t=>t.kill()),this.tiles=[],this.sideLimits=[],this.gameAreaLimits=[],this.farthestAwayPlayerXCoordinate=0,this.farthestAwayTileXCoordinate=0,this.closestLimitXCoordinate=-1e4}addTile(t,i=!1){const s=new x6(this,{depth:xl.TILE_DEPTH,width:Ss,z:0,x:t,isEmpty:i});this.tiles.push({tile:s,x:t}),this.addEntity(s),this.farthestAwayTileXCoordinate=t;const[r,n]=[new Pv(this,{depth:xl.TILE_DEPTH,width:Ss,z:-xl.TILE_DEPTH,x:t}),new Pv(this,{depth:xl.TILE_DEPTH,width:Ss,z:xl.TILE_DEPTH,x:t})];this.sideLimits.push(r),this.addEntity(r),this.sideLimits.push(n),this.addEntity(n)}setUpInitialTiles(){for(let i=-3*5;i<5*2;i++){const s=i*Ss;this.addTile(s,i<=0)}}update(t){super.update(t),this.updateHandlers.forEach(i=>i(this.app,t))}};Nt(xl,"TILE_DEPTH",Ss*20);let j_=xl;window.CANNON=BN;const wA=document.getElementsByTagName("canvas");if(i6.isEmpty(wA))throw new s6("Canvas not found");const T6=wA[0],FA=new re(T6,!0),sx=new n6(FA);sx.createScene("home",new j_(sx));sx.runRenderLoop();window.addEventListener("resize",()=>{FA.resize()});document.addEventListener("keydown",o=>o.preventDefault()); diff --git a/docs/index.html b/docs/index.html index 24804ce..df6adc5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,7 @@ Crossy Road | saacostam - + diff --git a/src/main.ts b/src/main.ts index 4ba6811..9eb996e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,3 +25,5 @@ app.runRenderLoop(); window.addEventListener("resize", () => { engine.resize(); }); + +document.addEventListener('keydown', e => e.preventDefault());