@korial29/tiny-fps 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.js +7 -6
- package/dist/local.js +1 -1
- package/dist/server.js +22 -10
- package/dist/types/client/audio.d.ts +11 -2
- package/dist/types/client/effects.d.ts +3 -0
- package/dist/types/client/hud.d.ts +15 -5
- package/dist/types/client/progress.d.ts +14 -4
- package/dist/types/client/sfx.d.ts +2 -0
- package/dist/types/shared/protocol.d.ts +7 -1
- package/dist/types/shared/room.d.ts +2 -1
- package/dist/types/shared/types.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -189,7 +189,7 @@ Keys are read by their position (`KeyboardEvent.code`), so on an AZERTY keyboard
|
|
|
189
189
|
- **Health**: 9 points. A hit takes one, then you can't be hurt for a second. A dead player comes back at the start 3 s later. Every 4th kill leaves a health pack.
|
|
190
190
|
- **Keys and gates**: red, blue and yellow keys open the barred gates of their colour, for the whole team.
|
|
191
191
|
- **The way out**: the start room locks behind you. Touch the goal to open it, then the level is won once every living player is back inside.
|
|
192
|
-
- **Five levels**: Warm-up, Foundry, Cistern, Loop and Citadel. Then the run starts over in hard mode, with faster monsters that strike and fire more often. The end screen shows the time.
|
|
192
|
+
- **Five levels**: Warm-up, Foundry, Cistern, Loop and Citadel. Then the run starts over in hard mode, with faster monsters that strike and fire more often. The end screen shows the time and each player's kills and deaths.
|
|
193
193
|
- **Sound**: every sound is synthesised in code and placed left or right by where it comes from; a dark music loops under it. The sound starts with the click that locks the pointer.
|
|
194
194
|
- **Dark levels**: your flashlight casts shadows, and so do muzzle flashes. Explosions, hits, bullets, the goal and the open exit light up their surroundings.
|
|
195
195
|
|
|
@@ -208,7 +208,7 @@ Parity with the js13k game is tracked in [`docs/PARITY.md`](docs/PARITY.md).
|
|
|
208
208
|
- [x] Five levels, the goal and the way back, hard mode on the next run, end screen with the time
|
|
209
209
|
- [x] Flashlights with shadow maps, lit muzzle flashes, explosion, hit, bullet, goal and exit lights
|
|
210
210
|
- [x] Sound: a jsfxr-style synthesiser (shot, boom, hit, collect, clock, burst), stereo by position, a looped music; M mutes
|
|
211
|
-
- [
|
|
211
|
+
- [x] HUD and screens: health bar, damage vignette and pickup fades, low-health pulse and heartbeat, title and pause screen, death countdown, end screen with each player's kills and deaths
|
|
212
212
|
- [x] Shadow DOM, zero runtime dependencies, size-gated in CI
|
|
213
213
|
|
|
214
214
|
---
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var e=.4,t=1.8,n=1.6,r=1.55,i=.5,a=.02,o=1.8,s=.45,c=.9,l=.15,u={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,FIRE:32},d={WALKER:0,FLYER:1},f={DIE:0,HURT:1,BOOM:2,SWING:3},p={HEALTH:0,KEY_RED:1,KEY_BLUE:2,KEY_YELLOW:3},m={HUNT:0,RETURN:1},h={BRICK:0,TILE:1,LAVA:2,STONE:3},g=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r)));let r={map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}})),barred:/* @__PURE__ */ new Set};return _(r,0,m.HUNT),r},_=({map:e,barred:t},n,r)=>{t.clear(),e.gates?.forEach(e=>n&1<<e.key||t.add(e.sector)),e.exit!==void 0&&r===m.HUNT&&t.add(e.exit)},v=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),y=({map:e},t,n)=>e.sectors.findIndex(e=>v(e,t,n)),b=({map:e,edges:t},[n,r,i],[a,o,s])=>{let[c,l]=[a-n,s-i];return t.some(t=>{let[a,s]=[t.bx-t.ax,t.bz-t.az],u=c*s-l*a;if(!u)return!1;let d=((t.ax-n)*s-(t.az-i)*a)/u,f=((t.ax-n)*l-(t.az-i)*c)/u;if(d<=0||d>=1||f<0||f>1)return!1;if(t.back<0)return!0;let[p,m]=[e.sectors[t.front],e.sectors[t.back]],h=r+d*(o-r);return h<Math.max(p.floor,m.floor)||h>Math.min(p.ceil,m.ceil)})},x=(e,[t,n,r,i],a,o,s,c,l,u)=>Array.from({length:s},(d,f)=>{let[p,m]=e?[n,i]:[t,r],[h,g,_]=[p+f*(m-p)/s,p+(f+1)*(m-p)/s,+(a+f*o).toFixed(1)];return e?[t,h,r,g,_,c,l,u]:[h,n,g,i,_,c,l,u]}),[S,C,w,T]=[p.HEALTH,p.KEY_RED,p.KEY_BLUE,p.KEY_YELLOW],E=Math.PI/4,D=(e,[t,n,r],i,a,o,s)=>{let c=e.map(([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r]]),l=[...new Map(c.flat().map(e=>[`${e}`,e])).values()];return{sectors:e.map(([,,,,e,t,n=`103`,r],i)=>({pts:c[i].flatMap((e,t,n)=>{let r=n[(t+1)%4],i=t=>(t[0]-e[0])*(r[0]-e[0])+(t[1]-e[1])*(r[1]-e[1]);return[e,...l.filter(t=>(r[0]-e[0])*(t[1]-e[1])===(r[1]-e[1])*(t[0]-e[0])&&i(t)>0&&i(t)<(r[0]-e[0])**2+(r[1]-e[1])**2).sort((e,t)=>i(e)-i(t))]}),floor:e,ceil:t,ft:+n[0],wt:+n[1],ct:+n[2],light:r})),spawns:Array.from({length:16},(e,i)=>[t+i%4*2,n+(i>>2)*2,r*E]),monsters:[...i.map(([e,t,n])=>[e,t,n*E,d.WALKER]),...a.map(([e,t,n])=>[e,t,n*E,d.FLYER])],items:o,gates:e.flatMap(([,,,,,,,,e],t)=>e?[{sector:t,key:e}]:[]),goal:s,exit:0}},O=[D([[0,0,10,10,0,4,`103`],[10,4,22,6,0,2.8,`333`,.6],[22,0,38,14,0,6,`303`],...x(0,[38,4,42,10],.4,.4,4,6,`333`),[42,2,52,12,2,6,`103`,.9],...x(1,[46,12,48,22],1.6,-.4,4,4.8,`000`,.7),[38,22,56,36,0,6,`113`]],[2,2,6],[[28,4,3],[34,10,4],[48,6,4],[44,30,0]],[[30,8,0],[52,28,2]],[[26,12,S],[50,10,S],[40,34,S]],[54,34]),D([[0,14,10,26,0,4,`103`],[10,22,20,24,0,2.8,`333`,.6],[24,8,28,16,0,9,`303`],[20,16,28,30,0,9,`303`],...x(1,[20,8,24,16],2,-.4,5,9,`333`),[28,8,42,18,-1.6,9,`203`,.9],...x(1,[28,18,42,21],-1.2,.4,3,9,`333`),[28,21,50,30,0,9,`303`],[42,8,50,21,0,9,`303`],[20,0,50,8,2.4,9,`103`,.8],[50,14,51,17,0,3.5,`000`,1,C],[51,8,59,26,0,7,`113`,.6],[59,8,67,26,.4,7,`013`,.8],[57,26,59,36,0,4.8,`000`,.7],[50,36,68,50,0,7,`013`]],[2,16,6],[[46,14,2],[36,26,0],[38,4,2],[56,12,4],[62,20,2],[60,44,0]],[[35,13,0],[60,14,4],[58,42,6]],[[24,26,S],[24,4,S],[64,10,S],[52,46,S],[46,4,C]],[66,48]),D([[0,20,10,32,0,4,`103`],[10,26,20,28,0,2.8,`333`,.6],[20,14,56,26,0,11,`133`,.9],[20,26,34,32,0,11,`133`,.9],[34,26,42,32,-.4,11,`233`],[42,26,56,32,0,11,`133`,.9],[20,32,56,44,0,11,`133`,.9],[36,44,38,54,0,1.9,`333`,.45],[30,54,46,68,0,5,`000`,.7],[56,28,57,31,0,4,`000`,1,C],...x(0,[57,26,65,32],.4,.4,8,10,`333`,.8),[65,22,81,36,3.6,11,`103`],[71,36,74,37,3.6,7,`000`,1,w],[71,37,74,48,3.6,6.4,`333`,.6],[62,48,82,64,3.6,10,`213`]],[2,22,6],[[30,18,4],[50,20,4],[30,40,0],[50,40,0],[36,60,2],[42,64,0],[76,28,2],[70,58,0]],[[26,24,0],[48,22,0],[36,40,2],[72,56,4]],[[24,40,S],[52,42,S],[44,57,S],[68,34,S],[64,62,S],[38,66,C],[79,24,w]],[80,62]),D([[0,44,10,56,0,4,`103`],[10,49,20,51,0,2.8,`333`,.6],[20,30,52,40,0,9,`303`],[20,48,52,58,0,9,`303`,.9],[20,40,32,48,0,9,`303`],[40,40,52,48,0,9,`303`],[20,22,49,30,3.2,9,`113`,.8],[34,58,36,66,0,2.8,`333`,.5],[26,66,46,84,0,5,`000`,.5],[52,42,53,45,0,4,`000`,1,C],[53,36,64,54,0,6,`133`,.8],[64,36,70,54,.4,6,`233`,.8],[60,35,63,36,0,4,`000`,1,w],[57,12,77,35,0,8,`013`,.9],[56,24,57,27,0,4,`000`,1,T],...x(0,[49,22,56,30],2.8,-.4,7,9,`333`,.8),[12,24,20,28,3.2,6,`333`,.6],[0,10,12,34,3.2,9,`113`]],[2,46,6],[[30,36,4],[44,36,2],[40,52,0],[40,26,4],[30,74,6],[42,78,2],[56,40,6],[64,50,2],[62,18,4],[72,28,2],[6,22,0]],[[28,48,0],[46,44,4],[36,72,0],[60,45,6],[68,22,4]],[[24,54,S],[24,26,S],[44,80,S],[68,38,S],[74,14,S],[36,82,C],[68,52,w],[74,32,T]],[6,13]),D([[0,60,10,72,0,4,`103`],[10,65,24,67,0,2.8,`333`,.6],[24,48,56,84,0,12,`313`],[27,40,31,48,0,3.4,`000`,.5],[24,16,34,40,0,12,`303`,.9],...x(0,[34,16,40,26],-.4,-.4,3,12,`233`),[34,26,40,30,0,12,`333`],...x(0,[34,30,40,40],-.4,-.4,3,12,`233`),[40,16,60,40,0,12,`303`,.9],[60,27,61,30,0,4,`000`,1,T],[61,10,101,16,0,14,`103`],[61,40,101,46,0,14,`103`],[61,16,69,40,0,14,`103`],[93,16,101,40,0,14,`103`],[69,16,93,20,.4,14,`233`,.9],[69,36,93,40,.4,14,`233`,.9],[69,20,73,36,.4,14,`233`,.9],[89,20,93,36,.4,14,`233`,.9],[73,20,89,36,.8,14,`333`],[101,26,111,28,0,3.2,`333`,.6],[111,16,131,40,0,8,`113`],[56,66,57,69,0,4,`000`,1,C],[57,56,75,80,0,12,`000`,.7],...x(0,[75,60,85,72],.4,.4,5,12,`333`,.8),[85,52,101,80,2.4,12,`013`],[38,84,42,85,0,4,`000`,1,w],[38,85,42,95,0,1.9,`000`,.4],[28,95,56,115,0,6,`030`,.6]],[2,62,6],[[34,56,4],[50,56,2],[36,76,0],[46,20,4],[54,34,2],[66,60,2],[66,76,0],[92,60,2],[34,100,4],[50,108,2],[70,13,4],[92,13,2],[70,43,0],[92,43,6]],[[30,70,0],[46,68,0],[50,28,0],[76,26,0],[86,30,0],[81,22,0]],[[30,80,S],[56,36,S],[60,78,S],[50,112,S],[64,13,S],[98,43,S],[114,38,S],[52,22,C],[95,66,w],[42,110,T]],[127,36])],k=65536/(2*Math.PI),A=e=>Math.round(e*k)&65535,j=e=>Math.max(-32768,Math.min(32767,Math.round(e))),M=e=>j(e*1e4),N=e=>e/1e4,P=e=>e/k,F=(e=0)=>Math.round(e*256)&16777215,I=e=>({...e,yaw:P(A(e.yaw)),pitch:N(M(e.pitch)),...e.view!==void 0&&{view:F(e.view)/256}}),ee=e=>{let t=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(11));t.setUint8(0,1),t.setUint16(1,e.seq&65535),t.setUint8(3,e.keys&255),t.setUint16(4,A(e.yaw)),t.setInt16(6,M(e.pitch));let n=F(e.view);return t.setUint16(8,n>>8),t.setUint8(10,n&255),t.buffer},te=e=>{if(e.byteLength<7)return null;let t=new DataView(e),n=t.getUint8(3);if(t.getUint8(0)!==2)return null;let r=7+25*n,[i,a,o,s,c]=[14,16,13,14,14].map(n=>{if(e.byteLength<=r)return null;let i=t.getUint8(r),a=r+1;return r=a+n*i,[a,i]});if(!i||!a||!o||!s||!c||e.byteLength!==r)return null;let l=([e,t],n,r)=>Array.from({length:t},(t,i)=>r(e+i*n)),u=[];for(let e=0;e<n;e++){let n=7+e*25;u.push({id:t.getUint8(n),x:t.getFloat32(n+1),y:t.getFloat32(n+5),z:t.getFloat32(n+9),vy:t.getFloat32(n+13),yaw:P(t.getUint16(n+17)),pitch:N(t.getInt16(n+19)),ack:t.getUint16(n+21),cool:t.getUint8(n+23)>>1,ground:(t.getUint8(n+23)&1)==1,hp:t.getUint8(n+24)})}return{tick:t.getUint16(1),players:u,shots:l(i,14,e=>({id:t.getUint8(e),x:t.getFloat32(e+1),y:t.getFloat32(e+5),z:t.getFloat32(e+9),hit:t.getUint8(e+13)===255?-1:t.getUint8(e+13)})),monsters:l(a,16,e=>({id:t.getUint8(e),kind:t.getUint8(e+1)&1,chase:!!(t.getUint8(e+1)&2),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10),yaw:P(t.getUint16(e+14))})),bullets:l(o,13,e=>({id:t.getUint8(e),x:t.getFloat32(e+1),y:t.getFloat32(e+5),z:t.getFloat32(e+9)})),events:l(s,14,e=>({type:t.getUint8(e),id:t.getUint8(e+1),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10)})),level:t.getUint8(4),hard:(t.getUint8(5)&1)==1,phase:t.getUint8(5)>>1&1,keys:t.getUint8(6),items:l(c,14,e=>({id:t.getUint8(e),kind:t.getUint8(e+1),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10)}))}},L=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},R=44100,z={SHOT:0,BOOM:1,HIT:2,COLLECT:3,CLOCK:4,BURST:5},ne=([e,t,n,r,i,a,o,s,c,l,u],d)=>{let f=new Float32Array(Math.ceil((r+i+a)*R)),p=0,m=0,h=0,g=()=>{d=d+1831565813|0;let e=Math.imul(d^d>>>15,1|d);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/2**31-1};for(let d=0;d<f.length;d++){let _=d/R;p+=t*2**(n*_)*(_>c?l:1)*(1+o*Math.sin(_*44))/R,p>=1&&(p%=1,h=g());let v=e==3?h:e==2?Math.sin(p*2*Math.PI):e?1-2*p:p<.5?1:-1;m+=(v-m)*s;let y=_<r?_/r:_<r+i?1:((r+i+a-_)/a)**2;f[d]=m*y*u}return f},re=[[[3,7e3,-.5,.002,0,.06,0,.6,0,1,.8],[0,220,-5,.002,0,.075,0,.3,0,1,.5]],[[3,500,-1.5,.004,.05,.8,0,.1,0,1,2.2],[2,110,-1.5,.004,.05,.6,0,1,0,1,.8]],[[1,160,-1.5,.003,.04,.22,.2,.5,0,1,.6],[0,83,-1,.003,.04,.22,0,.3,0,1,.4],[3,3e3,0,.002,0,.12,0,.4,0,1,.5]],[[2,880,.3,.005,.06,.4,0,1,.09,1.5,.8],[2,1760,.3,.005,.06,.35,0,1,.09,1.5,.3]],[[3,4e3,0,.001,0,.025,0,.5,0,1,.7],[2,1300,-1,.001,0,.04,0,1,0,1,.5]],[[3,1200,-1,.002,0,.14,0,.45,0,1,.7],[0,3200,-1,.002,0,.05,0,1,.025,.7,.2]]],B=e=>{let t=re[e].map((t,n)=>ne(t,e*9+n));return Float32Array.from({length:Math.max(...t.map(e=>e.length))},(e,n)=>Math.tanh(t.reduce((e,t)=>e+(t[n]??0),0)))},V=R*60/108,ie=V/4,H=4,ae=[2,150,-6,.002,0,.25,0,1,0,1,1],oe=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],se=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],ce=()=>{let e=new Float32Array(V*4*H),t={},n=(n,r)=>(t[String(r)]??=ne(r,1)).forEach((t,r)=>e[(n*ie+r)%e.length]+=t),r=e=>55*2**(e/12),i=[0,0,-4,-5],a=[0,0,12,0,0,7,12,7];for(let e=0;e<64;e++){let t=e%16;if(`x.......x.x.....`[t]==`x`&&n(e,ae),`....x.......x...`[t]==`x`&&n(e,oe),t%2==0){n(e,se);let o=i[e>>4]+a[t>>1];n(e,[1,r(o),0,.005,.08,.18,0,.15,0,1,.6])}}[15,12,10,19,17,15].forEach((e,t)=>n([18,24,28,50,54,60][t],[2,r(e+24),0,.02,.1,.6,.01,1,0,1,.5]));let o=e.reduce((e,t)=>Math.max(e,Math.abs(t)),0);return e.map(e=>e/o*.35)},le=40,ue=24,de=.5,fe=`tiny-fps:muted`,pe=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},me=()=>{let e;try{e=new AudioContext}catch{return pe()}let t=(t,n=1)=>{let r=e.createGain();return r.gain.value=n,r.connect(t),r},n=t(e.destination),r=t(n,de),i=[],a=/* @__PURE__ */ new Set,o=[0,0,0],s=0,c=!1,l=t=>{let n=e.createBuffer(1,t.length,R);return n.getChannelData(0).set(t),n},u=t=>{let n=e.createBufferSource();return n.buffer=t,n};return{unlock(){if(e.resume().catch(()=>{}),!i.length){for(let e of Object.values(z))i[e]=l(B(e));let e=u(l(ce()));e.loop=!0,e.connect(r),e.start()}},listen(e,t){[o,s]=[e,t]},play(r,c){let l=0,d=1;if(c){let[e,t,n]=c.map((e,t)=>e-o[t]),r=Math.hypot(e,t,n);d=Math.max(0,1-r/le)**2,l=(e*Math.cos(s)-n*Math.sin(s))/Math.max(r,1)}let f=i[r];if(!f||!d)return;if(a.size>=ue){let e=[...a].reduce((e,t)=>t.vol<e.vol?t:e);if(e.vol>=d)return;e.src.stop(),a.delete(e)}let p=u(f),m=e.createStereoPanner();m.pan.value=l,p.connect(m).connect(t(n,d));let h={vol:d,src:p};a.add(h),p.onended=()=>a.delete(h),p.start()},mute(t){c=t,n.gain.setTargetAtTime(+!t,e.currentTime,.05)},get muted(){return c},destroy:()=>void e.close().catch(()=>{})}},he=(e,{type:t,id:n,x:r,y:i,z:a},o)=>{let s=[r,i,a];t==f.DIE?e.play(z.BOOM,s):t==f.BOOM?e.play(z.BURST,s):t==f.HURT&&e.play(z.HIT,n==o?void 0:s)},ge=e=>{let t=0;return(n,r)=>{n&&r>=t&&(t=r+1e3,e.play(z.CLOCK))}},_e=()=>{try{return localStorage.getItem(fe)==`1`}catch{return!1}},ve=e=>{e.mute(!e.muted);try{localStorage.setItem(fe,e.muted?`1`:`0`)}catch{}return e.muted},ye=1/60,U=Math.PI*2,be=1e-6,xe=.01,Se=e=>(e%U+U)%U,Ce=e=>[-Math.sin(e),-Math.cos(e)],we=Math.fround,Te=(e,t,n)=>Math.min(Math.max(e,t),n),Ee=({map:e,barred:t},n,r,i,a)=>{if(n.back<0||t.has(n.back))return!0;let o=e.sectors[n.front],s=e.sectors[n.back],c=Math.min(o.ceil,s.ceil);return s.floor>r+a+xe||c-Math.max(o.floor,s.floor)<i-xe||c<r+i-xe},De=(e,t,n,r,i)=>{let a=(n-be)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=Te((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!Ee(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},Oe=(e,t,n,r,i,a,o)=>{let{map:s,edges:c}=e,l=Math.max(y(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-be)**2;for(let i of c){if(i.front!==l||i.back<0)continue;let c=i.bx-i.ax,p=i.bz-i.az,m=t-i.ax,h=n-i.az,g=Te((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!Ee(e,i,r,a,o)){let e=s.sectors[i.back];u=Math.max(u,e.floor),d=Math.min(d,e.ceil)}}return[u,d]},ke=(n,r,a,o,s)=>{n.x+=r,n.z+=a,De(n,s,e,t,i);let[c,l]=Oe(s,n.x,n.z,n.y,e,t,i);n.ground&&o&&(n.vy=7);let u=n.vy-20*ye;n.y+=(n.vy+u)/2*ye,n.vy=u,n.ground=!1,n.y+1.8>l&&(n.y=l-t,n.vy=Math.min(n.vy,0)),(n.vy<=0?n.y<=c+xe:n.y<c)&&(n.y=c,n.vy<=0&&(n.vy=0,n.ground=!0)),n.x=we(n.x),n.y=we(n.y),n.z=we(n.z),n.vy=we(n.vy)},Ae=(e,t,n)=>{let i=(t.keys&u.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=Se(t.yaw),e.pitch=Math.max(-1.55,Math.min(r,t.pitch));let a=(t.keys&u.FORWARD?1:0)-(t.keys&u.BACK?1:0),o=(t.keys&u.RIGHT?1:0)-(t.keys&u.LEFT?1:0),s=6*ye*(i?.5:1)/(Math.hypot(a,o)||1),[c,l]=Ce(e.yaw);return ke(e,(c*a-l*o)*s,(l*a+c*o)*s,(t.keys&u.JUMP)!==0,n),i&&!e.cool?(e.cool=5,!0):!1},je=.55,Me=6,Ne=(e,t,n=[0,0,0])=>{let r=[];for(let i=1;i<e.length;i++){let[[a,o],[s,c]]=[e[i-1],e[i]],l=Math.hypot(s-a,c-o);if(!l)continue;let[u,d]=[(c-o)/l,-(s-a)/l],f=(e,i,a)=>{let[o,s]=[Math.cos(e*U/t),Math.sin(e*U/t)];r.push(n[0]+i*o,n[1]+i*s,n[2]-a,u*o,u*s,-d)};for(let e=0;e<t;e++)for(let[t,n,r]of[[e,a,o],[e+1,a,o],[e+1,s,c],[e,a,o],[e+1,s,c],[e,s,c]])f(t,n,r)}return r},Pe=e=>{let t=[];for(let n=0;n<Me;n++){let r=n*U/Me;t.push(...Ne([[0,0],[.02,0],[.02,.45],[.014,.45],[.014,.55],[0,.55]],e,[Math.cos(r)*.05,Math.sin(r)*.05,0]))}return{barrels:t,body:Ne([[0,-.3],[.08,-.3],[.09,-.26],[.09,0],[.075,0],[.075,.1],[.03,.1],[.03,.4],[0,.4]],e)}},W=(e,t,n=0)=>{let[r,i,a,o,s,c]=[e,t,n].flatMap(e=>[Math.sin(e),Math.cos(e)]),l=[i,0,-r],u=[r*a,o,i*a];return[l.map((e,t)=>e*c-u[t]*s),u.map((e,t)=>e*c+l[t]*s),[-r*o,a,-i*o]]},G=(e,[t,n,r],[i,a,o],s,c,l=-1)=>{let[u,d]=[Math.sin(s),Math.cos(s)],f=(e,t)=>[e*d+t*u,-e*u+t*d];for(let s=0;s<3;s++)for(let u of[-1,1]){let[d,p]=[(s+1)%3,(s+2)%3],m=[0,0,0];m[s]=u;let[h,g]=f(m[0],m[2]);for(let[_,v]of[[-1,-1],[1,-1],[1,1],[-1,-1],[1,1],[-1,1]]){let y=[0,0,0];[y[s],y[d],y[p]]=[u,_,v];let[b,x]=f(y[0]*i,y[2]*o);e.push(t+b,n+y[1]*a,r+x,h,m[1],g,c[0],c[1],l,c[2])}}},K=(e,[t,n,r])=>Array.from({length:e.length*(10/6)},(i,a)=>{let[o,s]=[Math.floor(a/10),a%10];return s<6?e[o*6+s]:[t,n,-1,r][s-6]}),q=(e,t,n,[r,i,a],o,s,c=0)=>{let[l,u]=[Math.sin(c),Math.cos(c)],d=(e,t,n)=>[0,1,2].map(o=>r[o]*(e*u-t*l)+i[o]*(e*l+t*u)-a[o]*n),f=[0,1,2].map(e=>n[e]+r[e]*o[0]+i[e]*o[1]+a[e]*o[2]);for(let n=0;n<t.length;n+=10){let r=d(t[n]*s,t[n+1]*s,t[n+2]*s);e.push(f[0]+r[0],f[1]+r[1],f[2]+r[2],...d(t[n+3],t[n+4],t[n+5])),e.push(...t.slice(n+6,n+10))}},Fe=.3,Ie=3.6,J={body:[.27,.22,.25],arm:[.4,.26,.22],leg:[.18,.17,.22],head:[.45,.33,.3],shell:[.36,.2,.32],fin:[.5,.25,.25],gore:[.6,.08,.07],calm:[.6,.05,.04],chase:[1,.3,.15],blob:[1,.3,.05],core:[1,.8,.4]},Le=[[J.body,J.arm,J.head,J.gore,J.gore,J.chase],[J.shell,J.fin,J.shell,J.gore,J.chase]],Re=e=>e?J.chase:J.calm,Y=({x:e,y:t,z:n,yaw:r},i,a,o)=>{let[s,c]=[Math.sin(r),Math.cos(r)];return[e+i*c-o*s,t+a,n-i*s-o*c]},ze=(e,t,n,r,i,a)=>{let o=[];G(o,[0,-i[1],0],i,0,a),q(e,o,t,W(n,r),[0,0,0],1)},Be=e=>e<.25?-.8*Math.sin(e*4*Math.PI):2*Math.sin((e-.25)*Math.PI/.75),Ve=(e,t,n,r)=>{let i=Math.sin(n*Ie)*.6,a=o*.44,s=o*.8,[c,l]=[-1,1].map(e=>Y(t,e*.16,a,0));ze(e,c,t.yaw,i,[.09,a/2,.09],J.leg),ze(e,l,t.yaw,-i,[.09,a/2,.09],J.leg),ze(e,Y(t,-.35,s,0),t.yaw,-i*.8,[.07,.34,.07],J.arm),ze(e,Y(t,.35,s,0),t.yaw,i*.8+(r>0?Be(r):0),[.07,.34,.07],J.arm),G(e,Y(t,0,1.142,0),[.26,.35,.16],t.yaw,J.body),G(e,Y(t,0,1.6500000000000001,0),[.15,.15,.15],t.yaw,J.head);let u=t.chase?.06:.045;for(let n of[-1,1])G(e,Y(t,n*.075,1.69,.15),[u,u*.7,.02],t.yaw,Re(t.chase),-2)},He=K(Ne([[0,0],[.18,.06],[s,.32],[s*.93,.5],[.22,.78],[0,c]],8),J.shell),Ue=(e,t,n)=>{let r=Math.sin(n*2+t.id)*.06,i=[t.x,t.y+r,t.z];q(e,He,i,W(0,Math.PI/2),[0,0,0],1);for(let r=0;r<4;r++){let a=n*1.5+r*U/4;G(e,[t.x+Math.cos(a)*.4,i[1]+.35,t.z+Math.sin(a)*.4],[.16,.03,.04],-a,J.fin)}let a=Y({...t,y:i[1]},0,c*.45,s*.9),o=t.chase?1.3:1;G(e,a,[.1*o,.07*o,.05],t.yaw,Re(t.chase),-2)},We=(e,t,n)=>{let r=[t.x,t.y,t.z];if(G(e,r,[l*.8,l*.8,l*.8],0,J.blob,-2),G(e,r,[l*.5,l*.5,l*.5],Math.PI/4,J.core,-2),n)for(let t of[1,2]){let i=l*(1-t*.3);G(e,r.map((e,r)=>e-n[r]*t*.2),[i,i,i],0,J.blob,-2)}},Ge=.05,Ke=.3,qe=96,Je=64,Ye=12,Xe=.3,Ze=.15,Qe=.4,$e=.5,et=.9,tt=.3,nt=14,rt=4.4,it=.035,at=.03,ot=30,st=({r:e,t})=>{let n=t/Xe;return n<1?e*Math.sqrt(n)*(1-n*n*n):0},ct=(e=64)=>{let t=[];return{clear(){t=[]},push(n,r){t.push(...n.map(e=>({t:r,v:e}))),t.splice(0,t.length-e)},due(e){let n=t.findIndex(({t})=>t+100>e);return t.splice(0,n<0?t.length:n).map(({v:e})=>e)}}},lt=(e=Math.random,t)=>{let r=t,i=0,a=0,o=0,s=0,c=0,l,d=()=>e()*2-1,p=/* @__PURE__ */ new Map,m=(e,t,n,r)=>{_.sparks.length<qe&&_.sparks.push({p:e,v:t,life:n,c:r})},h=(t,n,r,i)=>{for(let a=0;a<n;a++){let[n,a]=[e()*U,d()],o=Math.sqrt(1-a*a)*r*(.5+e()*.5);m(t,[Math.cos(n)*o,a*r,Math.sin(n)*o],Ke*(.6+e()*.4),i)}},g=(e,t)=>{_.blasts.push({p:e,r:t,t:0}),_.blasts.splice(0,_.blasts.length-Ye)},_={bob:0,roll:0,shakeYaw:0,shakePitch:0,kick:0,spin:0,flash:0,flashes:/* @__PURE__ */ new Map,sparks:[],gibs:[],blasts:[],hurt:0,gain:0,gainC:[1,1,1],dead:0,swings:/* @__PURE__ */ new Map,herd:/* @__PURE__ */ new Map,aim:/* @__PURE__ */ new Map,update(e,t,r,f=!1){let p=Math.min(1,r*10),m=e&&l?.ground&&e.ground?Math.hypot(e.x-l.x,e.z-l.z):0;m<1&&(i+=m*rt),a+=(+(m>.5*r&&m<1)-a)*p,l=e,_.dead=Math.max(0,Math.min(1,_.dead+(f?r:-r)/$e));let h=_.dead*_.dead*(3-2*_.dead);_.bob=Math.sin(i)*it*a-h*(n-tt);let g=+!!(t&u.RIGHT)-!!(t&u.LEFT);s+=(g*at-s)*Math.min(1,r*8),_.roll=s+h*et,o*=Math.exp(-r*12),_.shakeYaw=d()*o,_.shakePitch=d()*o,_.kick*=Math.exp(-r*18),_.flash=Math.max(0,_.flash-r);for(let[e,t]of _.flashes)t>r?_.flashes.set(e,t-r):_.flashes.delete(e);c=Math.max(0,Math.min(ot,c+(t&u.FIRE?60:-25)*r)),_.spin=(_.spin+c*r)%U;for(let e of _.sparks)e.v[1]-=9.8*r,e.p=e.p.map((t,n)=>t+e.v[n]*r),e.life-=r;_.sparks=_.sparks.filter(e=>e.life>0),_.hurt=Math.max(0,_.hurt-r),_.gain=Math.max(0,_.gain-r);for(let[e,t]of _.swings)t>r?_.swings.set(e,t-r):_.swings.delete(e);for(let e of _.blasts)e.t+=r;_.blasts=_.blasts.filter(e=>e.t<Xe);for(let e of _.gibs)e.life-=r,e.rest||v(e,r);_.gibs=_.gibs.filter(e=>e.life>0)},hit(){_.hurt=Ze},pickup(e){[_.gain,_.gainC]=[Qe,e]},reset(e){r=e,_.sparks=[],_.gibs=[],_.blasts=[],_.flashes.clear(),_.swings.clear(),_.herd.clear(),_.aim.clear(),p.clear(),_.hurt=_.gain=_.flash=0},shot(t,n,r,i=!0){r?(_.kick=1,_.flash=Ge,o=.012):_.flashes.set(t.id,Ge);let a=[t.x,t.y,t.z],s=n.map((e,t)=>e-a[t]),c=Math.hypot(...s);if(i&&c>0&&c<99.99)for(let t=0;t<4;t++){let t=s.map(t=>t/c*(2+e()*2)+d());t[1]+=1,m(a,t,Ke*(.6+e()*.4))}},track(e,t){for(let{id:t,kind:n,x:r,z:i}of e){let e=_.herd.get(t),a=e?Math.hypot(r-e.x,i-e.z):0;_.herd.set(t,{x:r,z:i,kind:n,walked:(e?.walked??0)+(a<1?a:0)})}let n=/* @__PURE__ */ new Map;for(let{id:e,x:r,y:i,z:a}of t){let[t,o]=[p.get(e),[r,i,a]],s=t?Math.hypot(o[0]-t[0],o[1]-t[1],o[2]-t[2]):0;t&&s>1e-4&&_.aim.set(e,o.map((e,n)=>(e-t[n])/s)),n.set(e,o)}p=n;for(let e of _.aim.keys())n.has(e)||_.aim.delete(e)},event({type:t,id:n,x:i,y:a,z:o},s){let c=[i,a,o];if(t==f.DIE){let t=Le[_.herd.get(n)?.kind??0]??Le[0],s=10+Math.floor(e()*7);for(let n=0;n<s;n++){let n=e()*U,s=1.5+e()*3.5;_.gibs.push({p:[i,a+d()*.3,o],v:[Math.cos(n)*s,2+e()*4,Math.sin(n)*s],yaw:e()*U,size:.05+e()*.08,c:t[Math.floor(e()*t.length)],life:2+e(),floor:r?.map.sectors[y(r,i,o)]?.floor??a,rest:!1})}_.gibs.splice(0,_.gibs.length-Je),g(c,.6),h(c,14,5)}else t==f.BOOM?(g(c,.25),h(c,8,3)):t==f.HURT?n!=s&&h(c,8,3,[1,.12,.08]):t==f.SWING&&_.swings.set(n,Fe)}},v=(e,t)=>{e.v[1]-=nt*t;let n=e.p.map((n,r)=>n+e.v[r]*t);r&&b(r,e.p,n)&&(e.v[0]*=-.3,e.v[2]*=-.3,[n[0],n[2]]=[e.p[0],e.p[2]]);let i=r?.map.sectors[y(r,n[0],n[2])];e.floor=i?.floor??e.floor,i&&n[1]>i.ceil-e.size&&(n[1]=i.ceil-e.size,e.v[1]=Math.min(e.v[1],0)*.3),n[1]<=e.floor+e.size&&(n[1]=e.floor+e.size,e.v[1]<-3?e.v=[e.v[0]*.5,-e.v[1]*.3,e.v[2]*.5]:(e.v=[0,0,0],e.rest=!0)),e.p=n};return _},ut=[[1,1,1],[.95,.15,.1],[.2,.4,1],[1,.85,.15]],dt=(e,t=1)=>`rgba(${e.map(e=>Math.round(e*255))},${t})`,ft=.3,pt=[.25,1,.45],mt=[.85,.1,.1],ht=[.05,.05,.06],X=(e,[t,n,r],[i,a,o],s,c,l,u=-1)=>{let[d,f]=[Math.sin(c),Math.cos(c)];G(e,[t+i*f+o*d,n+a,r-i*d+o*f],s,c,l,u)},gt=(e,{id:t,kind:n,x:r,y:i,z:a},o)=>{let s=o*2+t,c=[r,i+(n?.55:.4)+Math.sin(o*2.5+t)*.07,a],l=ut[n];if(n==p.HEALTH){G(e,c,[.2,.2,.2],s,l);for(let t of[[.21,.06,.21],[.06,.21,.21],[.21,.21,.06]])G(e,c,t,s,mt)}else X(e,c,[0,.17,0],[.1,.1,.025],s,l,-2),X(e,c,[0,.17,0],[.04,.04,.035],s,ht),X(e,c,[0,-.1,0],[.025,.17,.025],s,l),X(e,c,[.06,-.24,0],[.05,.03,.025],s,l),X(e,c,[.045,-.15,0],[.035,.025,.025],s,l)},_t=({map:e},{front:t,back:n})=>{let[r,i]=[e.sectors[t],e.sectors[n]];return[Math.max(r.floor,i.floor),Math.min(r.ceil,i.ceil)]},vt=(e,t,n,r,i,a,o=-1)=>{let[s,c]=[t.bx-t.ax,t.bz-t.az];G(e,[(t.ax+t.bx)/2,n,(t.az+t.bz)/2],[Math.hypot(s,c)/2,r,i],Math.atan2(-c,s),a,o)},yt=(e,t,n)=>{let{gates:r=[],exit:i}=t.map;for(let{sector:n,key:i}of r){if(!t.barred.has(n))continue;let r=ut[i];for(let i of t.edges.filter(e=>e.front==n&&e.back>=0)){let[n,a]=_t(t,i),o=Math.ceil(Math.hypot(i.bx-i.ax,i.bz-i.az)/ft);for(let t=0;t<o;t++){let s=(t+.5)/o;G(e,[i.ax+(i.bx-i.ax)*s,(n+a)/2,i.az+(i.bz-i.az)*s],[.03,(a-n)/2,.03],0,r)}vt(e,i,n+.1,.04,.04,r),vt(e,i,a-.1,.04,.04,r)}}if(i!==void 0&&!t.barred.has(i)){let r=pt.map(e=>e*(.75+.25*Math.sin(n*4)));for(let n of t.edges.filter(e=>e.front==i&&e.back>=0)){let[i,a]=_t(t,n);for(let t of[i+.04,a-.04])vt(e,n,t,.04,.04,r,-2);for(let[t,o]of[[n.ax,n.az],[n.bx,n.bz]])G(e,[t,(i+a)/2,o],[.05,(a-i)/2,.05],0,r,-2)}}},bt=(e,t,n)=>{let r=t.map.goal,i=r&&t.map.sectors[y(t,r[0],r[1])]?.floor;if(!r||i===void 0)return;let a=Math.sin(n*4),[o,s]=[1*(.7+a*.07),[1,.85,.25].map(e=>e*(.75+a*.25))];for(let t of[0,1])G(e,[r[0],i+.03+t*.005,r[1]],[o,.03,o],n/2+t*Math.PI/4,s,-2);G(e,[r[0],i+.8+Math.sin(n*2)*.1,r[1]],[.15,.15,.15],n*2,[1,.95,.5],-2)},xt=(e,t,n,r)=>{for(let t of n)gt(e,t,r);yt(e,t,r),bt(e,t,r)},St={TITLE:0,NOTE:1,END:2},Ct=[2,3,6],wt=`h1,h2,h3,h4,h5,ul,ol{position:absolute;margin:0;padding:0;pointer-events:none;user-select:none;white-space:pre-line}h1,h2,h4{left:0;right:0;text-align:center}h1{top:14%;font-size:20px;line-height:1.4}h1::first-line{font-size:44px}h2{top:32%;font-size:22px}h4{top:45%;font-size:26px}h5{top:8px;right:12px;font-size:12px}h3{inset:0;padding-top:25%;text-align:center;background:#000b;font-size:22px;line-height:1.6}h3::first-line{font-size:48px}ul,ol{left:12px;display:flex;gap:3px;list-style:none}ul{bottom:12px}ol{bottom:38px}ul li{width:14px;height:18px;border-radius:2px;background:#e33;box-shadow:0 0 0 1px #0008}ol li{width:16px;height:9px;border-radius:2px;box-shadow:0 0 0 1px #0008}`,Tt=e=>{e.insertAdjacentHTML(`beforeend`,`<ul>${`<li></li>`.repeat(9)}</ul><ol>${`<li hidden></li>`.repeat(3)}</ol><h1 hidden></h1><h2 hidden></h2><h4 hidden>Respawning…</h4><h3 hidden></h3><h5 hidden>Muted (M)</h5>`);let t=t=>[...e.querySelectorAll(t)],[n,r]=[t(`ul li`),t(`ol li`)],i=[`h1`,`h2`,`h3`].map(t=>e.querySelector(t)),[a,o]=[`h4`,`h5`].map(t=>e.querySelector(t));r.forEach((e,t)=>e.style.background=dt(ut[t+1]));let s=Ct.map(()=>0);return{hp:e=>n.forEach((t,n)=>t.style.opacity=n<e?`1`:`0.2`),keys:e=>r.forEach((t,n)=>t.hidden=!(e>>n+1&1)),dead:e=>a.hidden=!e,mute:e=>o.hidden=!e,say(e,t){i[e].textContent=t,i[e].hidden=!1,s[e]=Ct[e]},update(e){s.forEach((t,n)=>{t>0&&(s[n]=t-e)<=0&&(i[n].hidden=!0)})}}},Et=.0025,Dt=Math.PI*2,Ot={KeyW:u.FORWARD,ArrowUp:u.FORWARD,KeyS:u.BACK,ArrowDown:u.BACK,KeyA:u.LEFT,ArrowLeft:u.LEFT,KeyD:u.RIGHT,ArrowRight:u.RIGHT,Space:u.JUMP},kt=e=>Ot[e]??0,At=(e,t=()=>{})=>{let n=new AbortController,i=(e,t,r)=>e.addEventListener(t,r,{signal:n.signal}),a={yaw:0,pitch:0,keys:0,locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>n.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{a.locked()&&(a.yaw=((a.yaw-e.movementX*Et)%Dt+Dt)%Dt,a.pitch=Math.max(-1.55,Math.min(r,a.pitch-e.movementY*Et)))}),i(document,`keydown`,e=>{let n=kt(e.code);e.code==`KeyM`&&!e.repeat&&a.locked()&&t(),n&&a.locked()&&(a.keys|=n,e.preventDefault())}),i(document,`keyup`,e=>{a.keys&=~kt(e.code)}),i(document,`mousedown`,e=>{e.button==0&&a.locked()&&(a.keys|=u.FIRE)}),i(document,`mouseup`,e=>{e.button==0&&(a.keys&=~u.FIRE)});let o=()=>{a.keys=0};return i(window,`blur`,o),i(document,`pointerlockchange`,()=>a.locked()||o()),a},jt=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},Mt=(e,t,n)=>{let[r,i,o,s]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],c=jt(n+1),l=(c&65535)/65536*U,u=(c>>>16)/65535,[d,f]=[Math.cos(l)*u*a,Math.sin(l)*u*a],p=[-r*s+i*d+r*o*f,o+s*f,-i*s-r*d+i*o*f],m=Math.hypot(...p);return[p[0]/m,p[1]/m,p[2]/m]},Nt=(e,t,n,r)=>{let{map:i,edges:a}=e,o=Math.max(y(e,t[0],t[2]),0),s=0;for(let e=0;e<=i.sectors.length;e++){let{floor:e,ceil:c}=i.sectors[o],l=1/0,u;for(let e of a){if(e.front!==o)continue;let[r,i]=[e.bx-e.ax,e.bz-e.az],a=n[2]*r-n[0]*i;if(a>=0)continue;let c=Math.max(((t[2]-e.az)*r-(t[0]-e.ax)*i)/-a,s),d=((t[0]+c*n[0]-e.ax)*r+(t[2]+c*n[2]-e.az)*i)/(r*r+i*i);d>-1e-9&&d<1+1e-9&&(c<l-1e-9||c<l+1e-9&&e.back<0)&&([l,u]=[c,e])}let d=n[1]<0?(e-t[1])/n[1]:n[1]>0?(c-t[1])/n[1]:1/0;if(d<=l||!u)return Math.min(Math.max(d,s),r);if(l>=r)return r;let f=t[1]+l*n[1],p=u.back<0?void 0:i.sectors[u.back];if(!p||f<Math.max(e,p.floor)||f>Math.min(c,p.ceil))return l;[o,s]=[u.back,l]}return s},Pt=(e,t,n)=>{let[r,i]=[e[0]-n.x,e[2]-n.z],a=t[0]*t[0]+t[2]*t[2],o=r*t[0]+i*t[2],s=r*r+i*i-n.r*n.r,[c,l]=[0,1/0];if(a>1e-12){let e=o*o-a*s;if(e<0)return 1/0;[c,l]=[Math.max(0,(-o-Math.sqrt(e))/a),(-o+Math.sqrt(e))/a]}else if(s>0)return 1/0;let[u,d]=[n.y-e[1],n.y+n.h-e[1]];if(t[1]){let[e,n]=[u/t[1],d/t[1]];c=Math.max(c,Math.min(e,n)),l=Math.min(l,Math.max(e,n))}else if(u>0||d<0)return 1/0;return c<=l?c:1/0},Ft=({id:n,x:r,y:i,z:a})=>({id:n,x:r,y:i,z:a,r:e,h:t}),It=({id:e,kind:t,x:n,y:r,z:i})=>{let a=t===d.WALKER;return{id:e,x:n,y:r,z:i,r:a?.4:s,h:a?o:c}},Lt=(e,t,r,i)=>{let a=[t.x,t.y+n,t.z],o=Mt(t.yaw,t.pitch,r),s=Nt(e,a,o,100),c=-1;for(let e of i){let n=e.id===t.id?1/0:Pt(a,o,e);n<s&&([s,c]=[n,e.id])}return{id:t.id,x:a[0]+o[0]*s,y:a[1]+o[1]*s,z:a[2]+o[2]*s,hit:c}},Rt=120,zt=16,Z=({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s,cool:c})=>({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s,cool:c}),Bt=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,z:e.z+(t.z-e.z)*n}),Vt=(e,t,n)=>Se(e+(((t-e+Math.PI)%U+U)%U-Math.PI)*n),Ht=(e,t)=>(t-e&65535)<32768,Ut=(e,t,n)=>({...t,...Bt(e,t,n),yaw:Vt(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),Wt=e=>{let t=e,n,r=0,i=[],a,o,s,c=!0,l=/* @__PURE__ */ new Map,u=[],d=e=>{let t=e-100,n=0;for(;n+1<u.length&&u[n+1].t<=t;)n++;let r=u[n],i=u[n+1]??r;return{a:r,b:i,u:i.t>r.t?Math.max(0,Math.min(1,(t-r.t)/(i.t-r.t))):0}},f=e=>{if(!u.length)return;let{a:t,b:n,u:r}=d(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536},p=e=>{let t=u.at(-1);if(!t)return[];let{a:r,b:i,u:a}=d(e);return t.s.players.filter(e=>e.id!==n).map(e=>{let t=r.s.players.find(t=>t.id===e.id),n=i.s.players.find(t=>t.id===e.id);return t&&n?Ut(Z(t),Z(n),a):Z(n??t??e)})},m=(e,t,n)=>{if(!u.length)return[];let{a:r,b:i,u:a}=d(e),o=t(r.s);return t(i.s).map(e=>{let t=o.find(t=>t.id===e.id);return t?n(t,e,a):e})},h=e=>m(e,e=>e.monsters,(e,t,n)=>({...t,...Bt(e,t,n),yaw:Vt(e.yaw,t.yaw,n)}));return{you:e=>{n=e},step:(e,n)=>{let d=I({...e,seq:r,view:n===void 0?void 0:f(n)});if(s=void 0,r=r+1&65535,i.push(d),i.length>Rt&&i.shift(),a&&(o=Z(a),c&&Ae(a,d,t))){let e=n??1/0,r=h(e).filter(e=>!l.has(e.id)),i=u.at(-1)?.s.players??[],o=p(e).filter(e=>i.find(t=>t.id===e.id)?.hp);s=Lt(t,a,d.seq,[...o.map(Ft),...r.map(It)]),s.hit>=16&&l.set(s.hit,d.seq)}return d},snapshot:(e,r)=>{u.push({t:r,s:e}),u.length>zt&&u.shift(),_(t,e.keys,e.phase);let s=e.players.find(e=>e.id===n);s&&(c=s.hp>0,i=i.filter(e=>!Ht(e.seq,s.ack)),l.forEach((t,n)=>{let r=e=>e.monsters.some(e=>e.id===n);Ht(t,s.ack)&&(r(e)||!u.some(e=>r(e.s)))&&l.delete(n)}),a=Z(s),o=Z(a),i.forEach((e,n)=>{n===i.length-1&&(o=Z(a)),c&&Ae(a,e,t)}))},monsters:h,bullets:e=>m(e,e=>e.bullets,(e,t,n)=>({...t,...Bt(e,t,n)})),level:e=>{t=e,u.length=0,l.clear(),a=o=s=void 0},shot:()=>s,me:e=>a&&o?Ut(o,a,Math.max(0,Math.min(1,e))):void 0,others:p}},Gt={SPOT:0,POINT:1},Kt=[1.2,1.1,.9],qt=[3,1.4,.4],Jt=Math.cos(.436),Yt=.5,Xt=2,Zt=4,Q=(e,t,n)=>({kind:Gt.POINT,p:e,d:[0,0,0],cone:0,range:t,color:n,shadow:!1}),Qt=(e,t,n,r,i,a=!1)=>({...Q(e,r,i),kind:Gt.SPOT,d:t,cone:n,shadow:a}),$t=(e,...t)=>e.map((e,n)=>e+t.reduce((e,[t,r])=>e+t[n]*r,0)),en=(e,t)=>e.map(e=>e*t),tn=({eye:e,yaw:t,pitch:r,dead:i,others:a,fx:o,bullets:s,lvl:c,t:l})=>{let[u,d,f]=W(t,r),p=[];i||(p.push(Qt($t(e,[u,.2],[d,-.2]),f,Jt,25,Kt,!0)),o.flash>0&&p.push(Qt($t(e,[u,.26],[d,-.24],[f,.6+je*.8]),f,Yt,8,qt,!0)));let m=t=>Math.hypot(t[0]-e[0],t[1]-e[1],t[2]-e[2]),h=[];a.map(e=>({p:e,e:[e.x,e.y+n,e.z]})).sort((e,t)=>m(e.e)-m(t.e)).forEach(({p:e,e:t},n)=>{let[r,i,a]=W(e.yaw,e.pitch);h.push(Qt($t(t,[a,.35]),a,Jt,25,Kt,n<Xt)),o.flashes.has(e.id)&&h.push(Q($t([e.x,e.y+1.25,e.z],[r,.36],[i,-.12],[a,.8]),6,qt))});for(let e of o.blasts){let t=st(e);t>0&&h.push(Q(e.p,6,en(qt,t*6)))}o.hurt>0&&h.push(Q(e,4,en([2,.15,.1],Math.min(1,o.hurt*10)))),s.map(e=>Q([e.x,e.y,e.z],3,[1.2,.4,.15])).sort((e,t)=>m(e.p)-m(t.p)).slice(0,Zt).forEach(e=>h.push(e));let{exit:g,goal:_}=c.map;if(g!==void 0){let e=1+.3*Math.sin(l*4);if(c.barred.has(g)){if(_){let t=c.map.sectors[y(c,_[0],_[1])]?.floor??0;h.push(Q([_[0],t+1,_[1]],8,en([.2,1.2,1.5],e)))}}else{let{floor:t}=c.map.sectors[g];for(let{ax:n,az:r,bx:i,bz:a,front:o,back:s}of c.edges)if(o==g&&s>=0){let[o,s]=[i-n,a-r],c=.5/Math.hypot(o,s);h.push(Q([(n+i)/2-s*c,t+1.2,(r+a)/2+o*c],8,en([.2,1.5,.3],e)))}}}return p.concat(h.sort((e,t)=>m(e.p)-m(t.p)).slice(0,16-p.length))},nn=1.5,rn=e=>{let t=Math.floor(e*10/60);return`${Math.floor(t/600)}:${String(Math.floor(t/10)%60).padStart(2,`0`)}.${t%10}`},an=({spawns:e},t,n)=>e.reduce((e,r)=>Math.hypot(r[0]-t,r[1]-n)<Math.hypot(e[0]-t,e[1]-n)?r:e)[2],on=({lvl:e,you:t,predictor:n,rd:r,delays:i,fx:a,hud:o,audio:s})=>{let c=-1,l=-1,u=/* @__PURE__ */ new Map,d={lvl:e,items:[],dead:!1,returning:!1,alive:e=>u.get(e)!==0,snapshot(e){let f=t(),p=e.level*2+ +e.hard;if(p!=c){let t=O[e.level];if(!t)return;c=p,d.lvl=g(t),d.items=[],u=/* @__PURE__ */ new Map,l=-1,n.level(d.lvl),r?.level(d.lvl),a.reset(d.lvl),i.forEach(e=>e.clear()),o.say(St.TITLE,`Level ${e.level+1}${e.hard?`
|
|
2
|
-
Hard mode`:``}`)}let
|
|
1
|
+
var e=.4,t=1.8,n=1.6,r=1.55,i=.5,a=.02,o=1.8,s=.45,c=.9,l=.15,u={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,FIRE:32},d={WALKER:0,FLYER:1},f={DIE:0,HURT:1,BOOM:2,SWING:3},p={HEALTH:0,KEY_RED:1,KEY_BLUE:2,KEY_YELLOW:3},m={HUNT:0,RETURN:1},h={BRICK:0,TILE:1,LAVA:2,STONE:3},g=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r)));let r={map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}})),barred:/* @__PURE__ */ new Set};return _(r,0,m.HUNT),r},_=({map:e,barred:t},n,r)=>{t.clear(),e.gates?.forEach(e=>n&1<<e.key||t.add(e.sector)),e.exit!==void 0&&r===m.HUNT&&t.add(e.exit)},v=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),y=({map:e},t,n)=>e.sectors.findIndex(e=>v(e,t,n)),b=({map:e,edges:t},[n,r,i],[a,o,s])=>{let[c,l]=[a-n,s-i];return t.some(t=>{let[a,s]=[t.bx-t.ax,t.bz-t.az],u=c*s-l*a;if(!u)return!1;let d=((t.ax-n)*s-(t.az-i)*a)/u,f=((t.ax-n)*l-(t.az-i)*c)/u;if(d<=0||d>=1||f<0||f>1)return!1;if(t.back<0)return!0;let[p,m]=[e.sectors[t.front],e.sectors[t.back]],h=r+d*(o-r);return h<Math.max(p.floor,m.floor)||h>Math.min(p.ceil,m.ceil)})},x=(e,[t,n,r,i],a,o,s,c,l,u)=>Array.from({length:s},(d,f)=>{let[p,m]=e?[n,i]:[t,r],[h,g,_]=[p+f*(m-p)/s,p+(f+1)*(m-p)/s,+(a+f*o).toFixed(1)];return e?[t,h,r,g,_,c,l,u]:[h,n,g,i,_,c,l,u]}),[S,C,w,T]=[p.HEALTH,p.KEY_RED,p.KEY_BLUE,p.KEY_YELLOW],E=Math.PI/4,D=(e,t,[n,r,i],a,o,s,c)=>{let l=t.map(([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r]]),u=[...new Map(l.flat().map(e=>[`${e}`,e])).values()];return{name:e,sectors:t.map(([,,,,e,t,n=`103`,r],i)=>({pts:l[i].flatMap((e,t,n)=>{let r=n[(t+1)%4],i=t=>(t[0]-e[0])*(r[0]-e[0])+(t[1]-e[1])*(r[1]-e[1]);return[e,...u.filter(t=>(r[0]-e[0])*(t[1]-e[1])===(r[1]-e[1])*(t[0]-e[0])&&i(t)>0&&i(t)<(r[0]-e[0])**2+(r[1]-e[1])**2).sort((e,t)=>i(e)-i(t))]}),floor:e,ceil:t,ft:+n[0],wt:+n[1],ct:+n[2],light:r})),spawns:Array.from({length:16},(e,t)=>[n+t%4*2,r+(t>>2)*2,i*E]),monsters:[...a.map(([e,t,n])=>[e,t,n*E,d.WALKER]),...o.map(([e,t,n])=>[e,t,n*E,d.FLYER])],items:s,gates:t.flatMap(([,,,,,,,,e],t)=>e?[{sector:t,key:e}]:[]),goal:c,exit:0}},O=[D(`Warm-up`,[[0,0,10,10,0,4,`103`],[10,4,22,6,0,2.8,`333`,.6],[22,0,38,14,0,6,`303`],...x(0,[38,4,42,10],.4,.4,4,6,`333`),[42,2,52,12,2,6,`103`,.9],...x(1,[46,12,48,22],1.6,-.4,4,4.8,`000`,.7),[38,22,56,36,0,6,`113`]],[2,2,6],[[28,4,3],[34,10,4],[48,6,4],[44,30,0]],[[30,8,0],[52,28,2]],[[26,12,S],[50,10,S],[40,34,S]],[54,34]),D(`Foundry`,[[0,14,10,26,0,4,`103`],[10,22,20,24,0,2.8,`333`,.6],[24,8,28,16,0,9,`303`],[20,16,28,30,0,9,`303`],...x(1,[20,8,24,16],2,-.4,5,9,`333`),[28,8,42,18,-1.6,9,`203`,.9],...x(1,[28,18,42,21],-1.2,.4,3,9,`333`),[28,21,50,30,0,9,`303`],[42,8,50,21,0,9,`303`],[20,0,50,8,2.4,9,`103`,.8],[50,14,51,17,0,3.5,`000`,1,C],[51,8,59,26,0,7,`113`,.6],[59,8,67,26,.4,7,`013`,.8],[57,26,59,36,0,4.8,`000`,.7],[50,36,68,50,0,7,`013`]],[2,16,6],[[46,14,2],[36,26,0],[38,4,2],[56,12,4],[62,20,2],[60,44,0]],[[35,13,0],[60,14,4],[58,42,6]],[[24,26,S],[24,4,S],[64,10,S],[52,46,S],[46,4,C]],[66,48]),D(`Cistern`,[[0,20,10,32,0,4,`103`],[10,26,20,28,0,2.8,`333`,.6],[20,14,56,26,0,11,`133`,.9],[20,26,34,32,0,11,`133`,.9],[34,26,42,32,-.4,11,`233`],[42,26,56,32,0,11,`133`,.9],[20,32,56,44,0,11,`133`,.9],[36,44,38,54,0,1.9,`333`,.45],[30,54,46,68,0,5,`000`,.7],[56,28,57,31,0,4,`000`,1,C],...x(0,[57,26,65,32],.4,.4,8,10,`333`,.8),[65,22,81,36,3.6,11,`103`],[71,36,74,37,3.6,7,`000`,1,w],[71,37,74,48,3.6,6.4,`333`,.6],[62,48,82,64,3.6,10,`213`]],[2,22,6],[[30,18,4],[50,20,4],[30,40,0],[50,40,0],[36,60,2],[42,64,0],[76,28,2],[70,58,0]],[[26,24,0],[48,22,0],[36,40,2],[72,56,4]],[[24,40,S],[52,42,S],[44,57,S],[68,34,S],[64,62,S],[38,66,C],[79,24,w]],[80,62]),D(`Loop`,[[0,44,10,56,0,4,`103`],[10,49,20,51,0,2.8,`333`,.6],[20,30,52,40,0,9,`303`],[20,48,52,58,0,9,`303`,.9],[20,40,32,48,0,9,`303`],[40,40,52,48,0,9,`303`],[20,22,49,30,3.2,9,`113`,.8],[34,58,36,66,0,2.8,`333`,.5],[26,66,46,84,0,5,`000`,.5],[52,42,53,45,0,4,`000`,1,C],[53,36,64,54,0,6,`133`,.8],[64,36,70,54,.4,6,`233`,.8],[60,35,63,36,0,4,`000`,1,w],[57,12,77,35,0,8,`013`,.9],[56,24,57,27,0,4,`000`,1,T],...x(0,[49,22,56,30],2.8,-.4,7,9,`333`,.8),[12,24,20,28,3.2,6,`333`,.6],[0,10,12,34,3.2,9,`113`]],[2,46,6],[[30,36,4],[44,36,2],[40,52,0],[40,26,4],[30,74,6],[42,78,2],[56,40,6],[64,50,2],[62,18,4],[72,28,2],[6,22,0]],[[28,48,0],[46,44,4],[36,72,0],[60,45,6],[68,22,4]],[[24,54,S],[24,26,S],[44,80,S],[68,38,S],[74,14,S],[36,82,C],[68,52,w],[74,32,T]],[6,13]),D(`Citadel`,[[0,60,10,72,0,4,`103`],[10,65,24,67,0,2.8,`333`,.6],[24,48,56,84,0,12,`313`],[27,40,31,48,0,3.4,`000`,.5],[24,16,34,40,0,12,`303`,.9],...x(0,[34,16,40,26],-.4,-.4,3,12,`233`),[34,26,40,30,0,12,`333`],...x(0,[34,30,40,40],-.4,-.4,3,12,`233`),[40,16,60,40,0,12,`303`,.9],[60,27,61,30,0,4,`000`,1,T],[61,10,101,16,0,14,`103`],[61,40,101,46,0,14,`103`],[61,16,69,40,0,14,`103`],[93,16,101,40,0,14,`103`],[69,16,93,20,.4,14,`233`,.9],[69,36,93,40,.4,14,`233`,.9],[69,20,73,36,.4,14,`233`,.9],[89,20,93,36,.4,14,`233`,.9],[73,20,89,36,.8,14,`333`],[101,26,111,28,0,3.2,`333`,.6],[111,16,131,40,0,8,`113`],[56,66,57,69,0,4,`000`,1,C],[57,56,75,80,0,12,`000`,.7],...x(0,[75,60,85,72],.4,.4,5,12,`333`,.8),[85,52,101,80,2.4,12,`013`],[38,84,42,85,0,4,`000`,1,w],[38,85,42,95,0,1.9,`000`,.4],[28,95,56,115,0,6,`030`,.6]],[2,62,6],[[34,56,4],[50,56,2],[36,76,0],[46,20,4],[54,34,2],[66,60,2],[66,76,0],[92,60,2],[34,100,4],[50,108,2],[70,13,4],[92,13,2],[70,43,0],[92,43,6]],[[30,70,0],[46,68,0],[50,28,0],[76,26,0],[86,30,0],[81,22,0]],[[30,80,S],[56,36,S],[60,78,S],[50,112,S],[64,13,S],[98,43,S],[114,38,S],[52,22,C],[95,66,w],[42,110,T]],[127,36])],k=65536/(2*Math.PI),A=e=>Math.round(e*k)&65535,j=e=>Math.max(-32768,Math.min(32767,Math.round(e))),M=e=>j(e*1e4),N=e=>e/1e4,P=e=>e/k,F=(e=0)=>Math.round(e*256)&16777215,I=e=>({...e,yaw:P(A(e.yaw)),pitch:N(M(e.pitch)),...e.view!==void 0&&{view:F(e.view)/256}}),ee=e=>{let t=/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(11));t.setUint8(0,1),t.setUint16(1,e.seq&65535),t.setUint8(3,e.keys&255),t.setUint16(4,A(e.yaw)),t.setInt16(6,M(e.pitch));let n=F(e.view);return t.setUint16(8,n>>8),t.setUint8(10,n&255),t.buffer},te=e=>{if(e.byteLength<7)return null;let t=new DataView(e),n=t.getUint8(3);if(t.getUint8(0)!==2)return null;let r=7+25*n,[i,a,o,s,c]=[14,16,13,14,14].map(n=>{if(e.byteLength<=r)return null;let i=t.getUint8(r),a=r+1;return r=a+n*i,[a,i]});if(!i||!a||!o||!s||!c||e.byteLength!==r)return null;let l=([e,t],n,r)=>Array.from({length:t},(t,i)=>r(e+i*n)),u=[];for(let e=0;e<n;e++){let n=7+e*25;u.push({id:t.getUint8(n),x:t.getFloat32(n+1),y:t.getFloat32(n+5),z:t.getFloat32(n+9),vy:t.getFloat32(n+13),yaw:P(t.getUint16(n+17)),pitch:N(t.getInt16(n+19)),ack:t.getUint16(n+21),cool:t.getUint8(n+23)>>1,ground:(t.getUint8(n+23)&1)==1,hp:t.getUint8(n+24)})}return{tick:t.getUint16(1),players:u,shots:l(i,14,e=>({id:t.getUint8(e),x:t.getFloat32(e+1),y:t.getFloat32(e+5),z:t.getFloat32(e+9),hit:t.getUint8(e+13)===255?-1:t.getUint8(e+13)})),monsters:l(a,16,e=>({id:t.getUint8(e),kind:t.getUint8(e+1)&1,chase:!!(t.getUint8(e+1)&2),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10),yaw:P(t.getUint16(e+14))})),bullets:l(o,13,e=>({id:t.getUint8(e),x:t.getFloat32(e+1),y:t.getFloat32(e+5),z:t.getFloat32(e+9)})),events:l(s,14,e=>({type:t.getUint8(e),id:t.getUint8(e+1),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10)})),level:t.getUint8(4),hard:(t.getUint8(5)&1)==1,phase:t.getUint8(5)>>1&1,keys:t.getUint8(6),items:l(c,14,e=>({id:t.getUint8(e),kind:t.getUint8(e+1),x:t.getFloat32(e+2),y:t.getFloat32(e+6),z:t.getFloat32(e+10)}))}},L=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},R=44100,z={SHOT:0,BOOM:1,HIT:2,COLLECT:3,CLOCK:4,BURST:5,HEART:6},B=([e,t,n,r,i,a,o,s,c,l,u],d)=>{let f=new Float32Array(Math.ceil((r+i+a)*R)),p=0,m=0,h=0,g=()=>{d=d+1831565813|0;let e=Math.imul(d^d>>>15,1|d);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/2**31-1};for(let d=0;d<f.length;d++){let _=d/R;p+=t*2**(n*_)*(_>c?l:1)*(1+o*Math.sin(_*44))/R,p>=1&&(p%=1,h=g());let v=e==3?h:e==2?Math.sin(p*2*Math.PI):e?1-2*p:p<.5?1:-1;m+=(v-m)*s;let y=_<r?_/r:_<r+i?1:((r+i+a-_)/a)**2;f[d]=m*y*u}return f},ne=[[[3,7e3,-.5,.002,0,.06,0,.6,0,1,.8],[0,220,-5,.002,0,.075,0,.3,0,1,.5]],[[3,500,-1.5,.004,.05,.8,0,.1,0,1,2.2],[2,110,-1.5,.004,.05,.6,0,1,0,1,.8]],[[1,160,-1.5,.003,.04,.22,.2,.5,0,1,.6],[0,83,-1,.003,.04,.22,0,.3,0,1,.4],[3,3e3,0,.002,0,.12,0,.4,0,1,.5]],[[2,880,.3,.005,.06,.4,0,1,.09,1.5,.8],[2,1760,.3,.005,.06,.35,0,1,.09,1.5,.3]],[[3,4e3,0,.001,0,.025,0,.5,0,1,.7],[2,1300,-1,.001,0,.04,0,1,0,1,.5]],[[3,1200,-1,.002,0,.14,0,.45,0,1,.7],[0,3200,-1,.002,0,.05,0,1,.025,.7,.2]],[[2,55,-1,.01,.01,.12,0,1,0,1,.9],[2,110,-1,.01,0,.08,0,1,0,1,.3],[2,48,-1,.01,.01,.14,0,1,0,1,.6,.22],[2,96,-1,.01,0,.09,0,1,0,1,.2,.22]]],re=e=>{let t=ne[e].map((t,n)=>[B(t,e*9+n),Math.round((t[11]??0)*R)]);return Float32Array.from({length:Math.max(...t.map(([e,t])=>t+e.length))},(e,n)=>Math.tanh(t.reduce((e,[t,r])=>e+(t[n-r]??0),0)))},V=R*60/108,ie=V/4,ae=4,oe=[2,150,-6,.002,0,.25,0,1,0,1,1],se=[3,9e3,0,.002,0,.15,0,.5,0,1,.5],ce=[3,3e4,0,.001,0,.04,0,.7,0,1,.15],le=()=>{let e=new Float32Array(V*4*ae),t={},n=(n,r)=>(t[String(r)]??=B(r,1)).forEach((t,r)=>e[(n*ie+r)%e.length]+=t),r=e=>55*2**(e/12),i=[0,0,-4,-5],a=[0,0,12,0,0,7,12,7];for(let e=0;e<64;e++){let t=e%16;if(`x.......x.x.....`[t]==`x`&&n(e,oe),`....x.......x...`[t]==`x`&&n(e,se),t%2==0){n(e,ce);let o=i[e>>4]+a[t>>1];n(e,[1,r(o),0,.005,.08,.18,0,.15,0,1,.6])}}[15,12,10,19,17,15].forEach((e,t)=>n([18,24,28,50,54,60][t],[2,r(e+24),0,.02,.1,.6,.01,1,0,1,.5]));let o=e.reduce((e,t)=>Math.max(e,Math.abs(t)),0);return e.map(e=>e/o*.35)},ue=40,de=24,fe=.5,pe=`tiny-fps:muted`,me=()=>{let e=!1;return{unlock:()=>{},listen:()=>{},play:()=>{},mute:t=>{e=t},get muted(){return e},destroy:()=>{}}},he=()=>{let e;try{e=new AudioContext}catch{return me()}let t=(t,n=1)=>{let r=e.createGain();return r.gain.value=n,r.connect(t),r},n=t(e.destination),r=t(n,fe),i=[],a=/* @__PURE__ */ new Set,o=[0,0,0],s=0,c=!1,l=t=>{let n=e.createBuffer(1,t.length,R);return n.getChannelData(0).set(t),n},u=t=>{let n=e.createBufferSource();return n.buffer=t,n};return{unlock(){if(e.resume().catch(()=>{}),!i.length){for(let e of Object.values(z))i[e]=l(re(e));let e=u(l(le()));e.loop=!0,e.connect(r),e.start()}},listen(e,t){[o,s]=[e,t]},play(r,c,l=1){let d=0,f=l;if(c){let[e,t,n]=c.map((e,t)=>e-o[t]),r=Math.hypot(e,t,n);f=Math.max(0,1-r/ue)**2*l,d=(e*Math.cos(s)-n*Math.sin(s))/Math.max(r,1)}let p=i[r];if(!p||!f)return;if(a.size>=de){let e=[...a].reduce((e,t)=>t.vol<e.vol?t:e);if(e.vol>=f)return;e.src.stop(),a.delete(e)}let m=u(p),h=e.createStereoPanner();h.pan.value=d,m.connect(h).connect(t(n,f));let g={vol:f,src:m};a.add(g),m.onended=()=>a.delete(g),m.start()},mute(t){c=t,n.gain.setTargetAtTime(+!t,e.currentTime,.05)},get muted(){return c},destroy:()=>void e.close().catch(()=>{})}},ge=(e,{type:t,id:n,x:r,y:i,z:a},o)=>{let s=[r,i,a];t==f.DIE?e.play(z.BOOM,s):t==f.BOOM?e.play(z.BURST,s):t==f.HURT&&e.play(z.HIT,n==o?void 0:s)},_e=e=>{let t=0;return(n,r)=>{n&&r>=t&&(t=r+1e3,e.play(z.CLOCK))}},ve=e=>{let t=-1/0;return(n,r)=>{if(n<1||n>3)return t=-1/0,0;let i=n>1?800:500;return r-t>=i&&(t=r,e.play(z.HEART,void 0,n>1?.6:1)),1-(r-t)/i}},ye=()=>{try{return localStorage.getItem(pe)==`1`}catch{return!1}},be=e=>{e.mute(!e.muted);try{localStorage.setItem(pe,e.muted?`1`:`0`)}catch{}return e.muted},xe=1/60,H=Math.PI*2,Se=1e-6,Ce=.01,we=e=>(e%H+H)%H,Te=e=>[-Math.sin(e),-Math.cos(e)],Ee=Math.fround,De=(e,t,n)=>Math.min(Math.max(e,t),n),Oe=({map:e,barred:t},n,r,i,a)=>{if(n.back<0||t.has(n.back))return!0;let o=e.sectors[n.front],s=e.sectors[n.back],c=Math.min(o.ceil,s.ceil);return s.floor>r+a+Ce||c-Math.max(o.floor,s.floor)<i-Ce||c<r+i-Ce},ke=(e,t,n,r,i)=>{let a=(n-Se)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=De((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!Oe(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},Ae=(e,t,n,r,i,a,o)=>{let{map:s,edges:c}=e,l=Math.max(y(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-Se)**2;for(let i of c){if(i.front!==l||i.back<0)continue;let c=i.bx-i.ax,p=i.bz-i.az,m=t-i.ax,h=n-i.az,g=De((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!Oe(e,i,r,a,o)){let e=s.sectors[i.back];u=Math.max(u,e.floor),d=Math.min(d,e.ceil)}}return[u,d]},je=(n,r,a,o,s)=>{n.x+=r,n.z+=a,ke(n,s,e,t,i);let[c,l]=Ae(s,n.x,n.z,n.y,e,t,i);n.ground&&o&&(n.vy=7);let u=n.vy-20*xe;n.y+=(n.vy+u)/2*xe,n.vy=u,n.ground=!1,n.y+1.8>l&&(n.y=l-t,n.vy=Math.min(n.vy,0)),(n.vy<=0?n.y<=c+Ce:n.y<c)&&(n.y=c,n.vy<=0&&(n.vy=0,n.ground=!0)),n.x=Ee(n.x),n.y=Ee(n.y),n.z=Ee(n.z),n.vy=Ee(n.vy)},Me=(e,t,n)=>{let i=(t.keys&u.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=we(t.yaw),e.pitch=Math.max(-1.55,Math.min(r,t.pitch));let a=(t.keys&u.FORWARD?1:0)-(t.keys&u.BACK?1:0),o=(t.keys&u.RIGHT?1:0)-(t.keys&u.LEFT?1:0),s=6*xe*(i?.5:1)/(Math.hypot(a,o)||1),[c,l]=Te(e.yaw);return je(e,(c*a-l*o)*s,(l*a+c*o)*s,(t.keys&u.JUMP)!==0,n),i&&!e.cool?(e.cool=5,!0):!1},Ne=.55,Pe=6,Fe=(e,t,n=[0,0,0])=>{let r=[];for(let i=1;i<e.length;i++){let[[a,o],[s,c]]=[e[i-1],e[i]],l=Math.hypot(s-a,c-o);if(!l)continue;let[u,d]=[(c-o)/l,-(s-a)/l],f=(e,i,a)=>{let[o,s]=[Math.cos(e*H/t),Math.sin(e*H/t)];r.push(n[0]+i*o,n[1]+i*s,n[2]-a,u*o,u*s,-d)};for(let e=0;e<t;e++)for(let[t,n,r]of[[e,a,o],[e+1,a,o],[e+1,s,c],[e,a,o],[e+1,s,c],[e,s,c]])f(t,n,r)}return r},Ie=e=>{let t=[];for(let n=0;n<Pe;n++){let r=n*H/Pe;t.push(...Fe([[0,0],[.02,0],[.02,.45],[.014,.45],[.014,.55],[0,.55]],e,[Math.cos(r)*.05,Math.sin(r)*.05,0]))}return{barrels:t,body:Fe([[0,-.3],[.08,-.3],[.09,-.26],[.09,0],[.075,0],[.075,.1],[.03,.1],[.03,.4],[0,.4]],e)}},U=(e,t,n=0)=>{let[r,i,a,o,s,c]=[e,t,n].flatMap(e=>[Math.sin(e),Math.cos(e)]),l=[i,0,-r],u=[r*a,o,i*a];return[l.map((e,t)=>e*c-u[t]*s),u.map((e,t)=>e*c+l[t]*s),[-r*o,a,-i*o]]},W=(e,[t,n,r],[i,a,o],s,c,l=-1)=>{let[u,d]=[Math.sin(s),Math.cos(s)],f=(e,t)=>[e*d+t*u,-e*u+t*d];for(let s=0;s<3;s++)for(let u of[-1,1]){let[d,p]=[(s+1)%3,(s+2)%3],m=[0,0,0];m[s]=u;let[h,g]=f(m[0],m[2]);for(let[_,v]of[[-1,-1],[1,-1],[1,1],[-1,-1],[1,1],[-1,1]]){let y=[0,0,0];[y[s],y[d],y[p]]=[u,_,v];let[b,x]=f(y[0]*i,y[2]*o);e.push(t+b,n+y[1]*a,r+x,h,m[1],g,c[0],c[1],l,c[2])}}},Le=(e,[t,n,r])=>Array.from({length:e.length*(10/6)},(i,a)=>{let[o,s]=[Math.floor(a/10),a%10];return s<6?e[o*6+s]:[t,n,-1,r][s-6]}),G=(e,t,n,[r,i,a],o,s,c=0)=>{let[l,u]=[Math.sin(c),Math.cos(c)],d=(e,t,n)=>[0,1,2].map(o=>r[o]*(e*u-t*l)+i[o]*(e*l+t*u)-a[o]*n),f=[0,1,2].map(e=>n[e]+r[e]*o[0]+i[e]*o[1]+a[e]*o[2]);for(let n=0;n<t.length;n+=10){let r=d(t[n]*s,t[n+1]*s,t[n+2]*s);e.push(f[0]+r[0],f[1]+r[1],f[2]+r[2],...d(t[n+3],t[n+4],t[n+5])),e.push(...t.slice(n+6,n+10))}},Re=.3,ze=3.6,K={body:[.27,.22,.25],arm:[.4,.26,.22],leg:[.18,.17,.22],head:[.45,.33,.3],shell:[.36,.2,.32],fin:[.5,.25,.25],gore:[.6,.08,.07],calm:[.6,.05,.04],chase:[1,.3,.15],blob:[1,.3,.05],core:[1,.8,.4]},Be=[[K.body,K.arm,K.head,K.gore,K.gore,K.chase],[K.shell,K.fin,K.shell,K.gore,K.chase]],Ve=e=>e?K.chase:K.calm,q=({x:e,y:t,z:n,yaw:r},i,a,o)=>{let[s,c]=[Math.sin(r),Math.cos(r)];return[e+i*c-o*s,t+a,n-i*s-o*c]},He=(e,t,n,r,i,a)=>{let o=[];W(o,[0,-i[1],0],i,0,a),G(e,o,t,U(n,r),[0,0,0],1)},Ue=e=>e<.25?-.8*Math.sin(e*4*Math.PI):2*Math.sin((e-.25)*Math.PI/.75),We=(e,t,n,r)=>{let i=Math.sin(n*ze)*.6,a=o*.44,s=o*.8,[c,l]=[-1,1].map(e=>q(t,e*.16,a,0));He(e,c,t.yaw,i,[.09,a/2,.09],K.leg),He(e,l,t.yaw,-i,[.09,a/2,.09],K.leg),He(e,q(t,-.35,s,0),t.yaw,-i*.8,[.07,.34,.07],K.arm),He(e,q(t,.35,s,0),t.yaw,i*.8+(r>0?Ue(r):0),[.07,.34,.07],K.arm),W(e,q(t,0,1.142,0),[.26,.35,.16],t.yaw,K.body),W(e,q(t,0,1.6500000000000001,0),[.15,.15,.15],t.yaw,K.head);let u=t.chase?.06:.045;for(let n of[-1,1])W(e,q(t,n*.075,1.69,.15),[u,u*.7,.02],t.yaw,Ve(t.chase),-2)},Ge=Le(Fe([[0,0],[.18,.06],[s,.32],[s*.93,.5],[.22,.78],[0,c]],8),K.shell),Ke=(e,t,n)=>{let r=Math.sin(n*2+t.id)*.06,i=[t.x,t.y+r,t.z];G(e,Ge,i,U(0,Math.PI/2),[0,0,0],1);for(let r=0;r<4;r++){let a=n*1.5+r*H/4;W(e,[t.x+Math.cos(a)*.4,i[1]+.35,t.z+Math.sin(a)*.4],[.16,.03,.04],-a,K.fin)}let a=q({...t,y:i[1]},0,c*.45,s*.9),o=t.chase?1.3:1;W(e,a,[.1*o,.07*o,.05],t.yaw,Ve(t.chase),-2)},qe=(e,t,n)=>{let r=[t.x,t.y,t.z];if(W(e,r,[l*.8,l*.8,l*.8],0,K.blob,-2),W(e,r,[l*.5,l*.5,l*.5],Math.PI/4,K.core,-2),n)for(let t of[1,2]){let i=l*(1-t*.3);W(e,r.map((e,r)=>e-n[r]*t*.2),[i,i,i],0,K.blob,-2)}},Je=.05,Ye=.3,Xe=96,Ze=64,Qe=12,$e=.3,et=.45,tt=.4,nt=.5,rt=.9,it=.3,at=14,ot=4.4,st=.035,ct=.03,lt=30,ut=({r:e,t})=>{let n=t/$e;return n<1?e*Math.sqrt(n)*(1-n*n*n):0},dt=(e=64)=>{let t=[];return{clear(){t=[]},push(n,r){t.push(...n.map(e=>({t:r,v:e}))),t.splice(0,t.length-e)},due(e){let n=t.findIndex(({t})=>t+100>e);return t.splice(0,n<0?t.length:n).map(({v:e})=>e)}}},ft=(e=Math.random,t)=>{let r=t,i=0,a=0,o=0,s=0,c=0,l,d=()=>e()*2-1,p=/* @__PURE__ */ new Map,m=(e,t,n,r)=>{_.sparks.length<Xe&&_.sparks.push({p:e,v:t,life:n,c:r})},h=(t,n,r,i)=>{for(let a=0;a<n;a++){let[n,a]=[e()*H,d()],o=Math.sqrt(1-a*a)*r*(.5+e()*.5);m(t,[Math.cos(n)*o,a*r,Math.sin(n)*o],Ye*(.6+e()*.4),i)}},g=(e,t)=>{_.blasts.push({p:e,r:t,t:0}),_.blasts.splice(0,_.blasts.length-Qe)},_={bob:0,roll:0,shakeYaw:0,shakePitch:0,kick:0,spin:0,flash:0,flashes:/* @__PURE__ */ new Map,sparks:[],gibs:[],blasts:[],hurt:0,gain:0,gainC:[1,1,1],dead:0,swings:/* @__PURE__ */ new Map,herd:/* @__PURE__ */ new Map,aim:/* @__PURE__ */ new Map,update(e,t,r,f=!1){let p=Math.min(1,r*10),m=e&&l?.ground&&e.ground?Math.hypot(e.x-l.x,e.z-l.z):0;m<1&&(i+=m*ot),a+=(+(m>.5*r&&m<1)-a)*p,l=e,_.dead=Math.max(0,Math.min(1,_.dead+(f?r:-r)/nt));let h=_.dead*_.dead*(3-2*_.dead);_.bob=Math.sin(i)*st*a-h*(n-it);let g=+!!(t&u.RIGHT)-!!(t&u.LEFT);s+=(g*ct-s)*Math.min(1,r*8),_.roll=s+h*rt,o*=Math.exp(-r*12),_.shakeYaw=d()*o,_.shakePitch=d()*o,_.kick*=Math.exp(-r*18),_.flash=Math.max(0,_.flash-r);for(let[e,t]of _.flashes)t>r?_.flashes.set(e,t-r):_.flashes.delete(e);c=Math.max(0,Math.min(lt,c+(t&u.FIRE?60:-25)*r)),_.spin=(_.spin+c*r)%H;for(let e of _.sparks)e.v[1]-=9.8*r,e.p=e.p.map((t,n)=>t+e.v[n]*r),e.life-=r;_.sparks=_.sparks.filter(e=>e.life>0),_.hurt=Math.max(0,_.hurt-r),_.gain=Math.max(0,_.gain-r);for(let[e,t]of _.swings)t>r?_.swings.set(e,t-r):_.swings.delete(e);for(let e of _.blasts)e.t+=r;_.blasts=_.blasts.filter(e=>e.t<$e);for(let e of _.gibs)e.life-=r,e.rest||v(e,r);_.gibs=_.gibs.filter(e=>e.life>0)},hit(){_.hurt=et},pickup(e){[_.gain,_.gainC]=[tt,e]},reset(e){r=e,_.sparks=[],_.gibs=[],_.blasts=[],_.flashes.clear(),_.swings.clear(),_.herd.clear(),_.aim.clear(),p.clear(),_.hurt=_.gain=_.flash=0},shot(t,n,r,i=!0){r?(_.kick=1,_.flash=Je,o=.012):_.flashes.set(t.id,Je);let a=[t.x,t.y,t.z],s=n.map((e,t)=>e-a[t]),c=Math.hypot(...s);if(i&&c>0&&c<99.99)for(let t=0;t<4;t++){let t=s.map(t=>t/c*(2+e()*2)+d());t[1]+=1,m(a,t,Ye*(.6+e()*.4))}},track(e,t){for(let{id:t,kind:n,x:r,z:i}of e){let e=_.herd.get(t),a=e?Math.hypot(r-e.x,i-e.z):0;_.herd.set(t,{x:r,z:i,kind:n,walked:(e?.walked??0)+(a<1?a:0)})}let n=/* @__PURE__ */ new Map;for(let{id:e,x:r,y:i,z:a}of t){let[t,o]=[p.get(e),[r,i,a]],s=t?Math.hypot(o[0]-t[0],o[1]-t[1],o[2]-t[2]):0;t&&s>1e-4&&_.aim.set(e,o.map((e,n)=>(e-t[n])/s)),n.set(e,o)}p=n;for(let e of _.aim.keys())n.has(e)||_.aim.delete(e)},event({type:t,id:n,x:i,y:a,z:o},s){let c=[i,a,o];if(t==f.DIE){let t=Be[_.herd.get(n)?.kind??0]??Be[0],s=10+Math.floor(e()*7);for(let n=0;n<s;n++){let n=e()*H,s=1.5+e()*3.5;_.gibs.push({p:[i,a+d()*.3,o],v:[Math.cos(n)*s,2+e()*4,Math.sin(n)*s],yaw:e()*H,size:.05+e()*.08,c:t[Math.floor(e()*t.length)],life:2+e(),floor:r?.map.sectors[y(r,i,o)]?.floor??a,rest:!1})}_.gibs.splice(0,_.gibs.length-Ze),g(c,.6),h(c,14,5)}else t==f.BOOM?(g(c,.25),h(c,8,3)):t==f.HURT?n!=s&&h(c,8,3,[1,.12,.08]):t==f.SWING&&_.swings.set(n,Re)}},v=(e,t)=>{e.v[1]-=at*t;let n=e.p.map((n,r)=>n+e.v[r]*t);r&&b(r,e.p,n)&&(e.v[0]*=-.3,e.v[2]*=-.3,[n[0],n[2]]=[e.p[0],e.p[2]]);let i=r?.map.sectors[y(r,n[0],n[2])];e.floor=i?.floor??e.floor,i&&n[1]>i.ceil-e.size&&(n[1]=i.ceil-e.size,e.v[1]=Math.min(e.v[1],0)*.3),n[1]<=e.floor+e.size&&(n[1]=e.floor+e.size,e.v[1]<-3?e.v=[e.v[0]*.5,-e.v[1]*.3,e.v[2]*.5]:(e.v=[0,0,0],e.rest=!0)),e.p=n};return _},pt=[[1,1,1],[.95,.15,.1],[.2,.4,1],[1,.85,.15]],mt=(e,t=1)=>`rgba(${e.map(e=>Math.round(e*255))},${t})`,ht=.3,gt=[.25,1,.45],_t=[.85,.1,.1],vt=[.05,.05,.06],J=(e,[t,n,r],[i,a,o],s,c,l,u=-1)=>{let[d,f]=[Math.sin(c),Math.cos(c)];W(e,[t+i*f+o*d,n+a,r-i*d+o*f],s,c,l,u)},yt=(e,{id:t,kind:n,x:r,y:i,z:a},o)=>{let s=o*2+t,c=[r,i+(n?.55:.4)+Math.sin(o*2.5+t)*.07,a],l=pt[n];if(n==p.HEALTH){W(e,c,[.2,.2,.2],s,l);for(let t of[[.21,.06,.21],[.06,.21,.21],[.21,.21,.06]])W(e,c,t,s,_t)}else J(e,c,[0,.17,0],[.1,.1,.025],s,l,-2),J(e,c,[0,.17,0],[.04,.04,.035],s,vt),J(e,c,[0,-.1,0],[.025,.17,.025],s,l),J(e,c,[.06,-.24,0],[.05,.03,.025],s,l),J(e,c,[.045,-.15,0],[.035,.025,.025],s,l)},bt=({map:e},{front:t,back:n})=>{let[r,i]=[e.sectors[t],e.sectors[n]];return[Math.max(r.floor,i.floor),Math.min(r.ceil,i.ceil)]},xt=(e,t,n,r,i,a,o=-1)=>{let[s,c]=[t.bx-t.ax,t.bz-t.az];W(e,[(t.ax+t.bx)/2,n,(t.az+t.bz)/2],[Math.hypot(s,c)/2,r,i],Math.atan2(-c,s),a,o)},St=(e,t,n)=>{let{gates:r=[],exit:i}=t.map;for(let{sector:n,key:i}of r){if(!t.barred.has(n))continue;let r=pt[i];for(let i of t.edges.filter(e=>e.front==n&&e.back>=0)){let[n,a]=bt(t,i),o=Math.ceil(Math.hypot(i.bx-i.ax,i.bz-i.az)/ht);for(let t=0;t<o;t++){let s=(t+.5)/o;W(e,[i.ax+(i.bx-i.ax)*s,(n+a)/2,i.az+(i.bz-i.az)*s],[.03,(a-n)/2,.03],0,r)}xt(e,i,n+.1,.04,.04,r),xt(e,i,a-.1,.04,.04,r)}}if(i!==void 0&&!t.barred.has(i)){let r=gt.map(e=>e*(.75+.25*Math.sin(n*4)));for(let n of t.edges.filter(e=>e.front==i&&e.back>=0)){let[i,a]=bt(t,n);for(let t of[i+.04,a-.04])xt(e,n,t,.04,.04,r,-2);for(let[t,o]of[[n.ax,n.az],[n.bx,n.bz]])W(e,[t,(i+a)/2,o],[.05,(a-i)/2,.05],0,r,-2)}}},Ct=(e,t,n)=>{let r=t.map.goal,i=r&&t.map.sectors[y(t,r[0],r[1])]?.floor;if(!r||i===void 0)return;let a=Math.sin(n*4),[o,s]=[1*(.7+a*.07),[1,.85,.25].map(e=>e*(.75+a*.25))];for(let t of[0,1])W(e,[r[0],i+.03+t*.005,r[1]],[o,.03,o],n/2+t*Math.PI/4,s,-2);W(e,[r[0],i+.8+Math.sin(n*2)*.1,r[1]],[.15,.15,.15],n*2,[1,.95,.5],-2)},wt=(e,t,n,r)=>{for(let t of n)yt(e,t,r);St(e,t,r),Ct(e,t,r)},Tt={TITLE:0,NOTE:1},Et=[2,3,8],Dt=2,Y=.35,Ot=`h1,h2,h4,h5,ul,ol,aside,section,s{position:absolute;margin:0;padding:0;pointer-events:none;user-select:none;white-space:pre-line}h1,h2,h4{left:0;right:0;text-align:center}h1{top:14%;font-size:20px;line-height:1.4}h1::first-line{font-size:44px}h2{top:32%;font-size:22px}h5{top:8px;right:12px;font-size:12px}h4{top:28%;font-size:22px;line-height:1.5;color:#fcc;text-shadow:0 2px 8px #800}h4::first-line{font-size:52px;color:#f33}s{inset:0;opacity:0}s:first-of-type{background:radial-gradient(#d000 45%,#d00 115%)}ul{--f:0;--s:0;--d:0;left:12px;bottom:12px;width:min(40vw,140px);height:22px;border-radius:4px;overflow:hidden;background:#0009;box-shadow:0 0 0 1px #0008,0 0 0 calc(var(--d)*3px) #f22;transform:translateX(calc(var(--s)*1px));filter:brightness(calc(1 + var(--f)*2))}ul li{position:absolute;top:0;bottom:0;left:0;transition:width .15s}ul li+li{right:0;width:auto;text-align:center;line-height:22px;font-size:14px}ol{left:calc(22px + min(40vw,140px));bottom:12px;display:flex;gap:4px;list-style:none}ol li{width:16px;height:22px;border-radius:3px;box-shadow:0 0 0 1px #0008}aside,section{inset:0;z-index:1;display:flex;flex-direction:column;align-items:center;gap:14px;padding:0 12px;text-align:center;background:#000b}aside{justify-content:center}section{padding-top:10%;font-size:20px}:is(aside,section):not([hidden])~:is(h1,h2){visibility:hidden}h6{margin:0;font-size:inherit;text-shadow:none}aside h6{font:900 clamp(36px,13vw,84px)/1 system-ui,sans-serif;letter-spacing:.04em;transform:skewX(-8deg);background:linear-gradient(#fe6,#f92 45%,#d21);-webkit-background-clip:text;background-clip:text;color:transparent;filter:drop-shadow(0 3px 0 #500) drop-shadow(0 0 14px #f604)}section h6{font-size:20px;line-height:1.5}section h6::first-line{font-size:48px}strong{font-size:22px}small{font-size:16px;opacity:.8}table{border-collapse:collapse;font-size:16px}td,th{padding:2px 10px}th{opacity:.6}td+td,th+th{text-align:left}td+td+td,th+th+th{text-align:right}aside td:first-child{text-align:right;opacity:.7}`,kt=e=>{e.insertAdjacentHTML(`beforeend`,`<s></s><s></s><ul><li></li><li></li></ul><ol>${`<li hidden></li>`.repeat(3)}</ol><aside hidden><h6>TINY FPS</h6><span></span><table><tr><td>Mouse<td>look<tr><td>WASD / ZQSD<td>move<tr><td>Space<td>jump<tr><td>Left click<td>fire<tr><td>M<td>mute</table><strong></strong></aside><section hidden><h6></h6><table><thead><tr><th><th>Player<th>Kills<th>Deaths</thead><tbody></tbody></table><small></small></section><h1 hidden></h1><h2 hidden></h2><h4 hidden></h4><h5 hidden>Muted (M)</h5>`);let t=t=>e.querySelector(t),[n,r]=[...e.querySelectorAll(`s`)],[i,a,o]=[t(`ul`),t(`ul li`),t(`ul li+li`)],s=[...e.querySelectorAll(`ol li`)],[c,l,u,d]=[`h4`,`h5`,`section`,`aside`].map(e=>t(e)),[f,p,m]=[`section h6`,`section tbody`,`small`].map(e=>t(e)),[h,g]=[`aside span`,`strong`].map(e=>t(e)),_=[t(`h1`),t(`h2`),u];s.forEach((e,t)=>e.style.background=mt(pt[t+1]));let v=Et.map(()=>0),y=0,[b,x]=[0,0],S=(e,t)=>e.textContent!=t&&(e.textContent=t);return{hp(e){y&&(b=e>y?Y:b,x=e<y?Y:x),y=e,a.style.width=`${e/9*100}%`,a.style.background=`hsl(${(Math.max(e,1)-1)/8*110},75%,42%)`,S(o,String(e))},keys:e=>s.forEach((t,n)=>t.hidden=!(e>>n+1&1)),dead(e){c.hidden=!e,e&&S(c,`You died\nRespawn in ${e}`)},fade(e,t,i,a){n.style.opacity=String(Math.max(e*.9,t&&.2+t*.4)),r.style.opacity=String(i*.32),r.style.background=mt(a)},title(e,t){d.hidden=!e,S(h,t),S(g,e)},end(e,t,n){S(f,e),S(m,n),p.replaceChildren(...t.map(([e,t,n,r])=>{let i=document.createElement(`tr`);return[`●`,e,n,r].forEach((e,n)=>{let r=i.insertCell();r.textContent=String(e),r.style.color=n?``:t}),i})),_[Dt].hidden=!1,v[Dt]=Et[Dt]},mute:e=>l.hidden=!e,say(e,t){_[e].textContent=t,_[e].hidden=!1,v[e]=Et[e]},update(e){v.forEach((t,n)=>{t>0&&(v[n]=t-e)<=0&&(_[n].hidden=!0)}),b=Math.max(0,b-e),x=Math.max(0,x-e);for(let[e,t]of[[`--f`,b/Y],[`--d`,x/Y],[`--s`,Math.sin(x*90)*8*x/Y]])i.style.setProperty(e,String(t))}}},At=.0025,jt=Math.PI*2,Mt={KeyW:u.FORWARD,ArrowUp:u.FORWARD,KeyS:u.BACK,ArrowDown:u.BACK,KeyA:u.LEFT,ArrowLeft:u.LEFT,KeyD:u.RIGHT,ArrowRight:u.RIGHT,Space:u.JUMP},Nt=e=>Mt[e]??0,Pt=(e,t=()=>{})=>{let n=new AbortController,i=(e,t,r)=>e.addEventListener(t,r,{signal:n.signal}),a={yaw:0,pitch:0,keys:0,locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>n.abort()};i(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),i(document,`mousemove`,e=>{a.locked()&&(a.yaw=((a.yaw-e.movementX*At)%jt+jt)%jt,a.pitch=Math.max(-1.55,Math.min(r,a.pitch-e.movementY*At)))}),i(document,`keydown`,e=>{let n=Nt(e.code);e.code==`KeyM`&&!e.repeat&&a.locked()&&t(),n&&a.locked()&&(a.keys|=n,e.preventDefault())}),i(document,`keyup`,e=>{a.keys&=~Nt(e.code)}),i(document,`mousedown`,e=>{e.button==0&&a.locked()&&(a.keys|=u.FIRE)}),i(document,`mouseup`,e=>{e.button==0&&(a.keys&=~u.FIRE)});let o=()=>{a.keys=0};return i(window,`blur`,o),i(document,`pointerlockchange`,()=>a.locked()||o()),a},Ft=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},It=(e,t,n)=>{let[r,i,o,s]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],c=Ft(n+1),l=(c&65535)/65536*H,u=(c>>>16)/65535,[d,f]=[Math.cos(l)*u*a,Math.sin(l)*u*a],p=[-r*s+i*d+r*o*f,o+s*f,-i*s-r*d+i*o*f],m=Math.hypot(...p);return[p[0]/m,p[1]/m,p[2]/m]},Lt=(e,t,n,r)=>{let{map:i,edges:a}=e,o=Math.max(y(e,t[0],t[2]),0),s=0;for(let e=0;e<=i.sectors.length;e++){let{floor:e,ceil:c}=i.sectors[o],l=1/0,u;for(let e of a){if(e.front!==o)continue;let[r,i]=[e.bx-e.ax,e.bz-e.az],a=n[2]*r-n[0]*i;if(a>=0)continue;let c=Math.max(((t[2]-e.az)*r-(t[0]-e.ax)*i)/-a,s),d=((t[0]+c*n[0]-e.ax)*r+(t[2]+c*n[2]-e.az)*i)/(r*r+i*i);d>-1e-9&&d<1+1e-9&&(c<l-1e-9||c<l+1e-9&&e.back<0)&&([l,u]=[c,e])}let d=n[1]<0?(e-t[1])/n[1]:n[1]>0?(c-t[1])/n[1]:1/0;if(d<=l||!u)return Math.min(Math.max(d,s),r);if(l>=r)return r;let f=t[1]+l*n[1],p=u.back<0?void 0:i.sectors[u.back];if(!p||f<Math.max(e,p.floor)||f>Math.min(c,p.ceil))return l;[o,s]=[u.back,l]}return s},Rt=(e,t,n)=>{let[r,i]=[e[0]-n.x,e[2]-n.z],a=t[0]*t[0]+t[2]*t[2],o=r*t[0]+i*t[2],s=r*r+i*i-n.r*n.r,[c,l]=[0,1/0];if(a>1e-12){let e=o*o-a*s;if(e<0)return 1/0;[c,l]=[Math.max(0,(-o-Math.sqrt(e))/a),(-o+Math.sqrt(e))/a]}else if(s>0)return 1/0;let[u,d]=[n.y-e[1],n.y+n.h-e[1]];if(t[1]){let[e,n]=[u/t[1],d/t[1]];c=Math.max(c,Math.min(e,n)),l=Math.min(l,Math.max(e,n))}else if(u>0||d<0)return 1/0;return c<=l?c:1/0},zt=({id:n,x:r,y:i,z:a})=>({id:n,x:r,y:i,z:a,r:e,h:t}),Bt=({id:e,kind:t,x:n,y:r,z:i})=>{let a=t===d.WALKER;return{id:e,x:n,y:r,z:i,r:a?.4:s,h:a?o:c}},Vt=(e,t,r,i)=>{let a=[t.x,t.y+n,t.z],o=It(t.yaw,t.pitch,r),s=Lt(e,a,o,100),c=-1;for(let e of i){let n=e.id===t.id?1/0:Rt(a,o,e);n<s&&([s,c]=[n,e.id])}return{id:t.id,x:a[0]+o[0]*s,y:a[1]+o[1]*s,z:a[2]+o[2]*s,hit:c}},Ht=120,Ut=16,X=({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s,cool:c})=>({id:e,x:t,y:n,z:r,vy:i,yaw:a,pitch:o,ground:s,cool:c}),Wt=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,z:e.z+(t.z-e.z)*n}),Gt=(e,t,n)=>we(e+(((t-e+Math.PI)%H+H)%H-Math.PI)*n),Kt=(e,t)=>(t-e&65535)<32768,qt=(e,t,n)=>({...t,...Wt(e,t,n),yaw:Gt(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),Jt=e=>{let t=e,n,r=0,i=[],a,o,s,c=!0,l=/* @__PURE__ */ new Map,u=[],d=e=>{let t=e-100,n=0;for(;n+1<u.length&&u[n+1].t<=t;)n++;let r=u[n],i=u[n+1]??r;return{a:r,b:i,u:i.t>r.t?Math.max(0,Math.min(1,(t-r.t)/(i.t-r.t))):0}},f=e=>{if(!u.length)return;let{a:t,b:n,u:r}=d(e);return(t.s.tick+(n.s.tick-t.s.tick&65535)*r)%65536},p=e=>{let t=u.at(-1);if(!t)return[];let{a:r,b:i,u:a}=d(e);return t.s.players.filter(e=>e.id!==n).map(e=>{let t=r.s.players.find(t=>t.id===e.id),n=i.s.players.find(t=>t.id===e.id);return t&&n?qt(X(t),X(n),a):X(n??t??e)})},m=(e,t,n)=>{if(!u.length)return[];let{a:r,b:i,u:a}=d(e),o=t(r.s);return t(i.s).map(e=>{let t=o.find(t=>t.id===e.id);return t?n(t,e,a):e})},h=e=>m(e,e=>e.monsters,(e,t,n)=>({...t,...Wt(e,t,n),yaw:Gt(e.yaw,t.yaw,n)}));return{you:e=>{n=e},step:(e,n)=>{let d=I({...e,seq:r,view:n===void 0?void 0:f(n)});if(s=void 0,r=r+1&65535,i.push(d),i.length>Ht&&i.shift(),a&&(o=X(a),c&&Me(a,d,t))){let e=n??1/0,r=h(e).filter(e=>!l.has(e.id)),i=u.at(-1)?.s.players??[],o=p(e).filter(e=>i.find(t=>t.id===e.id)?.hp);s=Vt(t,a,d.seq,[...o.map(zt),...r.map(Bt)]),s.hit>=16&&l.set(s.hit,d.seq)}return d},snapshot:(e,r)=>{u.push({t:r,s:e}),u.length>Ut&&u.shift(),_(t,e.keys,e.phase);let s=e.players.find(e=>e.id===n);s&&(c=s.hp>0,i=i.filter(e=>!Kt(e.seq,s.ack)),l.forEach((t,n)=>{let r=e=>e.monsters.some(e=>e.id===n);Kt(t,s.ack)&&(r(e)||!u.some(e=>r(e.s)))&&l.delete(n)}),a=X(s),o=X(a),i.forEach((e,n)=>{n===i.length-1&&(o=X(a)),c&&Me(a,e,t)}))},monsters:h,bullets:e=>m(e,e=>e.bullets,(e,t,n)=>({...t,...Wt(e,t,n)})),level:e=>{t=e,u.length=0,l.clear(),a=o=s=void 0},shot:()=>s,me:e=>a&&o?qt(o,a,Math.max(0,Math.min(1,e))):void 0,others:p}},Yt={SPOT:0,POINT:1},Xt=[1.2,1.1,.9],Zt=[3,1.4,.4],Qt=Math.cos(.436),$t=.5,en=2,tn=4,Z=(e,t,n)=>({kind:Yt.POINT,p:e,d:[0,0,0],cone:0,range:t,color:n,shadow:!1}),nn=(e,t,n,r,i,a=!1)=>({...Z(e,r,i),kind:Yt.SPOT,d:t,cone:n,shadow:a}),rn=(e,...t)=>e.map((e,n)=>e+t.reduce((e,[t,r])=>e+t[n]*r,0)),an=(e,t)=>e.map(e=>e*t),on=({eye:e,yaw:t,pitch:r,dead:i,others:a,fx:o,bullets:s,lvl:c,t:l})=>{let[u,d,f]=U(t,r),p=[];i||(p.push(nn(rn(e,[u,.2],[d,-.2]),f,Qt,25,Xt,!0)),o.flash>0&&p.push(nn(rn(e,[u,.26],[d,-.24],[f,.6+Ne*.8]),f,$t,8,Zt,!0)));let m=t=>Math.hypot(t[0]-e[0],t[1]-e[1],t[2]-e[2]),h=[];a.map(e=>({p:e,e:[e.x,e.y+n,e.z]})).sort((e,t)=>m(e.e)-m(t.e)).forEach(({p:e,e:t},n)=>{let[r,i,a]=U(e.yaw,e.pitch);h.push(nn(rn(t,[a,.35]),a,Qt,25,Xt,n<en)),o.flashes.has(e.id)&&h.push(Z(rn([e.x,e.y+1.25,e.z],[r,.36],[i,-.12],[a,.8]),6,Zt))});for(let e of o.blasts){let t=ut(e);t>0&&h.push(Z(e.p,6,an(Zt,t*6)))}o.hurt>0&&h.push(Z(e,4,an([2,.15,.1],Math.min(1,o.hurt*10)))),s.map(e=>Z([e.x,e.y,e.z],3,[1.2,.4,.15])).sort((e,t)=>m(e.p)-m(t.p)).slice(0,tn).forEach(e=>h.push(e));let{exit:g,goal:_}=c.map;if(g!==void 0){let e=1+.3*Math.sin(l*4);if(c.barred.has(g)){if(_){let t=c.map.sectors[y(c,_[0],_[1])]?.floor??0;h.push(Z([_[0],t+1,_[1]],8,an([.2,1.2,1.5],e)))}}else{let{floor:t}=c.map.sectors[g];for(let{ax:n,az:r,bx:i,bz:a,front:o,back:s}of c.edges)if(o==g&&s>=0){let[o,s]=[i-n,a-r],c=.5/Math.hypot(o,s);h.push(Z([(n+i)/2-s*c,t+1.2,(r+a)/2+o*c],8,an([.2,1.5,.3],e)))}}}return p.concat(h.sort((e,t)=>m(e.p)-m(t.p)).slice(0,16-p.length))},sn=1.5,cn=(e,t)=>{let n=O[e]?.name;return`Level ${e+1}${n?`: ${n}`:``}${t?` (hard mode)`:``}`},ln=e=>{let t=Math.floor(e*10/60);return`${Math.floor(t/600)}:${String(Math.floor(t/10)%60).padStart(2,`0`)}.${t%10}`},un=({spawns:e},t,n)=>e.reduce((e,r)=>Math.hypot(r[0]-t,r[1]-n)<Math.hypot(e[0]-t,e[1]-n)?r:e)[2],dn=({lvl:e,you:t,roster:n,predictor:r,rd:i,delays:a,fx:o,hud:s,audio:c})=>{let l=-1,u=-1,d=0,f=/* @__PURE__ */ new Map,p={lvl:e,items:[],dead:!1,hp:0,name:cn(0,!1),returning:!1,alive:e=>f.get(e)!==0,snapshot(e){let n=t(),h=e.level*2+ +e.hard;if(h!=l){let t=O[e.level];if(!t)return;l=h,p.lvl=g(t),p.items=[],f=/* @__PURE__ */ new Map,u=-1,r.level(p.lvl),i?.level(p.lvl),o.reset(p.lvl),a.forEach(e=>e.clear()),p.name=cn(e.level,e.hard),s.say(Tt.TITLE,`Level ${e.level+1}${e.hard?`
|
|
2
|
+
Hard mode`:``}`)}let _=e.players.find(e=>e.id==n),v=f.get(n);_&&v!==void 0&&_.hp<v&&o.hit(),f=new Map(e.players.map(e=>[e.id,e.hp]));for(let t of p.items)_&&!e.items.some(e=>e.id==t.id)&&Math.hypot(t.x-_.x,t.z-_.z)<sn&&(o.pickup(pt[t.kind]),c?.play(z.COLLECT));p.items=e.items,e.phase!=u&&(u=e.phase,p.returning=u==m.RETURN,s.say(Tt.NOTE,u==m.RETURN?`Back to the start!`:`Find the exit`)),_?.hp===0&&!p.dead&&(d=e.tick),p.dead=_?.hp===0,p.hp=_?.hp??0,s.hp(p.hp),s.keys(e.keys);let y=180-(e.tick-d&65535);s.dead(p.dead?Math.max(1,Math.ceil(y/60)):0)},end(e,t,r){let i=new Map(n().map(e=>[e.id,e])),a=r.filter(e=>i.has(e.id)).sort((e,t)=>t.kills-e.kills||e.deaths-t.deaths||e.id-t.id).map(({id:e,kills:t,deaths:n})=>[i.get(e).name,i.get(e).color,t,n]);s.end(`Run complete\n${ln(e)}${t?` (hard)`:``}`,a,`Next run: Hard mode`)}};return p},fn=Object.keys(h).length,pn=(e,t,n)=>{let r=Math.imul(e,374761393)+Math.imul(t,668265263)+Math.imul(n,144665)|0;return r=Math.imul(r^r>>>13,1274126177),((r^r>>>16)>>>0)/4294967296},mn=(e,t,n,r)=>{let[i,a]=[Math.floor(e),Math.floor(t)],[o,s]=[e-i,t-a].map(e=>e*e*(3-2*e)),c=(e,t)=>pn((i+e)%n,(a+t)%n,r);return(c(0,0)*(1-o)+c(1,0)*o)*(1-s)+(c(0,1)*(1-o)+c(1,1)*o)*s},hn=(e,t,n,r,i)=>{let[a,o]=[0,.5];for(let s=0;s<r;s++,o/=2)a+=o*mn(e*(1<<s),t*(1<<s),n<<s,i+s);return a/(1-o*2)},gn=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),Q=(e,t)=>e.map(e=>e*t),$=[];$[h.BRICK]=(e,t)=>{let n=Math.floor(t*8),r=e*4+(n&1)*.5,[i,a,o]=[Math.floor(r)%4,r%1,t*8%1],s=.8+.4*mn(e*16,t*16,16,5);return a<.04||o<.08?Q([165,160,150],.7+.3*s):Q([170,78,56],(.8+.4*pn(i,n,1))*s*(.85+.15*o))},$[h.TILE]=(e,t)=>{let[n,r]=[Math.floor(e*4),Math.floor(t*4)],i=.9+.2*mn(e*16,t*16,16,7);return e*4%1<.04||t*4%1<.04?Q([85,85,80],i):Q([196,190,172],i*(.88+.08*(n+r&1)+.1*pn(n,r,2)))},$[h.LAVA]=(e,t)=>{let n=hn(e*4,t*4,4,4,11),r=Math.max(0,1-Math.abs(n-.5)*7)**2;return gn(gn([55,8,4],[230,70,8],n),[255,215,90],r)},$[h.STONE]=(e,t)=>Q([128,124,120],.45+.7*(hn(e*8,t*8,8,4,3)*1.3+.1*pn(Math.floor(e*128),Math.floor(t*128),4)));var _n=()=>{let e=new Uint8ClampedArray(fn*128*128*4);return $.forEach((t,n)=>{for(let r=0;r<16384;r++){let i=t(r%128/128,Math.floor(r/128)/128);e.set([...i.map(Math.round),255],(n*128*128+r)*4)}}),e},vn=[.05,.045,.05],yn=1<<18,bn=2,xn=512,Sn=.3,Cn=.55,wn=`#version 300 es
|
|
3
3
|
layout(location=0)in vec3 p;layout(location=1)in vec3 n;layout(location=2)in vec4 c;
|
|
4
4
|
uniform mat4 m;out vec3 P,N;out vec4 C;
|
|
5
|
-
void main(){P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,
|
|
5
|
+
void main(){P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,Tn=`#version 300 es
|
|
6
6
|
precision highp float;precision highp sampler2DArray;precision highp sampler2DArrayShadow;
|
|
7
7
|
in vec3 P,N;in vec4 C;uniform vec3 E;uniform float T,Z;uniform int Q;
|
|
8
8
|
uniform vec4 A[16],B[16],K[16];uniform mat4 M[4];
|
|
@@ -10,7 +10,7 @@ uniform sampler2DArray S;uniform sampler2DArrayShadow D;out vec4 o;
|
|
|
10
10
|
void main(){
|
|
11
11
|
if(Z<0.)return;
|
|
12
12
|
float L=C.z,s=step(0.,L),g=step(abs(L-${h.LAVA}.),.5)+step(L,-1.5);
|
|
13
|
-
vec3 c=mix(vec3(C.xy,C.w),texture(S,vec3(C.xy/${
|
|
13
|
+
vec3 c=mix(vec3(C.xy,C.w),texture(S,vec3(C.xy/${bn}.+vec2(g*T*.01,0),max(L,0.))).rgb,s);
|
|
14
14
|
vec3 n=normalize(N),l=vec3(mix(1.,C.w,s)*Z*(.45+.55*max(dot(n,normalize(vec3(.4,.8,.3))),0.)));
|
|
15
15
|
for(int i=0;i<16;i++){
|
|
16
16
|
if(i>=Q||g>0.)break;
|
|
@@ -21,8 +21,9 @@ w*=w*smoothstep(u,u+(1.-u)*.4,-dot(d,B[i].xyz))*max(dot(n,d),0.);
|
|
|
21
21
|
if(w>0.&&k>=0.){
|
|
22
22
|
vec4 q=M[int(k)]*vec4(P+n*.03,1);q.xyz=q.xyz/q.w*.5+.5;
|
|
23
23
|
float v=0.;
|
|
24
|
-
for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/
|
|
24
|
+
for(int j=0;j<4;j++)v+=texture(D,vec4(q.xy+(vec2(j&1,j>>1)*2.-1.)*${.75/xn},k,q.z-.0005));
|
|
25
25
|
w*=v/4.;}
|
|
26
26
|
l+=K[i].rgb*w;}
|
|
27
|
+
l=2.*(1.-exp(-.5*l));
|
|
27
28
|
c*=mix(l,vec3(1.4),g);
|
|
28
|
-
o=vec4(mix(c,vec3(${mn}),1.-exp(-.02*length(P-E))),1);}`,Sn=(e,t,n,r,i=0,a=Math.tan(70*Math.PI/360),[o,s]=[.1,200])=>{let[c,l,u]=W(t,n,i),d=(s+o)/(s-o),f=[c.map(e=>e/(a*r)),l.map(e=>e/a),u.map(e=>e*d),u].map(t=>[...t,-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]);return f[2][3]-=2*s*o/(s-o),Float32Array.from({length:16},(e,t)=>f[t&3][t>>2])},Cn=(e,t,n,r)=>{let i=e[3]*t+e[7]*n+e[11]*r+e[15];if(i<=0)return;let a=e[0]*t+e[4]*n+e[8]*r+e[12],o=e[1]*t+e[5]*n+e[9]*r+e[13];return[.5+a/(2*i),.5-o/(2*i)]},wn=({p:e,d:t,cone:n,range:r})=>Sn(e,Math.atan2(-t[0],-t[2]),Math.atan2(t[1],Math.hypot(t[0],t[2])),1,0,Math.min(Math.tan(Math.acos(n)),5.7),[.3,r]),Tn=e=>{let[t,n,r]=[0,0,0].map(()=>/* @__PURE__ */ new Float32Array(64)),i=/* @__PURE__ */ new Float32Array(64),a=0,o=e.slice(0,16);return o.forEach((e,o)=>{let s=e.shadow&&e.kind==Gt.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==Gt.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(wn(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},En=({map:e},{front:t,back:n})=>{let r=e.sectors[t];if(n<0)return[[r.floor,r.ceil]];let i=e.sectors[n];return[[r.floor,i.floor],[i.ceil,r.ceil]].filter(([e,t])=>t>e)},Dn=e=>{let t=[];for(let{pts:n,floor:r,ceil:i,ft:a,ct:o,light:s=1}of e.map.sectors)for(let[e,c,l]of[[r,1,a],[i,-1,o]])for(let r=1;r<n.length-1;r++)for(let[i,a]of[n[0],n[r],n[r+1]])t.push(i,e,a,0,c,0,i,a,l,s);for(let n of e.edges){let{ax:r,az:i,bx:a,bz:o,front:s}=n,{wt:c,light:l=1}=e.map.sectors[s],u=Math.hypot(a-r,o-i),[d,f]=[(a-r)/u,(o-i)/u];for(let[s,u]of En(e,n))for(let[e,n,p]of[[r,i,s],[a,o,s],[a,o,u],[r,i,s],[a,o,u],[r,i,u]])t.push(e,p,n,-f,0,d,e*d+n*f,p,c,l)}return t},On=(n,r)=>{let i=r,a=n.getContext(`webgl2`,{antialias:!0});if(!a)throw Error(`WebGL2 is not available`);let o=document.createElement(`canvas`).getContext(`2d`),s=/* @__PURE__ */ new Map,c=e=>{let t=s.get(e);if(!t){o.fillStyle=`#888`,o.fillStyle=e;let n=parseInt(o.fillStyle.slice(1),16),r=n>=0?n:8947848;s.set(e,t=[r>>16,r>>8&255,r&255].map(e=>e/255))}return t},l=Dn(i),u=pn(),f=l.length*4,p=f+hn,[m,h]=[[.55,.55,.6],[.2,.2,.23]],g={barrels:K(Pe(10).barrels,m),body:K(Pe(10).body,h)},_={barrels:K(Pe(5).barrels,m),body:K(Pe(5).body,h)},v=[],y=[];for(let e of[[.1,.01,.03],[.01,.1,.03],[.03,.03,.05]])G(v,[0,0,-je-.04],e,0,[1,.85,.4],-2),G(y,[0,0,-je-.12],e.map(e=>e*3),0,[1,.85,.4],-2);let b={},x,S,C=!1,w=/* @__PURE__ */ new Float32Array(16),T=()=>{a.bufferData(a.ARRAY_BUFFER,p,a.DYNAMIC_DRAW),a.bufferSubData(a.ARRAY_BUFFER,0,new Float32Array(l))},E=()=>{let e=a.createProgram();for(let[t,n]of[[a.VERTEX_SHADER,bn],[a.FRAGMENT_SHADER,xn]]){let r=a.createShader(t);a.shaderSource(r,n),a.compileShader(r),a.attachShader(e,r)}a.linkProgram(e),a.useProgram(e),b=Object.fromEntries([`m`,`E`,`T`,`Z`,`Q`,`A`,`B`,`K`,`M`,`D`].map(t=>[t,a.getUniformLocation(e,t)])),a.uniform1i(b.D,1),a.bindBuffer(a.ARRAY_BUFFER,a.createBuffer()),T(),[3,3,4].reduce((e,t,n)=>(a.enableVertexAttribArray(n),a.vertexAttribPointer(n,t,a.FLOAT,!1,40,e*4),e+t),0),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D_ARRAY,x=a.createTexture()),a.texStorage3D(a.TEXTURE_2D_ARRAY,1,a.DEPTH_COMPONENT24,_n,_n,4);for(let[e,t]of[[a.TEXTURE_MIN_FILTER,a.LINEAR],[a.TEXTURE_MAG_FILTER,a.LINEAR],[a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE],[a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE],[a.TEXTURE_COMPARE_MODE,a.COMPARE_REF_TO_TEXTURE]])a.texParameteri(a.TEXTURE_2D_ARRAY,e,t);a.bindFramebuffer(a.FRAMEBUFFER,S=a.createFramebuffer()),a.drawBuffers([a.NONE]),a.bindFramebuffer(a.FRAMEBUFFER,null),a.polygonOffset(2,4),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D_ARRAY,a.createTexture()),a.texImage3D(a.TEXTURE_2D_ARRAY,0,a.RGBA8,128,128,sn,0,a.RGBA,a.UNSIGNED_BYTE,u),a.generateMipmap(a.TEXTURE_2D_ARRAY),a.texParameteri(a.TEXTURE_2D_ARRAY,a.TEXTURE_MIN_FILTER,a.LINEAR_MIPMAP_LINEAR);let t=a.getExtension(`EXT_texture_filter_anisotropic`);t&&a.texParameterf(a.TEXTURE_2D_ARRAY,t.TEXTURE_MAX_ANISOTROPY_EXT,8),a.enable(a.DEPTH_TEST),a.clearColor(mn[0],mn[1],mn[2],1)};E();let D=e=>{e.preventDefault(),C=!0},O=()=>{E(),C=!1};return n.addEventListener(`webglcontextlost`,D),n.addEventListener(`webglcontextrestored`,O),{level(e){i=e,l=Dn(i),f=l.length*4,p=f+hn,C||T()},frame(r,o,s,u,m,h,E,D,O,k){let A=Math.min(devicePixelRatio,2),j=Math.round(n.clientWidth*A),M=Math.round(n.clientHeight*A);if(C||!j||!M)return;(n.width!=j||n.height!=M)&&(n.width=j,n.height=M),w=Sn(r,o,s,j/M,h.roll);let N=[];for(let n of u){let[r,i]=Ce(n.yaw),a=e*.8,o=1.4500000000000002;G(N,[n.x,n.y+o/2,n.z],[a,o/2,a],n.yaw,[...c(m.get(n.id)??`#888`)]);let s=[n.x,n.y+t-.17,n.z];G(N,s,[.17,.17,.17],n.yaw,[.95,.8,.65]),G(N,[s[0]+r*.17,s[1]+.03,s[2]+i*.17],[.13,.05,.03],n.yaw,[.1,.1,.12]);let l=[n.x,n.y+1.25,n.z],u=W(n.yaw,n.pitch);for(let e of[_.barrels,_.body,h.flashes.has(n.id)?y:[]])q(N,e,l,u,[.36,-.12,.3],.8)}let P=performance.now()/1e3;for(let e of E)if(e.kind==d.FLYER)Ue(N,e,P);else{let t=h.swings.get(e.id);Ve(N,e,h.herd.get(e.id)?.walked??0,t?1-t/Fe:0)}xt(N,i,O,P);for(let{p:e,yaw:t,size:n,c:r,life:i}of h.gibs){let a=n*Math.min(1,i*2);G(N,e,[a,a,a],t,r)}let F=N.length;for(let e of D)We(N,e,h.aim.get(e.id));for(let{p:e,c:t}of h.sparks)G(N,e,[.025,.025,.025],0,t??[1,.8,.3],-2);for(let e of h.blasts){let[t,n]=[st(e),e.t/Xe],r=[1,.9-n*.7,.5-n*.45];for(let n of[0,Math.PI/4])G(N,e.p,[t,t,t],n,r,-2)}let I=N.length,ee=W(o,s,h.roll),te=[.26,-.24+h.kick*.01,.6-h.kick*.06];h.dead||(q(N,g.body,r,ee,te,.8),q(N,g.barrels,r,ee,te,.8,h.spin),h.flash>0&&q(N,v,r,ee,te,.8,h.spin*3)),f+N.length*4>p&&(p=f+N.length*8,T()),a.bufferSubData(a.ARRAY_BUFFER,f,new Float32Array(N));let L=Tn(k),R=l.length/10;if(L.maps){a.uniform1f(b.Z,-1),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D_ARRAY,null),a.bindFramebuffer(a.FRAMEBUFFER,S),a.viewport(0,0,_n,_n),a.enable(a.POLYGON_OFFSET_FILL);for(let e=0;e<L.maps;e++)a.framebufferTextureLayer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,x,0,e),a.uniformMatrix4fv(b.m,!1,L.m.subarray(e*16,e*16+16)),a.clear(a.DEPTH_BUFFER_BIT),a.drawArrays(a.TRIANGLES,0,R+F/10);a.disable(a.POLYGON_OFFSET_FILL),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindTexture(a.TEXTURE_2D_ARRAY,x),a.activeTexture(a.TEXTURE0)}a.viewport(0,0,j,M),a.uniformMatrix4fv(b.m,!1,w),a.uniform3fv(b.E,r),a.uniform1f(b.T,performance.now()/1e3),a.uniform1f(b.Z,vn),a.uniform1i(b.Q,L.n),a.uniform4fv(b.A,L.a),a.uniform4fv(b.B,L.b),a.uniform4fv(b.K,L.k),a.uniformMatrix4fv(b.M,!1,L.m),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT),a.drawArrays(a.TRIANGLES,0,R+I/10),a.clear(a.DEPTH_BUFFER_BIT),a.uniform1f(b.Z,yn),a.drawArrays(a.TRIANGLES,R+I/10,(N.length-I)/10)},project:(e,t,n)=>Cn(w,e,t,n),destroy(){n.removeEventListener(`webglcontextlost`,D),n.removeEventListener(`webglcontextrestored`,O),a.getExtension(`WEBGL_lose_context`)?.loseContext()}}},kn=1/60,An=5,jn=(e,i)=>{let a=document.createElement(`div`),o=a.attachShadow({mode:`open`});o.innerHTML=`<style>:host{display:block;width:100%;height:100%}div{position:relative;width:100%;height:100%;overflow:hidden;background:#000;font:600 14px system-ui,sans-serif;color:#fff;text-shadow:0 1px 2px #000}canvas{display:block;width:100%;height:100%;cursor:pointer}i,p,b,em,s{position:absolute;pointer-events:none;user-select:none;margin:0}s{inset:0;background:#e00;opacity:0}`+wt+`i{left:50%;top:50%;width:6px;height:6px;margin:-3px;border-radius:50%;background:#fff;box-shadow:0 0 0 1px #0008}p{top:8px;left:12px}em{left:50%;top:60%;transform:translateX(-50%);font-size:18px;font-style:normal}b{transform:translate(-50%,-100%);font-size:12px;white-space:nowrap}[hidden]{display:none}</style><div><canvas></canvas><s></s><s></s><i></i><p></p><em></em></div>`,e.append(a);let s=o.querySelector(`canvas`),c=o.querySelector(`p`),l=o.querySelector(`em`),[u,d]=o.querySelectorAll(`s`),f=o.querySelector(`div`),p=Tt(f),m={roster:[],open:[],close:[]},h=e=>m[e].forEach(e=>e()),_=g(O[0]),v=Wt(_),y=me();y.mute(_e()),p.mute(y.muted);let x=ge(y),S=At(s,()=>p.mute(ve(y)));s.addEventListener(`click`,()=>y.unlock());let C=lt(Math.random,_),w=ct(),T=ct(),E=-1,D;try{D=On(s,_)}catch{}let k=on({lvl:_,you:()=>E,predictor:v,rd:D,delays:[w,T],fx:C,hud:p,audio:y}),A=[],j=/* @__PURE__ */ new Map,M=/* @__PURE__ */ new Map,N=/* @__PURE__ */ new Map,P=!1,F=D?``:`WebGL2 is not available`,I=!1,R=-1,ne=!1,re=performance.now(),B=0,V=0,ie=!1,H=i.socket??new WebSocket(i.url);H.binaryType=`arraybuffer`,H.onopen=()=>{P=!0,H.send(JSON.stringify({t:`join`,name:i.name})),h(`open`)},H.onclose=()=>{P=!1,F||=`Connection closed`,h(`close`)},H.onmessage=({data:e})=>{if(typeof e!=`string`){let t=te(e);if(t){let e=performance.now();k.snapshot(t),v.snapshot(t,e);let n=t.players.find(e=>e.id==E),r=t.level*2+ +t.hard;n?.hp&&(r!=R||!ne)&&([S.yaw,S.pitch]=[an(k.lvl.map,n.x,n.z),0]),[R,ne]=[r,!!n?.hp],w.push(t.shots.filter(e=>e.id!=E),e),T.push(t.events,e)}return}let t=L(e);t?.t==`roster`?(A=t.players,j=new Map(A.map(e=>[e.id,e.color])),M=new Map(A.map(e=>[e.id,e.name])),v.you(E=t.you),c.textContent=`Players: ${A.length}`,h(`roster`)):t?.t==`full`?F=`Room is full`:t?.t==`end`&&k.end(t.ticks,t.hard)};let ae=e=>{let t=N.get(e);return t||(N.set(e,t=document.createElement(`b`)),f.append(t)),t},oe=()=>{V=requestAnimationFrame(oe);let e=performance.now(),i=re;if(B=Math.min(B+(e-re)/1e3,An*kn),re=e,!I){let e=v.me(0);e&&([S.yaw,S.pitch,I]=[e.yaw,e.pitch,!0]),B=0}for(;I&&B>=kn;B-=kn){let t=k.dead?0:S.keys,r=v.step({keys:t,yaw:S.yaw,pitch:S.pitch},e);P&&H.send(ee(r));let i=v.shot(),a=i&&v.me(1);i&&a&&(C.shot(i,[a.x,a.y+n,a.z],!0),y.play(z.SHOT))}let a=v.me(B/kn),o=v.others(e).filter(e=>k.alive(e.id)),s=v.monsters(e),c=v.bullets(e),f=a?[a.x,a.y+n,a.z]:[0,0,0];C.track(s,c),y.listen(f,S.yaw);for(let t of w.due(e)){let e=o.find(e=>e.id==t.id);if(e){let r=[e.x,e.y+n,e.z];C.shot(t,r,!1,t.hit!=E),y.play(z.SHOT,r)}}for(let t of T.due(e))C.event(t,E),he(y,t,E);x(k.returning,e);let m=Math.min((e-i)/1e3,.1);if(C.update(a,S.keys,m,k.dead),p.update(m),a&&D){let t=Math.max(-1.55,Math.min(r,S.pitch+C.shakePitch));D.frame([f[0],f[1]+C.bob,f[2]],S.yaw+C.shakeYaw,t,o,j,C,s,c,k.items,tn({eye:[f[0],f[1]+C.bob,f[2]],yaw:S.yaw,pitch:S.pitch,dead:k.dead,others:o,fx:C,bullets:c,lvl:k.lvl,t:e/1e3}))}let h=/* @__PURE__ */ new Set;for(let e of o){let n=[e.x,e.y+t+.3,e.z],r=a&&!b(k.lvl,f,n)?D?.project(...n):void 0,i=ae(e.id);h.add(e.id),i.hidden=!r,r&&(i.style.left=r[0]*100+`%`,i.style.top=r[1]*100+`%`);let o=M.get(e.id)??``;i.textContent!=o&&(i.textContent=o)}for(let[e,t]of N)h.has(e)||(t.remove(),N.delete(e));for(let[e,t]of[[u,C.hurt*2],[d,C.gain*.8]])e.style.opacity=String(t);d.style.background=dt(C.gainC);let g=F||(P?I?S.locked()?``:`Click to play`:`Joining…`:`Connecting…`);l.textContent!=g&&(l.textContent=g)};return V=requestAnimationFrame(oe),{on:(e,t)=>void m[e].push(t),players:()=>A,destroy(){ie||(ie=!0,cancelAnimationFrame(V),S.destroy(),y.destroy(),D?.destroy(),H.onopen=H.onclose=H.onmessage=null,H.close(),document.exitPointerLock(),a.remove())}}};export{jn as tinyFps};
|
|
29
|
+
o=vec4(mix(c,vec3(${vn}),1.-exp(-.02*length(P-E))),1);}`,En=(e,t,n,r,i=0,a=Math.tan(70*Math.PI/360),[o,s]=[.1,200])=>{let[c,l,u]=U(t,n,i),d=(s+o)/(s-o),f=[c.map(e=>e/(a*r)),l.map(e=>e/a),u.map(e=>e*d),u].map(t=>[...t,-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]);return f[2][3]-=2*s*o/(s-o),Float32Array.from({length:16},(e,t)=>f[t&3][t>>2])},Dn=(e,t,n,r)=>{let i=e[3]*t+e[7]*n+e[11]*r+e[15];if(i<=0)return;let a=e[0]*t+e[4]*n+e[8]*r+e[12],o=e[1]*t+e[5]*n+e[9]*r+e[13];return[.5+a/(2*i),.5-o/(2*i)]},On=({p:e,d:t,cone:n,range:r})=>En(e,Math.atan2(-t[0],-t[2]),Math.atan2(t[1],Math.hypot(t[0],t[2])),1,0,Math.min(Math.tan(Math.acos(n)),5.7),[.3,r]),kn=e=>{let[t,n,r]=[0,0,0].map(()=>/* @__PURE__ */ new Float32Array(64)),i=/* @__PURE__ */ new Float32Array(64),a=0,o=e.slice(0,16);return o.forEach((e,o)=>{let s=e.shadow&&e.kind==Yt.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==Yt.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(On(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},An=({map:e},{front:t,back:n})=>{let r=e.sectors[t];if(n<0)return[[r.floor,r.ceil]];let i=e.sectors[n];return[[r.floor,i.floor],[i.ceil,r.ceil]].filter(([e,t])=>t>e)},jn=e=>{let t=[];for(let{pts:n,floor:r,ceil:i,ft:a,ct:o,light:s=1}of e.map.sectors)for(let[e,c,l]of[[r,1,a],[i,-1,o]])for(let r=1;r<n.length-1;r++)for(let[i,a]of[n[0],n[r],n[r+1]])t.push(i,e,a,0,c,0,i,a,l,s);for(let n of e.edges){let{ax:r,az:i,bx:a,bz:o,front:s}=n,{wt:c,light:l=1}=e.map.sectors[s],u=Math.hypot(a-r,o-i),[d,f]=[(a-r)/u,(o-i)/u];for(let[s,u]of An(e,n))for(let[e,n,p]of[[r,i,s],[a,o,s],[a,o,u],[r,i,s],[a,o,u],[r,i,u]])t.push(e,p,n,-f,0,d,e*d+n*f,p,c,l)}return t},Mn=(n,r)=>{let i=r,a=n.getContext(`webgl2`,{antialias:!0});if(!a)throw Error(`WebGL2 is not available`);let o=document.createElement(`canvas`).getContext(`2d`),s=/* @__PURE__ */ new Map,c=e=>{let t=s.get(e);if(!t){o.fillStyle=`#888`,o.fillStyle=e;let n=parseInt(o.fillStyle.slice(1),16),r=n>=0?n:8947848;s.set(e,t=[r>>16,r>>8&255,r&255].map(e=>e/255))}return t},l=jn(i),u=_n(),f=l.length*4,p=f+yn,[m,h]=[[.55,.55,.6],[.2,.2,.23]],g={barrels:Le(Ie(10).barrels,m),body:Le(Ie(10).body,h)},_={barrels:Le(Ie(5).barrels,m),body:Le(Ie(5).body,h)},v=[],y=[];for(let e of[[.1,.01,.03],[.01,.1,.03],[.03,.03,.05]])W(v,[0,0,-Ne-.04],e,0,[1,.85,.4],-2),W(y,[0,0,-Ne-.12],e.map(e=>e*3),0,[1,.85,.4],-2);let b={},x,S,C=!1,w=/* @__PURE__ */ new Float32Array(16),T=()=>{a.bufferData(a.ARRAY_BUFFER,p,a.DYNAMIC_DRAW),a.bufferSubData(a.ARRAY_BUFFER,0,new Float32Array(l))},E=()=>{let e=a.createProgram();for(let[t,n]of[[a.VERTEX_SHADER,wn],[a.FRAGMENT_SHADER,Tn]]){let r=a.createShader(t);a.shaderSource(r,n),a.compileShader(r),a.attachShader(e,r)}a.linkProgram(e),a.useProgram(e),b=Object.fromEntries([`m`,`E`,`T`,`Z`,`Q`,`A`,`B`,`K`,`M`,`D`].map(t=>[t,a.getUniformLocation(e,t)])),a.uniform1i(b.D,1),a.bindBuffer(a.ARRAY_BUFFER,a.createBuffer()),T(),[3,3,4].reduce((e,t,n)=>(a.enableVertexAttribArray(n),a.vertexAttribPointer(n,t,a.FLOAT,!1,40,e*4),e+t),0),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D_ARRAY,x=a.createTexture()),a.texStorage3D(a.TEXTURE_2D_ARRAY,1,a.DEPTH_COMPONENT24,xn,xn,4);for(let[e,t]of[[a.TEXTURE_MIN_FILTER,a.LINEAR],[a.TEXTURE_MAG_FILTER,a.LINEAR],[a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE],[a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE],[a.TEXTURE_COMPARE_MODE,a.COMPARE_REF_TO_TEXTURE]])a.texParameteri(a.TEXTURE_2D_ARRAY,e,t);a.bindFramebuffer(a.FRAMEBUFFER,S=a.createFramebuffer()),a.drawBuffers([a.NONE]),a.bindFramebuffer(a.FRAMEBUFFER,null),a.polygonOffset(2,4),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D_ARRAY,a.createTexture()),a.texImage3D(a.TEXTURE_2D_ARRAY,0,a.RGBA8,128,128,fn,0,a.RGBA,a.UNSIGNED_BYTE,u),a.generateMipmap(a.TEXTURE_2D_ARRAY),a.texParameteri(a.TEXTURE_2D_ARRAY,a.TEXTURE_MIN_FILTER,a.LINEAR_MIPMAP_LINEAR);let t=a.getExtension(`EXT_texture_filter_anisotropic`);t&&a.texParameterf(a.TEXTURE_2D_ARRAY,t.TEXTURE_MAX_ANISOTROPY_EXT,8),a.enable(a.DEPTH_TEST),a.clearColor(vn[0],vn[1],vn[2],1)};E();let D=e=>{e.preventDefault(),C=!0},O=()=>{E(),C=!1};return n.addEventListener(`webglcontextlost`,D),n.addEventListener(`webglcontextrestored`,O),{level(e){i=e,l=jn(i),f=l.length*4,p=f+yn,C||T()},frame(r,o,s,u,m,h,E,D,O,k){let A=Math.min(devicePixelRatio,2),j=Math.round(n.clientWidth*A),M=Math.round(n.clientHeight*A);if(C||!j||!M)return;(n.width!=j||n.height!=M)&&(n.width=j,n.height=M),w=En(r,o,s,j/M,h.roll);let N=[];for(let n of u){let[r,i]=Te(n.yaw),a=e*.8,o=1.4500000000000002;W(N,[n.x,n.y+o/2,n.z],[a,o/2,a],n.yaw,[...c(m.get(n.id)??`#888`)]);let s=[n.x,n.y+t-.17,n.z];W(N,s,[.17,.17,.17],n.yaw,[.95,.8,.65]),W(N,[s[0]+r*.17,s[1]+.03,s[2]+i*.17],[.13,.05,.03],n.yaw,[.1,.1,.12]);let l=[n.x,n.y+1.25,n.z],u=U(n.yaw,n.pitch);for(let e of[_.barrels,_.body,h.flashes.has(n.id)?y:[]])G(N,e,l,u,[.36,-.12,.3],.8)}let P=performance.now()/1e3;for(let e of E)if(e.kind==d.FLYER)Ke(N,e,P);else{let t=h.swings.get(e.id);We(N,e,h.herd.get(e.id)?.walked??0,t?1-t/Re:0)}wt(N,i,O,P);for(let{p:e,yaw:t,size:n,c:r,life:i}of h.gibs){let a=n*Math.min(1,i*2);W(N,e,[a,a,a],t,r)}let F=N.length;for(let e of D)qe(N,e,h.aim.get(e.id));for(let{p:e,c:t}of h.sparks)W(N,e,[.025,.025,.025],0,t??[1,.8,.3],-2);for(let e of h.blasts){let[t,n]=[ut(e),e.t/$e],r=[1,.9-n*.7,.5-n*.45];for(let n of[0,Math.PI/4])W(N,e.p,[t,t,t],n,r,-2)}let I=N.length,ee=U(o,s,h.roll),te=[.26,-.24+h.kick*.01,.6-h.kick*.06];h.dead||(G(N,g.body,r,ee,te,.8),G(N,g.barrels,r,ee,te,.8,h.spin),h.flash>0&&G(N,v,r,ee,te,.8,h.spin*3)),f+N.length*4>p&&(p=f+N.length*8,T()),a.bufferSubData(a.ARRAY_BUFFER,f,new Float32Array(N));let L=kn(k),R=l.length/10;if(L.maps){a.uniform1f(b.Z,-1),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D_ARRAY,null),a.bindFramebuffer(a.FRAMEBUFFER,S),a.viewport(0,0,xn,xn),a.enable(a.POLYGON_OFFSET_FILL);for(let e=0;e<L.maps;e++)a.framebufferTextureLayer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,x,0,e),a.uniformMatrix4fv(b.m,!1,L.m.subarray(e*16,e*16+16)),a.clear(a.DEPTH_BUFFER_BIT),a.drawArrays(a.TRIANGLES,0,R+F/10);a.disable(a.POLYGON_OFFSET_FILL),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindTexture(a.TEXTURE_2D_ARRAY,x),a.activeTexture(a.TEXTURE0)}a.viewport(0,0,j,M),a.uniformMatrix4fv(b.m,!1,w),a.uniform3fv(b.E,r),a.uniform1f(b.T,performance.now()/1e3),a.uniform1f(b.Z,Sn),a.uniform1i(b.Q,L.n),a.uniform4fv(b.A,L.a),a.uniform4fv(b.B,L.b),a.uniform4fv(b.K,L.k),a.uniformMatrix4fv(b.M,!1,L.m),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT),a.drawArrays(a.TRIANGLES,0,R+I/10),a.clear(a.DEPTH_BUFFER_BIT),a.uniform1f(b.Z,Cn),a.drawArrays(a.TRIANGLES,R+I/10,(N.length-I)/10)},project:(e,t,n)=>Dn(w,e,t,n),destroy(){n.removeEventListener(`webglcontextlost`,D),n.removeEventListener(`webglcontextrestored`,O),a.getExtension(`WEBGL_lose_context`)?.loseContext()}}},Nn=1/60,Pn=5,Fn=(e,i)=>{let a=document.createElement(`div`),o=a.attachShadow({mode:`open`});o.innerHTML=`<style>:host{display:block;width:100%;height:100%}div{position:relative;width:100%;height:100%;overflow:hidden;background:#000;font:600 14px system-ui,sans-serif;color:#fff;text-shadow:0 1px 2px #000}canvas{display:block;width:100%;height:100%;cursor:pointer}i,p,b{position:absolute;pointer-events:none;user-select:none;margin:0}`+Ot+`i{left:50%;top:50%;width:6px;height:6px;margin:-3px;border-radius:50%;background:#fff;box-shadow:0 0 0 1px #0008}p{top:8px;left:12px}b{transform:translate(-50%,-100%);font-size:12px;white-space:nowrap}[hidden]{display:none}</style><div><canvas></canvas><i></i><p></p></div>`,e.append(a);let s=o.querySelector(`canvas`),c=o.querySelector(`p`),l=o.querySelector(`div`),u=kt(l),d={roster:[],open:[],close:[]},f=e=>d[e].forEach(e=>e()),p=g(O[0]),m=Jt(p),h=he();h.mute(ye()),u.mute(h.muted);let _=_e(h),v=ve(h),y=Pt(s,()=>u.mute(be(h)));s.addEventListener(`click`,()=>h.unlock());let x=ft(Math.random,p),S=dt(),C=dt(),w=-1,T;try{T=Mn(s,p)}catch{}let E=dn({lvl:p,you:()=>w,roster:()=>D,predictor:m,rd:T,delays:[S,C],fx:x,hud:u,audio:h}),D=[],k=/* @__PURE__ */ new Map,A=/* @__PURE__ */ new Map,j=/* @__PURE__ */ new Map,M=!1,N=T?``:`WebGL2 is not available`,P=!1,F=-1,I=!1,R=performance.now(),B=0,ne=0,re=!1,V=i.socket??new WebSocket(i.url);V.binaryType=`arraybuffer`,V.onopen=()=>{M=!0,V.send(JSON.stringify({t:`join`,name:i.name})),f(`open`)},V.onclose=()=>{M=!1,N||=`Connection closed`,f(`close`)},V.onmessage=({data:e})=>{if(typeof e!=`string`){let t=te(e);if(t){let e=performance.now();E.snapshot(t),m.snapshot(t,e);let n=t.players.find(e=>e.id==w),r=t.level*2+ +t.hard;n?.hp&&(r!=F||!I)&&([y.yaw,y.pitch]=[un(E.lvl.map,n.x,n.z),0]),[F,I]=[r,!!n?.hp],S.push(t.shots.filter(e=>e.id!=w),e),C.push(t.events,e)}return}let t=L(e);t?.t==`roster`?(D=t.players,k=new Map(D.map(e=>[e.id,e.color])),A=new Map(D.map(e=>[e.id,e.name])),m.you(w=t.you),c.textContent=`Players: ${D.length}`,f(`roster`)):t?.t==`full`?N=`Room is full`:t?.t==`end`&&E.end(t.ticks,t.hard,t.stats)};let ie=e=>{let t=j.get(e);return t||(j.set(e,t=document.createElement(`b`)),l.append(t)),t},ae=()=>{ne=requestAnimationFrame(ae);let e=performance.now(),i=R;if(B=Math.min(B+(e-R)/1e3,Pn*Nn),R=e,!P){let e=m.me(0);e&&([y.yaw,y.pitch,P]=[e.yaw,e.pitch,!0]),B=0}for(;P&&B>=Nn;B-=Nn){let t=E.dead?0:y.keys,r=m.step({keys:t,yaw:y.yaw,pitch:y.pitch},e);M&&V.send(ee(r));let i=m.shot(),a=i&&m.me(1);i&&a&&(x.shot(i,[a.x,a.y+n,a.z],!0),h.play(z.SHOT))}let a=m.me(B/Nn),o=m.others(e).filter(e=>E.alive(e.id)),s=m.monsters(e),c=m.bullets(e),l=a?[a.x,a.y+n,a.z]:[0,0,0];x.track(s,c),h.listen(l,y.yaw);for(let t of S.due(e)){let e=o.find(e=>e.id==t.id);if(e){let r=[e.x,e.y+n,e.z];x.shot(t,r,!1,t.hit!=w),h.play(z.SHOT,r)}}for(let t of C.due(e))x.event(t,w),ge(h,t,w);_(E.returning,e);let d=Math.min((e-i)/1e3,.1);if(x.update(a,y.keys,d,E.dead),u.update(d),a&&T){let t=Math.max(-1.55,Math.min(r,y.pitch+x.shakePitch));T.frame([l[0],l[1]+x.bob,l[2]],y.yaw+x.shakeYaw,t,o,k,x,s,c,E.items,on({eye:[l[0],l[1]+x.bob,l[2]],yaw:y.yaw,pitch:y.pitch,dead:E.dead,others:o,fx:x,bullets:c,lvl:E.lvl,t:e/1e3}))}let f=/* @__PURE__ */ new Set;for(let e of o){let n=[e.x,e.y+t+.3,e.z],r=a&&!b(E.lvl,l,n)?T?.project(...n):void 0,i=ie(e.id);f.add(e.id),i.hidden=!r,r&&(i.style.left=r[0]*100+`%`,i.style.top=r[1]*100+`%`);let o=A.get(e.id)??``;i.textContent!=o&&(i.textContent=o)}for(let[e,t]of j)f.has(e)||(t.remove(),j.delete(e));u.fade(x.hurt/et,v(E.hp,e),x.gain/tt,x.gainC),u.title(N||(M?P?y.locked()?``:`Click to play`:`Joining…`:`Connecting…`),E.name)};return ne=requestAnimationFrame(ae),{on:(e,t)=>void d[e].push(t),players:()=>D,destroy(){re||(re=!0,cancelAnimationFrame(ne),y.destroy(),h.destroy(),T?.destroy(),V.onopen=V.onclose=V.onmessage=null,V.close(),document.exitPointerLock(),a.remove())}}};export{Fn as tinyFps};
|
package/dist/local.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=65536/(2*Math.PI),t=t=>Math.round(t*e)&65535,n=e=>Math.max(-32768,Math.min(32767,Math.round(e))),r=e=>n(e*1e4),i=e=>e/1e4,a=t=>t/e,o=e=>{if(e.byteLength!==11)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint8(3),yaw:a(t.getUint16(4)),pitch:i(t.getInt16(6)),view:(t.getUint16(8)*256+t.getUint8(10))/256}:null},s=e=>{let n=7+25*e.players.length,i=n+1+14*e.shots.length,a=i+1+16*e.monsters.length,o=a+1+13*e.bullets.length,s=o+1+14*e.events.length,c=new DataView(new ArrayBuffer(s+1+14*e.items.length));return c.setUint8(0,2),c.setUint16(1,e.tick&65535),c.setUint8(3,e.players.length),c.setUint8(4,e.level),c.setUint8(5,+e.hard|(e.phase&1)<<1),c.setUint8(6,e.keys),e.players.forEach((e,n)=>{let i=7+n*25;c.setUint8(i,e.id),c.setFloat32(i+1,e.x),c.setFloat32(i+5,e.y),c.setFloat32(i+9,e.z),c.setFloat32(i+13,e.vy),c.setUint16(i+17,t(e.yaw)),c.setInt16(i+19,r(e.pitch)),c.setUint16(i+21,e.ack&65535),c.setUint8(i+23,+e.ground|e.cool<<1),c.setUint8(i+24,e.hp)}),c.setUint8(n,e.shots.length),e.shots.forEach((e,t)=>{let r=n+1+t*14;c.setUint8(r,e.id),c.setFloat32(r+1,e.x),c.setFloat32(r+5,e.y),c.setFloat32(r+9,e.z),c.setUint8(r+13,e.hit&255)}),c.setUint8(i,e.monsters.length),e.monsters.forEach((e,n)=>{let r=i+1+n*16;c.setUint8(r,e.id),c.setUint8(r+1,e.kind&1|e.chase<<1),c.setFloat32(r+2,e.x),c.setFloat32(r+6,e.y),c.setFloat32(r+10,e.z),c.setUint16(r+14,t(e.yaw))}),c.setUint8(a,e.bullets.length),e.bullets.forEach((e,t)=>{let n=a+1+t*13;c.setUint8(n,e.id),c.setFloat32(n+1,e.x),c.setFloat32(n+5,e.y),c.setFloat32(n+9,e.z)}),c.setUint8(o,e.events.length),e.events.forEach((e,t)=>{let n=o+1+t*14;c.setUint8(n,e.type),c.setUint8(n+1,e.id),c.setFloat32(n+2,e.x),c.setFloat32(n+6,e.y),c.setFloat32(n+10,e.z)}),c.setUint8(s,e.items.length),e.items.forEach((e,t)=>{let n=s+1+t*14;c.setUint8(n,e.id),c.setUint8(n+1,e.kind),c.setFloat32(n+2,e.x),c.setFloat32(n+6,e.y),c.setFloat32(n+10,e.z)}),c.buffer},c=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},l=.4,u=1.8,d=1.6,f=1.55,p=.5,m=.5,h=.02,g=.4,_=1.8,v=2.5,y=.45,b=.9,x=1.2,S=3.5,ee=Math.cos(Math.PI/6),C=.15,te=1.3,ne=.6,w={maxPlayers:16},T={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,FIRE:32},E={WALKER:0,FLYER:1},D={DIE:0,HURT:1,BOOM:2,SWING:3},O={HEALTH:0,KEY_RED:1,KEY_BLUE:2,KEY_YELLOW:3},k={HUNT:0,RETURN:1},A=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r)));let r={map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}})),barred:/* @__PURE__ */ new Set};return j(r,0,k.HUNT),r},j=({map:e,barred:t},n,r)=>{t.clear(),e.gates?.forEach(e=>n&1<<e.key||t.add(e.sector)),e.exit!==void 0&&r===k.HUNT&&t.add(e.exit)},M=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),N=({map:e},t,n)=>e.sectors.findIndex(e=>M(e,t,n)),P=({map:e,edges:t},[n,r,i],[a,o,s])=>{let[c,l]=[a-n,s-i];return t.some(t=>{let[a,s]=[t.bx-t.ax,t.bz-t.az],u=c*s-l*a;if(!u)return!1;let d=((t.ax-n)*s-(t.az-i)*a)/u,f=((t.ax-n)*l-(t.az-i)*c)/u;if(d<=0||d>=1||f<0||f>1)return!1;if(t.back<0)return!0;let[p,m]=[e.sectors[t.front],e.sectors[t.back]],h=r+d*(o-r);return h<Math.max(p.floor,m.floor)||h>Math.min(p.ceil,m.ceil)})},F=(e,[t,n,r,i],a,o,s,c,l,u)=>Array.from({length:s},(d,f)=>{let[p,m]=e?[n,i]:[t,r],[h,g,_]=[p+f*(m-p)/s,p+(f+1)*(m-p)/s,+(a+f*o).toFixed(1)];return e?[t,h,r,g,_,c,l,u]:[h,n,g,i,_,c,l,u]}),[I,L,R,z]=[O.HEALTH,O.KEY_RED,O.KEY_BLUE,O.KEY_YELLOW],B=Math.PI/4,V=(e,[t,n,r],i,a,o,s)=>{let c=e.map(([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r]]),l=[...new Map(c.flat().map(e=>[`${e}`,e])).values()];return{sectors:e.map(([,,,,e,t,n=`103`,r],i)=>({pts:c[i].flatMap((e,t,n)=>{let r=n[(t+1)%4],i=t=>(t[0]-e[0])*(r[0]-e[0])+(t[1]-e[1])*(r[1]-e[1]);return[e,...l.filter(t=>(r[0]-e[0])*(t[1]-e[1])===(r[1]-e[1])*(t[0]-e[0])&&i(t)>0&&i(t)<(r[0]-e[0])**2+(r[1]-e[1])**2).sort((e,t)=>i(e)-i(t))]}),floor:e,ceil:t,ft:+n[0],wt:+n[1],ct:+n[2],light:r})),spawns:Array.from({length:16},(e,i)=>[t+i%4*2,n+(i>>2)*2,r*B]),monsters:[...i.map(([e,t,n])=>[e,t,n*B,E.WALKER]),...a.map(([e,t,n])=>[e,t,n*B,E.FLYER])],items:o,gates:e.flatMap(([,,,,,,,,e],t)=>e?[{sector:t,key:e}]:[]),goal:s,exit:0}},re=[V([[0,0,10,10,0,4,`103`],[10,4,22,6,0,2.8,`333`,.6],[22,0,38,14,0,6,`303`],...F(0,[38,4,42,10],.4,.4,4,6,`333`),[42,2,52,12,2,6,`103`,.9],...F(1,[46,12,48,22],1.6,-.4,4,4.8,`000`,.7),[38,22,56,36,0,6,`113`]],[2,2,6],[[28,4,3],[34,10,4],[48,6,4],[44,30,0]],[[30,8,0],[52,28,2]],[[26,12,I],[50,10,I],[40,34,I]],[54,34]),V([[0,14,10,26,0,4,`103`],[10,22,20,24,0,2.8,`333`,.6],[24,8,28,16,0,9,`303`],[20,16,28,30,0,9,`303`],...F(1,[20,8,24,16],2,-.4,5,9,`333`),[28,8,42,18,-1.6,9,`203`,.9],...F(1,[28,18,42,21],-1.2,.4,3,9,`333`),[28,21,50,30,0,9,`303`],[42,8,50,21,0,9,`303`],[20,0,50,8,2.4,9,`103`,.8],[50,14,51,17,0,3.5,`000`,1,L],[51,8,59,26,0,7,`113`,.6],[59,8,67,26,.4,7,`013`,.8],[57,26,59,36,0,4.8,`000`,.7],[50,36,68,50,0,7,`013`]],[2,16,6],[[46,14,2],[36,26,0],[38,4,2],[56,12,4],[62,20,2],[60,44,0]],[[35,13,0],[60,14,4],[58,42,6]],[[24,26,I],[24,4,I],[64,10,I],[52,46,I],[46,4,L]],[66,48]),V([[0,20,10,32,0,4,`103`],[10,26,20,28,0,2.8,`333`,.6],[20,14,56,26,0,11,`133`,.9],[20,26,34,32,0,11,`133`,.9],[34,26,42,32,-.4,11,`233`],[42,26,56,32,0,11,`133`,.9],[20,32,56,44,0,11,`133`,.9],[36,44,38,54,0,1.9,`333`,.45],[30,54,46,68,0,5,`000`,.7],[56,28,57,31,0,4,`000`,1,L],...F(0,[57,26,65,32],.4,.4,8,10,`333`,.8),[65,22,81,36,3.6,11,`103`],[71,36,74,37,3.6,7,`000`,1,R],[71,37,74,48,3.6,6.4,`333`,.6],[62,48,82,64,3.6,10,`213`]],[2,22,6],[[30,18,4],[50,20,4],[30,40,0],[50,40,0],[36,60,2],[42,64,0],[76,28,2],[70,58,0]],[[26,24,0],[48,22,0],[36,40,2],[72,56,4]],[[24,40,I],[52,42,I],[44,57,I],[68,34,I],[64,62,I],[38,66,L],[79,24,R]],[80,62]),V([[0,44,10,56,0,4,`103`],[10,49,20,51,0,2.8,`333`,.6],[20,30,52,40,0,9,`303`],[20,48,52,58,0,9,`303`,.9],[20,40,32,48,0,9,`303`],[40,40,52,48,0,9,`303`],[20,22,49,30,3.2,9,`113`,.8],[34,58,36,66,0,2.8,`333`,.5],[26,66,46,84,0,5,`000`,.5],[52,42,53,45,0,4,`000`,1,L],[53,36,64,54,0,6,`133`,.8],[64,36,70,54,.4,6,`233`,.8],[60,35,63,36,0,4,`000`,1,R],[57,12,77,35,0,8,`013`,.9],[56,24,57,27,0,4,`000`,1,z],...F(0,[49,22,56,30],2.8,-.4,7,9,`333`,.8),[12,24,20,28,3.2,6,`333`,.6],[0,10,12,34,3.2,9,`113`]],[2,46,6],[[30,36,4],[44,36,2],[40,52,0],[40,26,4],[30,74,6],[42,78,2],[56,40,6],[64,50,2],[62,18,4],[72,28,2],[6,22,0]],[[28,48,0],[46,44,4],[36,72,0],[60,45,6],[68,22,4]],[[24,54,I],[24,26,I],[44,80,I],[68,38,I],[74,14,I],[36,82,L],[68,52,R],[74,32,z]],[6,13]),V([[0,60,10,72,0,4,`103`],[10,65,24,67,0,2.8,`333`,.6],[24,48,56,84,0,12,`313`],[27,40,31,48,0,3.4,`000`,.5],[24,16,34,40,0,12,`303`,.9],...F(0,[34,16,40,26],-.4,-.4,3,12,`233`),[34,26,40,30,0,12,`333`],...F(0,[34,30,40,40],-.4,-.4,3,12,`233`),[40,16,60,40,0,12,`303`,.9],[60,27,61,30,0,4,`000`,1,z],[61,10,101,16,0,14,`103`],[61,40,101,46,0,14,`103`],[61,16,69,40,0,14,`103`],[93,16,101,40,0,14,`103`],[69,16,93,20,.4,14,`233`,.9],[69,36,93,40,.4,14,`233`,.9],[69,20,73,36,.4,14,`233`,.9],[89,20,93,36,.4,14,`233`,.9],[73,20,89,36,.8,14,`333`],[101,26,111,28,0,3.2,`333`,.6],[111,16,131,40,0,8,`113`],[56,66,57,69,0,4,`000`,1,L],[57,56,75,80,0,12,`000`,.7],...F(0,[75,60,85,72],.4,.4,5,12,`333`,.8),[85,52,101,80,2.4,12,`013`],[38,84,42,85,0,4,`000`,1,R],[38,85,42,95,0,1.9,`000`,.4],[28,95,56,115,0,6,`030`,.6]],[2,62,6],[[34,56,4],[50,56,2],[36,76,0],[46,20,4],[54,34,2],[66,60,2],[66,76,0],[92,60,2],[34,100,4],[50,108,2],[70,13,4],[92,13,2],[70,43,0],[92,43,6]],[[30,70,0],[46,68,0],[50,28,0],[76,26,0],[86,30,0],[81,22,0]],[[30,80,I],[56,36,I],[60,78,I],[50,112,I],[64,13,I],[98,43,I],[114,38,I],[52,22,L],[95,66,R],[42,110,z]],[127,36])],H=1/60,U=Math.PI*2,ie=1e-6,W=.01,G=e=>(e%U+U)%U,K=e=>[-Math.sin(e),-Math.cos(e)],q=Math.fround,ae=(e,t,n)=>Math.min(Math.max(e,t),n),oe=({map:e,barred:t},n,r,i,a)=>{if(n.back<0||t.has(n.back))return!0;let o=e.sectors[n.front],s=e.sectors[n.back],c=Math.min(o.ceil,s.ceil);return s.floor>r+a+W||c-Math.max(o.floor,s.floor)<i-W||c<r+i-W},se=(e,t,n,r,i)=>{let a=(n-ie)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=ae((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!oe(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},ce=(e,t,n,r,i,a,o)=>{let{map:s,edges:c}=e,l=Math.max(N(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-ie)**2;for(let i of c){if(i.front!==l||i.back<0)continue;let c=i.bx-i.ax,p=i.bz-i.az,m=t-i.ax,h=n-i.az,g=ae((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!oe(e,i,r,a,o)){let e=s.sectors[i.back];u=Math.max(u,e.floor),d=Math.min(d,e.ceil)}}return[u,d]},J=(e,t,n,r,i)=>{e.x+=t,e.z+=n,se(e,i,l,u,p);let[a,o]=ce(i,e.x,e.z,e.y,l,u,p);e.ground&&r&&(e.vy=7);let s=e.vy-20*H;e.y+=(e.vy+s)/2*H,e.vy=s,e.ground=!1,e.y+1.8>o&&(e.y=o-u,e.vy=Math.min(e.vy,0)),(e.vy<=0?e.y<=a+W:e.y<a)&&(e.y=a,e.vy<=0&&(e.vy=0,e.ground=!0)),e.x=q(e.x),e.y=q(e.y),e.z=q(e.z),e.vy=q(e.vy)},le=(e,t,n,r,i)=>{e.x+=t,e.z+=r,se(e,i,y,b,0);let[a,o]=ce(i,e.x,e.z,e.y,y,b,0),s=Math.min(a+x,o-b),c=Math.max(a,Math.min(s,e.y+S*H));e.y=Math.min(Math.max(e.y+n,c),o-b),e.x=q(e.x),e.y=q(e.y),e.z=q(e.z)},ue=(e,t,n)=>{let r=(t.keys&T.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=G(t.yaw),e.pitch=Math.max(-f,Math.min(f,t.pitch));let i=(t.keys&T.FORWARD?1:0)-(t.keys&T.BACK?1:0),a=(t.keys&T.RIGHT?1:0)-(t.keys&T.LEFT?1:0),o=6*H*(r?m:1)/(Math.hypot(i,a)||1),[s,c]=K(e.yaw);return J(e,(s*i-c*a)*o,(c*i+s*a)*o,(t.keys&T.JUMP)!==0,n),r&&!e.cool?(e.cool=5,!0):!1},de=(e,t,n)=>{let{spawns:r,sectors:i}=t.map,[a,o,s]=r[(n%r.length+r.length)%r.length],c=i[Math.max(N(t,a,o),0)].floor;return{id:e,x:q(a),y:q(c),z:q(o),vy:0,yaw:G(s),pitch:0,ground:!0,cool:0}},fe=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},pe=(e,t,n)=>{let[r,i,a,o]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],s=fe(n+1),c=(s&65535)/65536*U,l=(s>>>16)/65535,[u,d]=[Math.cos(c)*l*h,Math.sin(c)*l*h],f=[-r*o+i*u+r*a*d,a+o*d,-i*o-r*u+i*a*d],p=Math.hypot(...f);return[f[0]/p,f[1]/p,f[2]/p]},me=(e,t,n,r)=>{let{map:i,edges:a}=e,o=Math.max(N(e,t[0],t[2]),0),s=0;for(let e=0;e<=i.sectors.length;e++){let{floor:e,ceil:c}=i.sectors[o],l=1/0,u;for(let e of a){if(e.front!==o)continue;let[r,i]=[e.bx-e.ax,e.bz-e.az],a=n[2]*r-n[0]*i;if(a>=0)continue;let c=Math.max(((t[2]-e.az)*r-(t[0]-e.ax)*i)/-a,s),d=((t[0]+c*n[0]-e.ax)*r+(t[2]+c*n[2]-e.az)*i)/(r*r+i*i);d>-1e-9&&d<1+1e-9&&(c<l-1e-9||c<l+1e-9&&e.back<0)&&([l,u]=[c,e])}let d=n[1]<0?(e-t[1])/n[1]:n[1]>0?(c-t[1])/n[1]:1/0;if(d<=l||!u)return Math.min(Math.max(d,s),r);if(l>=r)return r;let f=t[1]+l*n[1],p=u.back<0?void 0:i.sectors[u.back];if(!p||f<Math.max(e,p.floor)||f>Math.min(c,p.ceil))return l;[o,s]=[u.back,l]}return s},he=(e,t,n)=>{let[r,i]=[e[0]-n.x,e[2]-n.z],a=t[0]*t[0]+t[2]*t[2],o=r*t[0]+i*t[2],s=r*r+i*i-n.r*n.r,[c,l]=[0,1/0];if(a>1e-12){let e=o*o-a*s;if(e<0)return 1/0;[c,l]=[Math.max(0,(-o-Math.sqrt(e))/a),(-o+Math.sqrt(e))/a]}else if(s>0)return 1/0;let[u,d]=[n.y-e[1],n.y+n.h-e[1]];if(t[1]){let[e,n]=[u/t[1],d/t[1]];c=Math.max(c,Math.min(e,n)),l=Math.min(l,Math.max(e,n))}else if(u>0||d<0)return 1/0;return c<=l?c:1/0},ge=({id:e,x:t,y:n,z:r})=>({id:e,x:t,y:n,z:r,r:l,h:u}),Y=({id:e,kind:t,x:n,y:r,z:i})=>{let a=t===E.WALKER;return{id:e,x:n,y:r,z:i,r:a?g:y,h:a?_:b}},_e=(e,t,n,r)=>{let i=[t.x,t.y+d,t.z],a=pe(t.yaw,t.pitch,n),o=me(e,i,a,100),s=-1;for(let e of r){let n=e.id===t.id?1/0:he(i,a,e);n<o&&([o,s]=[n,e.id])}return{id:t.id,x:i[0]+a[0]*o,y:i[1]+a[1]*o,z:i[2]+a[2]*o,hit:s}},X=1/60,ve=.05,ye=.4,Z=1,be=15,Q=1.2,xe=255,Se=e=>{let t=e|0;return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}},Ce=(e,t,n=!1)=>{let r=(e.map.monsters??[]).slice(0,64),[i,a]=n?[te,ne]:[1,1],[o,s]=[v*i,S*i],[c,f]=[90,45].map(e=>Math.round(e*a)),m=[],h=[],g=0,_=0,y=r.map(([n,r,i,a],o)=>{let{floor:s,ceil:l}=e.map.sectors[Math.max(N(e,n,r),0)],u=a===E.FLYER;return{id:16+o,kind:a,x:Math.fround(n),y:Math.fround(u?Math.min(s+x,l-b):s),z:Math.fround(r),yaw:G(i),chase:!1,vy:0,ground:!0,target:-1,turn:Math.floor(t()*240),melee:0,swing:0,shoot:Math.floor(t()*c)}}),w=e=>e.y+Y(e).h/2,T=e=>[e.x,e.kind===E.WALKER?e.y+d:w(e),e.z],O=e=>[e.x,e.y+d,e.z],k=(e,t)=>{e.target=t,e.chase=t>=0},A=(t,n)=>{for(let r of y)r!==t&&!r.chase&&Math.hypot(r.x-t.x,r.z-t.z)<12&&!P(e,T(t),T(r))&&k(r,n)},j=(t,n)=>{let[r,i]=K(t.yaw),a,o=1/0;for(let s of n){let[n,c]=[s.x-t.x,s.z-t.z],l=Math.hypot(n,c);l<=30&&l<o&&n*r+c*i>=ee*l&&!P(e,T(t),O(s))&&([a,o]=[s,l])}if(a){let e=!t.chase;k(t,a.id),e&&A(t,a.id)}},M=(e,t)=>{let n=((t-e.yaw+Math.PI)%U+U)%U-Math.PI;e.yaw=G(e.yaw+Math.max(-.05,Math.min(ve,n)))},F=(t,n)=>e.map.sectors[Math.max(N(e,t.x,t.z),0)].floor<n-p,I=n=>{let r=(n.kind===E.WALKER?o:s)*ye*X,[i,a]=K(n.yaw),c={x:n.x,y:n.y,z:n.z,vy:n.vy,ground:n.ground};n.kind===E.WALKER?J(n,i*r,a*r,!1,e):le(n,i*r,-r,a*r,e);let l=n.kind===E.WALKER&&F(n,c.y);l||Math.hypot(n.x-c.x,n.z-c.z)<r/2?(l&&Object.assign(n,c),n.yaw=G(n.yaw+t()*U)):--n.turn<=0&&(n.turn=120+Math.floor(t()*240),n.yaw=G(n.yaw+(t()-.5)*Math.PI))},L=(n,r)=>{let[i,a,o]=T(n);if(m.length>=xe||P(e,[i,a,o],O(r))){n.shoot=0;return}let s=[r.x-i,r.y+Q-a,r.z-o],l=12*X/Math.hypot(...s);m.push({id:_++&255,x:i,y:a,z:o,vx:s[0]*l,vy:s[1]*l,vz:s[2]*l,life:300}),n.shoot=c+Math.floor((t()-.5)*20)},R=(t,n)=>{let[r,i]=[n.x-t.x,n.z-t.z],a=Math.hypot(r,i);if(a>1e-6&&M(t,Math.atan2(-r,-i)),t.kind===E.WALKER){let[n,r]=K(t.yaw),i=a>Z?o*X:0;J(t,n*i,r*i,!1,e)}else{let o=n.y+Q-b/2-t.y,c=Math.min(1,s*X/(Math.hypot(a,o)||1));le(t,a>Z?r*c:0,o*c,a>Z?i*c:0,e)}let c=Math.hypot(n.x-t.x,n.z-t.z)<=1.4&&t.y<n.y+1.8&&n.y<t.y+Y(t).h;if(t.melee=Math.max(0,t.melee-1),t.swing&&!--t.swing&&c){let[e,r]=K(t.yaw);(n.x-t.x)*e+(n.z-t.z)*r>0&&h.push({type:D.HURT,id:n.id,x:n.x,y:n.y+Q,z:n.z})}c&&!t.melee&&(h.push({type:D.SWING,id:t.id,x:t.x,y:w(t),z:t.z}),[t.melee,t.swing]=[f,be]),t.kind===E.WALKER&&t.shoot--<=0&&a<=30&&L(t,n)},z=(t,n)=>{let r=Math.hypot(t.vx,t.vy,t.vz),i=[t.x,t.y,t.z],a=[t.vx/r,t.vy/r,t.vz/r],o=me(e,i,a,r),s=-1;for(let e of n){let t=he(i,a,{id:e.id,x:e.x,y:e.y-C,z:e.z,r:l+C,h:u+2*C});t<o&&([o,s]=[t,e.id])}return[t.x,t.y,t.z]=[i[0]+a[0]*o,i[1]+a[1]*o,i[2]+a[2]*o],s>=0?h.push({type:D.HURT,id:s,x:t.x,y:t.y,z:t.z}):o<r&&h.push({type:D.BOOM,id:t.id,x:t.x,y:t.y,z:t.z}),s<0&&o>=r&&--t.life>0};return{monsters:()=>y.map(({id:e,kind:t,x:n,y:r,z:i,yaw:a,chase:o})=>({id:e,kind:t,x:n,y:r,z:i,yaw:a,chase:o})),bullets:()=>m.map(({id:e,x:t,y:n,z:r})=>({id:e,x:t,y:n,z:r})),events:h,step:e=>{g++;for(let t of y){(g+t.id)%60==0&&j(t,e);let n=e.find(e=>e.id===t.target);t.chase&&!n&&k(t,-1),n?R(t,n):I(t)}m=m.filter(t=>z(t,e))},kill:(e,t)=>{let n=y.findIndex(t=>t.id===e);if(n<0)return;let[r]=y.splice(n,1);return h.push({type:D.DIE,id:e,x:r.x,y:w(r),z:r.z}),A(r,t),r}}},we=20,Te=.5,Ee=2,$=[`#e6194b`,`#3cb44b`,`#ffe119`,`#4363d8`,`#f58231`,`#911eb4`,`#42d4f4`,`#f032e6`,`#bfef45`,`#fabed4`,`#469990`,`#dcbeff`,`#9a6324`,`#800000`,`#aaffc3`,`#808000`],De=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),Oe=e=>De((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),ke=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${De(e,15-`${r}`.length)} ${r}`;return n},Ae=(e,t,n,r,i)=>Math.hypot(e.x-t,e.z-r)<=i&&e.y<n+Te&&n<e.y+1.8,je=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},Me=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];maps;lvl;horde;rand;level=0;hard=!1;phase=k.HUNT;keys=0;items=[];nextItem=0;kills=0;runStart=0;shots=[];halt;rules;rr=0;constructor(e={},t=Date.now(),n=re){this.rules={...w,...e},this.rand=Se(t),this.maps=n.map(A),this.load(0)}get size(){return this.players().length}connect(e){this.peers.set(e,null)}receive(e,t){let n=this.peers.get(e);if(typeof t==`string`){let r=c(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&o(t);if(r&&n.bank>0){if(n.bank--,n.hp&&ue(n.state,r,this.lvl)){let e=_e(this.lvl,n.state,r.seq,this.rewind(n,r.view));if(this.shots.push(e),e.hit>=16){let t=this.horde.kill(e.hit,n.state.id);t&&++this.kills%4==0&&this.drop(O.HEALTH,t.x,t.z)}}n.ack=r.seq}}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&this.roster()}tick(){let e=this.players();if(!e.length)return;let t=++this.ticks;for(let n of e)n.bank=Math.min(10,n.bank+1),!n.hp&&t-n.hurt>=180&&(n.hp=9,n.state=this.place(n.info.id,e.filter(e=>e.hp&&e!==n).map(e=>e.state)));let{events:n}=this.horde,r=n.length;if(this.horde.step(e.filter(e=>e.hp).map(e=>e.state)),n.push(...n.splice(r).filter(e=>e.type!==D.HURT||this.wound(e.id,t))),this.progress(e.filter(e=>e.hp)),t%2==0){let n=this.horde.monsters();for(this.history.push({tick:t,players:e.map(e=>({...e.state})),monsters:n});this.history[0].tick<t-30;)this.history.shift();let r=s({tick:t,players:e.map(e=>({...e.state,ack:e.ack,hp:e.hp})),shots:this.shots,monsters:n,bullets:this.horde.bullets(),events:this.horde.events.splice(0,255),level:this.level,hard:this.hard,phase:this.phase,keys:this.keys,items:this.items});this.shots=[],e.forEach(e=>e.conn.send(r))}}start(e=je){if(this.halt)return;let t=1e3/60,n=performance.now(),r=0;this.halt=e(()=>{let e=performance.now();r+=e-n,n=e;for(let e=0;r>=t&&e<we;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){let n=this.players().filter(t=>t!==e&&t.hp).map(e=>e.state),r=this.horde.monsters(),[i,a]=[this.history[0],this.history.at(-1)];if(!i||!a)return[...n.map(ge),...r.map(Y)];let o=((this.ticks-t+32768)%65536+65536)%65536-32768,s=Math.min(Math.max(this.ticks-o,i.tick),a.tick),c=0;for(;c+1<this.history.length&&this.history[c+1].tick<=s;)c++;let[l,u]=[this.history[c],this.history[c+1]??this.history[c]],d=u.tick>l.tick?(s-l.tick)/(u.tick-l.tick):0,f=(e,t)=>e+(t-e)*d,p=(e,t)=>e.map(e=>{let n=t(l).find(t=>t.id===e.id),r=t(u).find(t=>t.id===e.id);return n&&r?{...r,x:f(n.x,r.x),y:f(n.y,r.y),z:f(n.z,r.z)}:r??n??e});return[...p(n,e=>e.players).map(ge),...p(r,e=>e.monsters).map(Y)]}load(e){this.level=e,this.lvl=this.maps[e],this.keys=0,this.phase=k.HUNT,j(this.lvl,0,k.HUNT),this.horde=Ce(this.lvl,this.rand,this.hard),this.items=[],this.nextItem=0,this.kills=0,this.lvl.map.items?.forEach(([e,t,n])=>this.drop(n,e,t)),this.shots=[],this.history=[];let t=[];for(let e of this.players())e.hp=9,e.state=this.place(e.info.id,t),t.push(e.state)}place(e,t){let n=this.lvl.map.spawns.findIndex((n,r)=>{let{x:i,z:a}=de(e,this.lvl,r);return!t.some(e=>Math.hypot(e.x-i,e.z-a)<Ee)});return de(e,this.lvl,n<0?this.rr++:n)}floor(e,t){return this.lvl.map.sectors[Math.max(N(this.lvl,e,t),0)].floor}drop(e,t,n){let r=Math.fround;this.items.push({id:this.nextItem++,kind:e,x:r(t),y:r(this.floor(t,n)),z:r(n)})}wound(e,t){let n=this.players().find(t=>t.info.id===e);return!n?.hp||t-n.hurt<60?!1:([n.hp,n.hurt]=[n.hp-1,t],!0)}progress(e){let{sectors:t,goal:n,exit:r}=this.lvl.map,i=!1;if(this.items=this.items.filter(t=>{let n=e.find(e=>Ae(e.state,t.x,t.y,t.z,.8)&&(t.kind!==O.HEALTH||e.hp<9));return n&&t.kind===O.HEALTH?n.hp=Math.min(9,n.hp+3):n&&(this.keys|=1<<t.kind,i=!0),!n}),this.phase===k.HUNT)n&&e.some(e=>Ae(e.state,n[0],this.floor(...n),n[1],1))&&(this.phase=k.RETURN,i=!0);else if(r!==void 0&&e.length&&e.every(e=>M(t[r],e.state.x,e.state.z)))return this.win();i&&j(this.lvl,this.keys,this.phase)}win(){if(this.level+1<this.maps.length){this.load(this.level+1);return}let e=JSON.stringify({t:`end`,ticks:this.ticks-this.runStart,hard:this.hard});this.players().forEach(t=>t.conn.send(e)),[this.hard,this.runStart]=[!0,this.ticks],this.load(0)}players(){return[...this.peers.values()].filter(e=>e!==null)}join(e,t){let n=this.players();if(n.length>=this.rules.maxPlayers){e.send(JSON.stringify({t:`full`}));return}let r=0;for(;n.some(e=>e.info.id===r);)r++;let i=$.find(e=>!n.some(t=>t.info.color===e))??$[r%$.length],a={conn:e,info:{id:r,name:ke(Oe(t)||`Player ${r}`,n.map(e=>e.info.name)),color:i},state:this.place(r,n.filter(e=>e.hp).map(e=>e.state)),bank:10,ack:65535,hp:9,hurt:-60};this.peers.set(e,a),this.roster()}roster(){let e=this.players(),t=e.map(e=>e.info).sort((e,t)=>e.id-t.id);e.forEach(e=>e.conn.send(JSON.stringify({t:`roster`,you:e.info.id,players:t})))}},Ne=(e,t)=>{let n=()=>{},r=()=>{n();let r=setInterval(e,t);n=()=>clearInterval(r)};try{let i=URL.createObjectURL(new Blob([`setInterval(()=>postMessage(0),${t})`])),a=new Worker(i);a.onmessage=e,a.onerror=r,n=()=>{a.terminate(),URL.revokeObjectURL(i)}}catch{r()}return()=>n()},Pe=(e,t)=>{let n=`tiny-fps:`+e,r=Math.random().toString(36).slice(2),i=new BroadcastChannel(n),a=new AbortController,o=globalThis.navigator?.locks,s,l,u,d,f=[],p,m=!1,h=e=>i.postMessage({from:r,...e}),g=e=>!m&&S.onmessage?.({data:e}),_={send:e=>queueMicrotask(()=>g(e))},v=()=>{let e=f.length?f:p?[p]:[];return f=[],e},y=e=>{if(m)return e();u=e,d=r,l=/* @__PURE__ */ new Map,s=new Me(t),s.start(Ne),s.connect(_),v().forEach(e=>s.receive(_,e)),h({kind:`h`})};i.onmessage=({data:e})=>{if(!m){if(s&&l){let{from:t,kind:n}=e,r=l.get(t);n===`q`?h({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!m&&h({to:t,kind:`m`,data:e})},l.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(l.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?g(e.data):e.kind===`h`&&e.from!==d&&(d=e.from,v().forEach(e=>h({kind:`m`,data:e}))))}};let b=e=>{m||(typeof e==`string`&&c(e)?.t===`join`&&(p=e),s?s.receive(_,e):d?h({kind:`m`,data:e}):f.push(e))},x=()=>{m||(m=!0,globalThis.removeEventListener?.(`pagehide`,x),s?(s.stop(),u()):(h({kind:`b`}),a.abort()),i.close(),setTimeout(()=>S.onclose?.()))},S={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:b,close:x};return o?o.request(n,{signal:a.signal},()=>new Promise(y)).catch(()=>{}):y(()=>{}),h({kind:`q`}),globalThis.addEventListener?.(`pagehide`,x),setTimeout(()=>!m&&S.onopen?.()),S};export{Pe as localSocket};
|
|
1
|
+
var e=65536/(2*Math.PI),t=t=>Math.round(t*e)&65535,n=e=>Math.max(-32768,Math.min(32767,Math.round(e))),r=e=>n(e*1e4),i=e=>e/1e4,a=t=>t/e,o=e=>{if(e.byteLength!==11)return null;let t=new DataView(e);return t.getUint8(0)===1?{seq:t.getUint16(1),keys:t.getUint8(3),yaw:a(t.getUint16(4)),pitch:i(t.getInt16(6)),view:(t.getUint16(8)*256+t.getUint8(10))/256}:null},s=e=>{let n=7+25*e.players.length,i=n+1+14*e.shots.length,a=i+1+16*e.monsters.length,o=a+1+13*e.bullets.length,s=o+1+14*e.events.length,c=new DataView(new ArrayBuffer(s+1+14*e.items.length));return c.setUint8(0,2),c.setUint16(1,e.tick&65535),c.setUint8(3,e.players.length),c.setUint8(4,e.level),c.setUint8(5,+e.hard|(e.phase&1)<<1),c.setUint8(6,e.keys),e.players.forEach((e,n)=>{let i=7+n*25;c.setUint8(i,e.id),c.setFloat32(i+1,e.x),c.setFloat32(i+5,e.y),c.setFloat32(i+9,e.z),c.setFloat32(i+13,e.vy),c.setUint16(i+17,t(e.yaw)),c.setInt16(i+19,r(e.pitch)),c.setUint16(i+21,e.ack&65535),c.setUint8(i+23,+e.ground|e.cool<<1),c.setUint8(i+24,e.hp)}),c.setUint8(n,e.shots.length),e.shots.forEach((e,t)=>{let r=n+1+t*14;c.setUint8(r,e.id),c.setFloat32(r+1,e.x),c.setFloat32(r+5,e.y),c.setFloat32(r+9,e.z),c.setUint8(r+13,e.hit&255)}),c.setUint8(i,e.monsters.length),e.monsters.forEach((e,n)=>{let r=i+1+n*16;c.setUint8(r,e.id),c.setUint8(r+1,e.kind&1|e.chase<<1),c.setFloat32(r+2,e.x),c.setFloat32(r+6,e.y),c.setFloat32(r+10,e.z),c.setUint16(r+14,t(e.yaw))}),c.setUint8(a,e.bullets.length),e.bullets.forEach((e,t)=>{let n=a+1+t*13;c.setUint8(n,e.id),c.setFloat32(n+1,e.x),c.setFloat32(n+5,e.y),c.setFloat32(n+9,e.z)}),c.setUint8(o,e.events.length),e.events.forEach((e,t)=>{let n=o+1+t*14;c.setUint8(n,e.type),c.setUint8(n+1,e.id),c.setFloat32(n+2,e.x),c.setFloat32(n+6,e.y),c.setFloat32(n+10,e.z)}),c.setUint8(s,e.items.length),e.items.forEach((e,t)=>{let n=s+1+t*14;c.setUint8(n,e.id),c.setUint8(n+1,e.kind),c.setFloat32(n+2,e.x),c.setFloat32(n+6,e.y),c.setFloat32(n+10,e.z)}),c.buffer},c=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},l=.4,u=1.8,d=1.6,f=1.55,p=.5,m=.5,h=.02,g=.4,_=1.8,v=2.5,y=.45,b=.9,x=1.2,S=3.5,ee=Math.cos(Math.PI/6),C=.15,te=1.3,ne=.6,w={maxPlayers:16},T={FORWARD:1,BACK:2,LEFT:4,RIGHT:8,JUMP:16,FIRE:32},E={WALKER:0,FLYER:1},D={DIE:0,HURT:1,BOOM:2,SWING:3},O={HEALTH:0,KEY_RED:1,KEY_BLUE:2,KEY_YELLOW:3},k={HUNT:0,RETURN:1},A=e=>{let t=(e,t,n,r)=>`${e},${t},${n},${r}`,n=/* @__PURE__ */ new Map;e.sectors.forEach(({pts:e},r)=>e.forEach(([i,a],o)=>n.set(t(i,a,...e[(o+1)%e.length]),r)));let r={map:e,edges:e.sectors.flatMap(({pts:e},r)=>e.map(([i,a],o)=>{let[s,c]=e[(o+1)%e.length];return{ax:i,az:a,bx:s,bz:c,front:r,back:n.get(t(s,c,i,a))??-1}})),barred:/* @__PURE__ */ new Set};return j(r,0,k.HUNT),r},j=({map:e,barred:t},n,r)=>{t.clear(),e.gates?.forEach(e=>n&1<<e.key||t.add(e.sector)),e.exit!==void 0&&r===k.HUNT&&t.add(e.exit)},M=({pts:e},t,n)=>e.every(([r,i],a)=>{let[o,s]=e[(a+1)%e.length];return(o-r)*(n-i)-(s-i)*(t-r)>=0}),N=({map:e},t,n)=>e.sectors.findIndex(e=>M(e,t,n)),P=({map:e,edges:t},[n,r,i],[a,o,s])=>{let[c,l]=[a-n,s-i];return t.some(t=>{let[a,s]=[t.bx-t.ax,t.bz-t.az],u=c*s-l*a;if(!u)return!1;let d=((t.ax-n)*s-(t.az-i)*a)/u,f=((t.ax-n)*l-(t.az-i)*c)/u;if(d<=0||d>=1||f<0||f>1)return!1;if(t.back<0)return!0;let[p,m]=[e.sectors[t.front],e.sectors[t.back]],h=r+d*(o-r);return h<Math.max(p.floor,m.floor)||h>Math.min(p.ceil,m.ceil)})},F=(e,[t,n,r,i],a,o,s,c,l,u)=>Array.from({length:s},(d,f)=>{let[p,m]=e?[n,i]:[t,r],[h,g,_]=[p+f*(m-p)/s,p+(f+1)*(m-p)/s,+(a+f*o).toFixed(1)];return e?[t,h,r,g,_,c,l,u]:[h,n,g,i,_,c,l,u]}),[I,L,R,z]=[O.HEALTH,O.KEY_RED,O.KEY_BLUE,O.KEY_YELLOW],B=Math.PI/4,V=(e,t,[n,r,i],a,o,s,c)=>{let l=t.map(([e,t,n,r])=>[[e,t],[n,t],[n,r],[e,r]]),u=[...new Map(l.flat().map(e=>[`${e}`,e])).values()];return{name:e,sectors:t.map(([,,,,e,t,n=`103`,r],i)=>({pts:l[i].flatMap((e,t,n)=>{let r=n[(t+1)%4],i=t=>(t[0]-e[0])*(r[0]-e[0])+(t[1]-e[1])*(r[1]-e[1]);return[e,...u.filter(t=>(r[0]-e[0])*(t[1]-e[1])===(r[1]-e[1])*(t[0]-e[0])&&i(t)>0&&i(t)<(r[0]-e[0])**2+(r[1]-e[1])**2).sort((e,t)=>i(e)-i(t))]}),floor:e,ceil:t,ft:+n[0],wt:+n[1],ct:+n[2],light:r})),spawns:Array.from({length:16},(e,t)=>[n+t%4*2,r+(t>>2)*2,i*B]),monsters:[...a.map(([e,t,n])=>[e,t,n*B,E.WALKER]),...o.map(([e,t,n])=>[e,t,n*B,E.FLYER])],items:s,gates:t.flatMap(([,,,,,,,,e],t)=>e?[{sector:t,key:e}]:[]),goal:c,exit:0}},re=[V(`Warm-up`,[[0,0,10,10,0,4,`103`],[10,4,22,6,0,2.8,`333`,.6],[22,0,38,14,0,6,`303`],...F(0,[38,4,42,10],.4,.4,4,6,`333`),[42,2,52,12,2,6,`103`,.9],...F(1,[46,12,48,22],1.6,-.4,4,4.8,`000`,.7),[38,22,56,36,0,6,`113`]],[2,2,6],[[28,4,3],[34,10,4],[48,6,4],[44,30,0]],[[30,8,0],[52,28,2]],[[26,12,I],[50,10,I],[40,34,I]],[54,34]),V(`Foundry`,[[0,14,10,26,0,4,`103`],[10,22,20,24,0,2.8,`333`,.6],[24,8,28,16,0,9,`303`],[20,16,28,30,0,9,`303`],...F(1,[20,8,24,16],2,-.4,5,9,`333`),[28,8,42,18,-1.6,9,`203`,.9],...F(1,[28,18,42,21],-1.2,.4,3,9,`333`),[28,21,50,30,0,9,`303`],[42,8,50,21,0,9,`303`],[20,0,50,8,2.4,9,`103`,.8],[50,14,51,17,0,3.5,`000`,1,L],[51,8,59,26,0,7,`113`,.6],[59,8,67,26,.4,7,`013`,.8],[57,26,59,36,0,4.8,`000`,.7],[50,36,68,50,0,7,`013`]],[2,16,6],[[46,14,2],[36,26,0],[38,4,2],[56,12,4],[62,20,2],[60,44,0]],[[35,13,0],[60,14,4],[58,42,6]],[[24,26,I],[24,4,I],[64,10,I],[52,46,I],[46,4,L]],[66,48]),V(`Cistern`,[[0,20,10,32,0,4,`103`],[10,26,20,28,0,2.8,`333`,.6],[20,14,56,26,0,11,`133`,.9],[20,26,34,32,0,11,`133`,.9],[34,26,42,32,-.4,11,`233`],[42,26,56,32,0,11,`133`,.9],[20,32,56,44,0,11,`133`,.9],[36,44,38,54,0,1.9,`333`,.45],[30,54,46,68,0,5,`000`,.7],[56,28,57,31,0,4,`000`,1,L],...F(0,[57,26,65,32],.4,.4,8,10,`333`,.8),[65,22,81,36,3.6,11,`103`],[71,36,74,37,3.6,7,`000`,1,R],[71,37,74,48,3.6,6.4,`333`,.6],[62,48,82,64,3.6,10,`213`]],[2,22,6],[[30,18,4],[50,20,4],[30,40,0],[50,40,0],[36,60,2],[42,64,0],[76,28,2],[70,58,0]],[[26,24,0],[48,22,0],[36,40,2],[72,56,4]],[[24,40,I],[52,42,I],[44,57,I],[68,34,I],[64,62,I],[38,66,L],[79,24,R]],[80,62]),V(`Loop`,[[0,44,10,56,0,4,`103`],[10,49,20,51,0,2.8,`333`,.6],[20,30,52,40,0,9,`303`],[20,48,52,58,0,9,`303`,.9],[20,40,32,48,0,9,`303`],[40,40,52,48,0,9,`303`],[20,22,49,30,3.2,9,`113`,.8],[34,58,36,66,0,2.8,`333`,.5],[26,66,46,84,0,5,`000`,.5],[52,42,53,45,0,4,`000`,1,L],[53,36,64,54,0,6,`133`,.8],[64,36,70,54,.4,6,`233`,.8],[60,35,63,36,0,4,`000`,1,R],[57,12,77,35,0,8,`013`,.9],[56,24,57,27,0,4,`000`,1,z],...F(0,[49,22,56,30],2.8,-.4,7,9,`333`,.8),[12,24,20,28,3.2,6,`333`,.6],[0,10,12,34,3.2,9,`113`]],[2,46,6],[[30,36,4],[44,36,2],[40,52,0],[40,26,4],[30,74,6],[42,78,2],[56,40,6],[64,50,2],[62,18,4],[72,28,2],[6,22,0]],[[28,48,0],[46,44,4],[36,72,0],[60,45,6],[68,22,4]],[[24,54,I],[24,26,I],[44,80,I],[68,38,I],[74,14,I],[36,82,L],[68,52,R],[74,32,z]],[6,13]),V(`Citadel`,[[0,60,10,72,0,4,`103`],[10,65,24,67,0,2.8,`333`,.6],[24,48,56,84,0,12,`313`],[27,40,31,48,0,3.4,`000`,.5],[24,16,34,40,0,12,`303`,.9],...F(0,[34,16,40,26],-.4,-.4,3,12,`233`),[34,26,40,30,0,12,`333`],...F(0,[34,30,40,40],-.4,-.4,3,12,`233`),[40,16,60,40,0,12,`303`,.9],[60,27,61,30,0,4,`000`,1,z],[61,10,101,16,0,14,`103`],[61,40,101,46,0,14,`103`],[61,16,69,40,0,14,`103`],[93,16,101,40,0,14,`103`],[69,16,93,20,.4,14,`233`,.9],[69,36,93,40,.4,14,`233`,.9],[69,20,73,36,.4,14,`233`,.9],[89,20,93,36,.4,14,`233`,.9],[73,20,89,36,.8,14,`333`],[101,26,111,28,0,3.2,`333`,.6],[111,16,131,40,0,8,`113`],[56,66,57,69,0,4,`000`,1,L],[57,56,75,80,0,12,`000`,.7],...F(0,[75,60,85,72],.4,.4,5,12,`333`,.8),[85,52,101,80,2.4,12,`013`],[38,84,42,85,0,4,`000`,1,R],[38,85,42,95,0,1.9,`000`,.4],[28,95,56,115,0,6,`030`,.6]],[2,62,6],[[34,56,4],[50,56,2],[36,76,0],[46,20,4],[54,34,2],[66,60,2],[66,76,0],[92,60,2],[34,100,4],[50,108,2],[70,13,4],[92,13,2],[70,43,0],[92,43,6]],[[30,70,0],[46,68,0],[50,28,0],[76,26,0],[86,30,0],[81,22,0]],[[30,80,I],[56,36,I],[60,78,I],[50,112,I],[64,13,I],[98,43,I],[114,38,I],[52,22,L],[95,66,R],[42,110,z]],[127,36])],H=1/60,U=Math.PI*2,ie=1e-6,W=.01,G=e=>(e%U+U)%U,K=e=>[-Math.sin(e),-Math.cos(e)],q=Math.fround,ae=(e,t,n)=>Math.min(Math.max(e,t),n),oe=({map:e,barred:t},n,r,i,a)=>{if(n.back<0||t.has(n.back))return!0;let o=e.sectors[n.front],s=e.sectors[n.back],c=Math.min(o.ceil,s.ceil);return s.floor>r+a+W||c-Math.max(o.floor,s.floor)<i-W||c<r+i-W},se=(e,t,n,r,i)=>{let a=(n-ie)**2;for(let o=0;o<4;o++){let o=0,s=0,c=0;for(let l of t.edges){let u=l.bx-l.ax,d=l.bz-l.az,f=e.x-l.ax,p=e.z-l.az;if(u*p-d*f<0)continue;let m=ae((f*u+p*d)/(u*u+d*d),0,1),h=f-m*u,g=p-m*d,_=h*h+g*g;if(_>=a)continue;let v=Math.sqrt(_);if(n-v<=o||!oe(t,l,e.y,r,i))continue;o=n-v;let y=v||Math.hypot(u,d);s=(v?h:-d)/y*o,c=(v?g:u)/y*o}if(!o)return;e.x+=s,e.z+=c}},ce=(e,t,n,r,i,a,o)=>{let{map:s,edges:c}=e,l=Math.max(N(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-ie)**2;for(let i of c){if(i.front!==l||i.back<0)continue;let c=i.bx-i.ax,p=i.bz-i.az,m=t-i.ax,h=n-i.az,g=ae((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!oe(e,i,r,a,o)){let e=s.sectors[i.back];u=Math.max(u,e.floor),d=Math.min(d,e.ceil)}}return[u,d]},J=(e,t,n,r,i)=>{e.x+=t,e.z+=n,se(e,i,l,u,p);let[a,o]=ce(i,e.x,e.z,e.y,l,u,p);e.ground&&r&&(e.vy=7);let s=e.vy-20*H;e.y+=(e.vy+s)/2*H,e.vy=s,e.ground=!1,e.y+1.8>o&&(e.y=o-u,e.vy=Math.min(e.vy,0)),(e.vy<=0?e.y<=a+W:e.y<a)&&(e.y=a,e.vy<=0&&(e.vy=0,e.ground=!0)),e.x=q(e.x),e.y=q(e.y),e.z=q(e.z),e.vy=q(e.vy)},le=(e,t,n,r,i)=>{e.x+=t,e.z+=r,se(e,i,y,b,0);let[a,o]=ce(i,e.x,e.z,e.y,y,b,0),s=Math.min(a+x,o-b),c=Math.max(a,Math.min(s,e.y+S*H));e.y=Math.min(Math.max(e.y+n,c),o-b),e.x=q(e.x),e.y=q(e.y),e.z=q(e.z)},ue=(e,t,n)=>{let r=(t.keys&T.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=G(t.yaw),e.pitch=Math.max(-f,Math.min(f,t.pitch));let i=(t.keys&T.FORWARD?1:0)-(t.keys&T.BACK?1:0),a=(t.keys&T.RIGHT?1:0)-(t.keys&T.LEFT?1:0),o=6*H*(r?m:1)/(Math.hypot(i,a)||1),[s,c]=K(e.yaw);return J(e,(s*i-c*a)*o,(c*i+s*a)*o,(t.keys&T.JUMP)!==0,n),r&&!e.cool?(e.cool=5,!0):!1},de=(e,t,n)=>{let{spawns:r,sectors:i}=t.map,[a,o,s]=r[(n%r.length+r.length)%r.length],c=i[Math.max(N(t,a,o),0)].floor;return{id:e,x:q(a),y:q(c),z:q(o),vy:0,yaw:G(s),pitch:0,ground:!0,cool:0}},fe=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},pe=(e,t,n)=>{let[r,i,a,o]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],s=fe(n+1),c=(s&65535)/65536*U,l=(s>>>16)/65535,[u,d]=[Math.cos(c)*l*h,Math.sin(c)*l*h],f=[-r*o+i*u+r*a*d,a+o*d,-i*o-r*u+i*a*d],p=Math.hypot(...f);return[f[0]/p,f[1]/p,f[2]/p]},me=(e,t,n,r)=>{let{map:i,edges:a}=e,o=Math.max(N(e,t[0],t[2]),0),s=0;for(let e=0;e<=i.sectors.length;e++){let{floor:e,ceil:c}=i.sectors[o],l=1/0,u;for(let e of a){if(e.front!==o)continue;let[r,i]=[e.bx-e.ax,e.bz-e.az],a=n[2]*r-n[0]*i;if(a>=0)continue;let c=Math.max(((t[2]-e.az)*r-(t[0]-e.ax)*i)/-a,s),d=((t[0]+c*n[0]-e.ax)*r+(t[2]+c*n[2]-e.az)*i)/(r*r+i*i);d>-1e-9&&d<1+1e-9&&(c<l-1e-9||c<l+1e-9&&e.back<0)&&([l,u]=[c,e])}let d=n[1]<0?(e-t[1])/n[1]:n[1]>0?(c-t[1])/n[1]:1/0;if(d<=l||!u)return Math.min(Math.max(d,s),r);if(l>=r)return r;let f=t[1]+l*n[1],p=u.back<0?void 0:i.sectors[u.back];if(!p||f<Math.max(e,p.floor)||f>Math.min(c,p.ceil))return l;[o,s]=[u.back,l]}return s},he=(e,t,n)=>{let[r,i]=[e[0]-n.x,e[2]-n.z],a=t[0]*t[0]+t[2]*t[2],o=r*t[0]+i*t[2],s=r*r+i*i-n.r*n.r,[c,l]=[0,1/0];if(a>1e-12){let e=o*o-a*s;if(e<0)return 1/0;[c,l]=[Math.max(0,(-o-Math.sqrt(e))/a),(-o+Math.sqrt(e))/a]}else if(s>0)return 1/0;let[u,d]=[n.y-e[1],n.y+n.h-e[1]];if(t[1]){let[e,n]=[u/t[1],d/t[1]];c=Math.max(c,Math.min(e,n)),l=Math.min(l,Math.max(e,n))}else if(u>0||d<0)return 1/0;return c<=l?c:1/0},ge=({id:e,x:t,y:n,z:r})=>({id:e,x:t,y:n,z:r,r:l,h:u}),Y=({id:e,kind:t,x:n,y:r,z:i})=>{let a=t===E.WALKER;return{id:e,x:n,y:r,z:i,r:a?g:y,h:a?_:b}},_e=(e,t,n,r)=>{let i=[t.x,t.y+d,t.z],a=pe(t.yaw,t.pitch,n),o=me(e,i,a,100),s=-1;for(let e of r){let n=e.id===t.id?1/0:he(i,a,e);n<o&&([o,s]=[n,e.id])}return{id:t.id,x:i[0]+a[0]*o,y:i[1]+a[1]*o,z:i[2]+a[2]*o,hit:s}},X=1/60,ve=.05,ye=.4,Z=1,be=15,Q=1.2,xe=255,Se=e=>{let t=e|0;return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}},Ce=(e,t,n=!1)=>{let r=(e.map.monsters??[]).slice(0,64),[i,a]=n?[te,ne]:[1,1],[o,s]=[v*i,S*i],[c,f]=[90,45].map(e=>Math.round(e*a)),m=[],h=[],g=0,_=0,y=r.map(([n,r,i,a],o)=>{let{floor:s,ceil:l}=e.map.sectors[Math.max(N(e,n,r),0)],u=a===E.FLYER;return{id:16+o,kind:a,x:Math.fround(n),y:Math.fround(u?Math.min(s+x,l-b):s),z:Math.fround(r),yaw:G(i),chase:!1,vy:0,ground:!0,target:-1,turn:Math.floor(t()*240),melee:0,swing:0,shoot:Math.floor(t()*c)}}),w=e=>e.y+Y(e).h/2,T=e=>[e.x,e.kind===E.WALKER?e.y+d:w(e),e.z],O=e=>[e.x,e.y+d,e.z],k=(e,t)=>{e.target=t,e.chase=t>=0},A=(t,n)=>{for(let r of y)r!==t&&!r.chase&&Math.hypot(r.x-t.x,r.z-t.z)<12&&!P(e,T(t),T(r))&&k(r,n)},j=(t,n)=>{let[r,i]=K(t.yaw),a,o=1/0;for(let s of n){let[n,c]=[s.x-t.x,s.z-t.z],l=Math.hypot(n,c);l<=30&&l<o&&n*r+c*i>=ee*l&&!P(e,T(t),O(s))&&([a,o]=[s,l])}if(a){let e=!t.chase;k(t,a.id),e&&A(t,a.id)}},M=(e,t)=>{let n=((t-e.yaw+Math.PI)%U+U)%U-Math.PI;e.yaw=G(e.yaw+Math.max(-.05,Math.min(ve,n)))},F=(t,n)=>e.map.sectors[Math.max(N(e,t.x,t.z),0)].floor<n-p,I=n=>{let r=(n.kind===E.WALKER?o:s)*ye*X,[i,a]=K(n.yaw),c={x:n.x,y:n.y,z:n.z,vy:n.vy,ground:n.ground};n.kind===E.WALKER?J(n,i*r,a*r,!1,e):le(n,i*r,-r,a*r,e);let l=n.kind===E.WALKER&&F(n,c.y);l||Math.hypot(n.x-c.x,n.z-c.z)<r/2?(l&&Object.assign(n,c),n.yaw=G(n.yaw+t()*U)):--n.turn<=0&&(n.turn=120+Math.floor(t()*240),n.yaw=G(n.yaw+(t()-.5)*Math.PI))},L=(n,r)=>{let[i,a,o]=T(n);if(m.length>=xe||P(e,[i,a,o],O(r))){n.shoot=0;return}let s=[r.x-i,r.y+Q-a,r.z-o],l=12*X/Math.hypot(...s);m.push({id:_++&255,x:i,y:a,z:o,vx:s[0]*l,vy:s[1]*l,vz:s[2]*l,life:300}),n.shoot=c+Math.floor((t()-.5)*20)},R=(t,n)=>{let[r,i]=[n.x-t.x,n.z-t.z],a=Math.hypot(r,i);if(a>1e-6&&M(t,Math.atan2(-r,-i)),t.kind===E.WALKER){let[n,r]=K(t.yaw),i=a>Z?o*X:0;J(t,n*i,r*i,!1,e)}else{let o=n.y+Q-b/2-t.y,c=Math.min(1,s*X/(Math.hypot(a,o)||1));le(t,a>Z?r*c:0,o*c,a>Z?i*c:0,e)}let c=Math.hypot(n.x-t.x,n.z-t.z)<=1.4&&t.y<n.y+1.8&&n.y<t.y+Y(t).h;if(t.melee=Math.max(0,t.melee-1),t.swing&&!--t.swing&&c){let[e,r]=K(t.yaw);(n.x-t.x)*e+(n.z-t.z)*r>0&&h.push({type:D.HURT,id:n.id,x:n.x,y:n.y+Q,z:n.z})}c&&!t.melee&&(h.push({type:D.SWING,id:t.id,x:t.x,y:w(t),z:t.z}),[t.melee,t.swing]=[f,be]),t.kind===E.WALKER&&t.shoot--<=0&&a<=30&&L(t,n)},z=(t,n)=>{let r=Math.hypot(t.vx,t.vy,t.vz),i=[t.x,t.y,t.z],a=[t.vx/r,t.vy/r,t.vz/r],o=me(e,i,a,r),s=-1;for(let e of n){let t=he(i,a,{id:e.id,x:e.x,y:e.y-C,z:e.z,r:l+C,h:u+2*C});t<o&&([o,s]=[t,e.id])}return[t.x,t.y,t.z]=[i[0]+a[0]*o,i[1]+a[1]*o,i[2]+a[2]*o],s>=0?h.push({type:D.HURT,id:s,x:t.x,y:t.y,z:t.z}):o<r&&h.push({type:D.BOOM,id:t.id,x:t.x,y:t.y,z:t.z}),s<0&&o>=r&&--t.life>0};return{monsters:()=>y.map(({id:e,kind:t,x:n,y:r,z:i,yaw:a,chase:o})=>({id:e,kind:t,x:n,y:r,z:i,yaw:a,chase:o})),bullets:()=>m.map(({id:e,x:t,y:n,z:r})=>({id:e,x:t,y:n,z:r})),events:h,step:e=>{g++;for(let t of y){(g+t.id)%60==0&&j(t,e);let n=e.find(e=>e.id===t.target);t.chase&&!n&&k(t,-1),n?R(t,n):I(t)}m=m.filter(t=>z(t,e))},kill:(e,t)=>{let n=y.findIndex(t=>t.id===e);if(n<0)return;let[r]=y.splice(n,1);return h.push({type:D.DIE,id:e,x:r.x,y:w(r),z:r.z}),A(r,t),r}}},we=20,Te=.5,Ee=2,$=[`#e6194b`,`#3cb44b`,`#ffe119`,`#4363d8`,`#f58231`,`#911eb4`,`#42d4f4`,`#f032e6`,`#bfef45`,`#fabed4`,`#469990`,`#dcbeff`,`#9a6324`,`#800000`,`#aaffc3`,`#808000`],De=(e,t)=>Array.from(e).slice(0,t).join(``).trim(),Oe=e=>De((typeof e==`string`?e:``).replace(/\s+/g,` `).replace(/\p{Cc}/gu,``).trim(),16),ke=(e,t)=>{let n=e;for(let r=2;t.includes(n);r++)n=`${De(e,15-`${r}`.length)} ${r}`;return n},Ae=(e,t,n,r,i)=>Math.hypot(e.x-t,e.z-r)<=i&&e.y<n+Te&&n<e.y+1.8,je=(e,t)=>{let n=setInterval(e,t);return()=>clearInterval(n)},Me=class{peers=/* @__PURE__ */ new Map;ticks=0;history=[];maps;lvl;horde;rand;level=0;hard=!1;phase=k.HUNT;keys=0;items=[];nextItem=0;kills=0;runStart=0;shots=[];halt;rules;rr=0;constructor(e={},t=Date.now(),n=re){this.rules={...w,...e},this.rand=Se(t),this.maps=n.map(A),this.load(0)}get size(){return this.players().length}connect(e){this.peers.set(e,null)}receive(e,t){let n=this.peers.get(e);if(typeof t==`string`){let r=c(t);n===null&&r?.t===`join`&&this.join(e,r.name);return}let r=n&&o(t);if(r&&n.bank>0){if(n.bank--,n.hp&&ue(n.state,r,this.lvl)){let e=_e(this.lvl,n.state,r.seq,this.rewind(n,r.view));if(this.shots.push(e),e.hit>=16){let t=this.horde.kill(e.hit,n.state.id);t&&n.kills++,t&&++this.kills%4==0&&this.drop(O.HEALTH,t.x,t.z)}}n.ack=r.seq}}disconnect(e){let t=this.peers.get(e);this.peers.delete(e),t&&this.roster()}tick(){let e=this.players();if(!e.length)return;let t=++this.ticks;for(let n of e)n.bank=Math.min(10,n.bank+1),!n.hp&&t-n.hurt>=180&&(n.hp=9,n.state=this.place(n.info.id,e.filter(e=>e.hp&&e!==n).map(e=>e.state)));let{events:n}=this.horde,r=n.length;if(this.horde.step(e.filter(e=>e.hp).map(e=>e.state)),n.push(...n.splice(r).filter(e=>e.type!==D.HURT||this.wound(e.id,t))),this.progress(e.filter(e=>e.hp)),t%2==0){let n=this.horde.monsters();for(this.history.push({tick:t,players:e.map(e=>({...e.state})),monsters:n});this.history[0].tick<t-30;)this.history.shift();let r=s({tick:t,players:e.map(e=>({...e.state,ack:e.ack,hp:e.hp})),shots:this.shots,monsters:n,bullets:this.horde.bullets(),events:this.horde.events.splice(0,255),level:this.level,hard:this.hard,phase:this.phase,keys:this.keys,items:this.items});this.shots=[],e.forEach(e=>e.conn.send(r))}}start(e=je){if(this.halt)return;let t=1e3/60,n=performance.now(),r=0;this.halt=e(()=>{let e=performance.now();r+=e-n,n=e;for(let e=0;r>=t&&e<we;e++)this.tick(),r-=t;r%=t},t)}stop(){this.halt?.(),this.halt=void 0}rewind(e,t=0){let n=this.players().filter(t=>t!==e&&t.hp).map(e=>e.state),r=this.horde.monsters(),[i,a]=[this.history[0],this.history.at(-1)];if(!i||!a)return[...n.map(ge),...r.map(Y)];let o=((this.ticks-t+32768)%65536+65536)%65536-32768,s=Math.min(Math.max(this.ticks-o,i.tick),a.tick),c=0;for(;c+1<this.history.length&&this.history[c+1].tick<=s;)c++;let[l,u]=[this.history[c],this.history[c+1]??this.history[c]],d=u.tick>l.tick?(s-l.tick)/(u.tick-l.tick):0,f=(e,t)=>e+(t-e)*d,p=(e,t)=>e.map(e=>{let n=t(l).find(t=>t.id===e.id),r=t(u).find(t=>t.id===e.id);return n&&r?{...r,x:f(n.x,r.x),y:f(n.y,r.y),z:f(n.z,r.z)}:r??n??e});return[...p(n,e=>e.players).map(ge),...p(r,e=>e.monsters).map(Y)]}load(e){this.level=e,this.lvl=this.maps[e],this.keys=0,this.phase=k.HUNT,j(this.lvl,0,k.HUNT),this.horde=Ce(this.lvl,this.rand,this.hard),this.items=[],this.nextItem=0,this.kills=0,this.lvl.map.items?.forEach(([e,t,n])=>this.drop(n,e,t)),this.shots=[],this.history=[];let t=[];for(let e of this.players())e.hp=9,e.state=this.place(e.info.id,t),t.push(e.state)}place(e,t){let n=this.lvl.map.spawns.findIndex((n,r)=>{let{x:i,z:a}=de(e,this.lvl,r);return!t.some(e=>Math.hypot(e.x-i,e.z-a)<Ee)});return de(e,this.lvl,n<0?this.rr++:n)}floor(e,t){return this.lvl.map.sectors[Math.max(N(this.lvl,e,t),0)].floor}drop(e,t,n){let r=Math.fround;this.items.push({id:this.nextItem++,kind:e,x:r(t),y:r(this.floor(t,n)),z:r(n)})}wound(e,t){let n=this.players().find(t=>t.info.id===e);return!n?.hp||t-n.hurt<60?!1:([n.hp,n.hurt]=[n.hp-1,t],n.deaths+=+!n.hp,!0)}progress(e){let{sectors:t,goal:n,exit:r}=this.lvl.map,i=!1;if(this.items=this.items.filter(t=>{let n=e.find(e=>Ae(e.state,t.x,t.y,t.z,.8)&&(t.kind!==O.HEALTH||e.hp<9));return n&&t.kind===O.HEALTH?n.hp=Math.min(9,n.hp+3):n&&(this.keys|=1<<t.kind,i=!0),!n}),this.phase===k.HUNT)n&&e.some(e=>Ae(e.state,n[0],this.floor(...n),n[1],1))&&(this.phase=k.RETURN,i=!0);else if(r!==void 0&&e.length&&e.every(e=>M(t[r],e.state.x,e.state.z)))return this.win();i&&j(this.lvl,this.keys,this.phase)}win(){if(this.level+1<this.maps.length){this.load(this.level+1);return}let e=JSON.stringify({t:`end`,ticks:this.ticks-this.runStart,hard:this.hard,stats:this.players().map(e=>({id:e.info.id,kills:e.kills,deaths:e.deaths}))});this.players().forEach(t=>t.conn.send(e)),this.players().forEach(e=>e.kills=e.deaths=0),[this.hard,this.runStart]=[!0,this.ticks],this.load(0)}players(){return[...this.peers.values()].filter(e=>e!==null)}join(e,t){let n=this.players();if(n.length>=this.rules.maxPlayers){e.send(JSON.stringify({t:`full`}));return}let r=0;for(;n.some(e=>e.info.id===r);)r++;let i=$.find(e=>!n.some(t=>t.info.color===e))??$[r%$.length],a={conn:e,info:{id:r,name:ke(Oe(t)||`Player ${r}`,n.map(e=>e.info.name)),color:i},state:this.place(r,n.filter(e=>e.hp).map(e=>e.state)),bank:10,ack:65535,hp:9,hurt:-60,kills:0,deaths:0};this.peers.set(e,a),this.roster()}roster(){let e=this.players(),t=e.map(e=>e.info).sort((e,t)=>e.id-t.id);e.forEach(e=>e.conn.send(JSON.stringify({t:`roster`,you:e.info.id,players:t})))}},Ne=(e,t)=>{let n=()=>{},r=()=>{n();let r=setInterval(e,t);n=()=>clearInterval(r)};try{let i=URL.createObjectURL(new Blob([`setInterval(()=>postMessage(0),${t})`])),a=new Worker(i);a.onmessage=e,a.onerror=r,n=()=>{a.terminate(),URL.revokeObjectURL(i)}}catch{r()}return()=>n()},Pe=(e,t)=>{let n=`tiny-fps:`+e,r=Math.random().toString(36).slice(2),i=new BroadcastChannel(n),a=new AbortController,o=globalThis.navigator?.locks,s,l,u,d,f=[],p,m=!1,h=e=>i.postMessage({from:r,...e}),g=e=>!m&&S.onmessage?.({data:e}),_={send:e=>queueMicrotask(()=>g(e))},v=()=>{let e=f.length?f:p?[p]:[];return f=[],e},y=e=>{if(m)return e();u=e,d=r,l=/* @__PURE__ */ new Map,s=new Me(t),s.start(Ne),s.connect(_),v().forEach(e=>s.receive(_,e)),h({kind:`h`})};i.onmessage=({data:e})=>{if(!m){if(s&&l){let{from:t,kind:n}=e,r=l.get(t);n===`q`?h({to:t,kind:`h`}):n===`m`&&!e.to?(r||(r={send:e=>!m&&h({to:t,kind:`m`,data:e})},l.set(t,r),s.connect(r)),s.receive(r,e.data)):n===`b`&&r&&(l.delete(t),s.disconnect(r))}else e.to!==r&&e.to||(e.kind===`m`&&e.to?g(e.data):e.kind===`h`&&e.from!==d&&(d=e.from,v().forEach(e=>h({kind:`m`,data:e}))))}};let b=e=>{m||(typeof e==`string`&&c(e)?.t===`join`&&(p=e),s?s.receive(_,e):d?h({kind:`m`,data:e}):f.push(e))},x=()=>{m||(m=!0,globalThis.removeEventListener?.(`pagehide`,x),s?(s.stop(),u()):(h({kind:`b`}),a.abort()),i.close(),setTimeout(()=>S.onclose?.()))},S={binaryType:`arraybuffer`,onopen:null,onclose:null,onmessage:null,send:b,close:x};return o?o.request(n,{signal:a.signal},()=>new Promise(y)).catch(()=>{}):y(()=>{}),h({kind:`q`}),globalThis.addEventListener?.(`pagehide`,x),setTimeout(()=>!m&&S.onopen?.()),S};export{Pe as localSocket};
|
package/dist/server.js
CHANGED
|
@@ -165,11 +165,11 @@ var [H, R, B, Y] = [
|
|
|
165
165
|
];
|
|
166
166
|
var QUARTER = Math.PI / 4;
|
|
167
167
|
/**
|
|
168
|
-
* One level from its rooms (the first is the start and the exit), the spawn grid (x, z of its
|
|
168
|
+
* One level from its name, its rooms (the first is the start and the exit), the spawn grid (x, z of its
|
|
169
169
|
* corner, facing), walkers and flyers (x, z, facing in eighth turns: 0 north, 2 west, 4 south, 6
|
|
170
170
|
* east), items (x, z, kind) and the goal.
|
|
171
171
|
*/
|
|
172
|
-
var level = (rooms, [sx, sz, sd], walkers, flyers, items, goal) => {
|
|
172
|
+
var level = (name, rooms, [sx, sz, sd], walkers, flyers, items, goal) => {
|
|
173
173
|
const boxes = rooms.map(([x0, z0, x1, z1]) => [
|
|
174
174
|
[x0, z0],
|
|
175
175
|
[x1, z0],
|
|
@@ -178,6 +178,7 @@ var level = (rooms, [sx, sz, sd], walkers, flyers, items, goal) => {
|
|
|
178
178
|
]);
|
|
179
179
|
const corners = [...new Map(boxes.flat().map((p) => [`${p}`, p])).values()];
|
|
180
180
|
return {
|
|
181
|
+
name,
|
|
181
182
|
sectors: rooms.map(([, , , , floor, ceil, t = "103", light], s) => ({
|
|
182
183
|
pts: boxes[s].flatMap((a, i, p) => {
|
|
183
184
|
const b = p[(i + 1) % 4];
|
|
@@ -217,7 +218,7 @@ var level = (rooms, [sx, sz, sd], walkers, flyers, items, goal) => {
|
|
|
217
218
|
};
|
|
218
219
|
};
|
|
219
220
|
var LEVELS = [
|
|
220
|
-
level([
|
|
221
|
+
level("Warm-up", [
|
|
221
222
|
[
|
|
222
223
|
0,
|
|
223
224
|
0,
|
|
@@ -327,7 +328,7 @@ var LEVELS = [
|
|
|
327
328
|
H
|
|
328
329
|
]
|
|
329
330
|
], [54, 34]),
|
|
330
|
-
level([
|
|
331
|
+
level("Foundry", [
|
|
331
332
|
[
|
|
332
333
|
0,
|
|
333
334
|
14,
|
|
@@ -543,7 +544,7 @@ var LEVELS = [
|
|
|
543
544
|
R
|
|
544
545
|
]
|
|
545
546
|
], [66, 48]),
|
|
546
|
-
level([
|
|
547
|
+
level("Cistern", [
|
|
547
548
|
[
|
|
548
549
|
0,
|
|
549
550
|
20,
|
|
@@ -791,7 +792,7 @@ var LEVELS = [
|
|
|
791
792
|
B
|
|
792
793
|
]
|
|
793
794
|
], [80, 62]),
|
|
794
|
-
level([
|
|
795
|
+
level("Loop", [
|
|
795
796
|
[
|
|
796
797
|
0,
|
|
797
798
|
44,
|
|
@@ -1094,7 +1095,7 @@ var LEVELS = [
|
|
|
1094
1095
|
Y
|
|
1095
1096
|
]
|
|
1096
1097
|
], [6, 13]),
|
|
1097
|
-
level([
|
|
1098
|
+
level("Citadel", [
|
|
1098
1099
|
[
|
|
1099
1100
|
0,
|
|
1100
1101
|
60,
|
|
@@ -2281,7 +2282,8 @@ var setEvery = (cb, ms) => {
|
|
|
2281
2282
|
* opens its gates for the team, a pack heals below full health.
|
|
2282
2283
|
* - Touching the goal turns the level from HUNT to RETURN (the exit opens); when every living
|
|
2283
2284
|
* player is in the exit the level is won: the next one starts, everyone respawned. After the
|
|
2284
|
-
* last, every player gets { t: 'end' }
|
|
2285
|
+
* last, every player gets { t: 'end' } with the run's kills and deaths per player, and a new
|
|
2286
|
+
* run starts at level 0, hard from then on, the counts back at 0.
|
|
2285
2287
|
* - Every SNAP_EVERY ticks of TICK_HZ, one snapshot with every player, the shots resolved since
|
|
2286
2288
|
* the last one, the monsters, the bullets, the events since the last one and the items goes to
|
|
2287
2289
|
* every peer.
|
|
@@ -2347,6 +2349,7 @@ var Room = class {
|
|
|
2347
2349
|
this.shots.push(shot);
|
|
2348
2350
|
if (shot.hit >= 16) {
|
|
2349
2351
|
const dead = this.horde.kill(shot.hit, p.state.id);
|
|
2352
|
+
if (dead) p.kills++;
|
|
2350
2353
|
if (dead && ++this.kills % 4 === 0) this.drop(ITEM.HEALTH, dead.x, dead.z);
|
|
2351
2354
|
}
|
|
2352
2355
|
}
|
|
@@ -2511,6 +2514,7 @@ var Room = class {
|
|
|
2511
2514
|
const p = this.players().find((q) => q.info.id === id);
|
|
2512
2515
|
if (!p?.hp || now - p.hurt < 60) return false;
|
|
2513
2516
|
[p.hp, p.hurt] = [p.hp - 1, now];
|
|
2517
|
+
p.deaths += +!p.hp;
|
|
2514
2518
|
return true;
|
|
2515
2519
|
}
|
|
2516
2520
|
/** What the living players do to the level: pick things up, touch the goal, win. */
|
|
@@ -2543,9 +2547,15 @@ var Room = class {
|
|
|
2543
2547
|
const end = JSON.stringify({
|
|
2544
2548
|
t: "end",
|
|
2545
2549
|
ticks: this.ticks - this.runStart,
|
|
2546
|
-
hard: this.hard
|
|
2550
|
+
hard: this.hard,
|
|
2551
|
+
stats: this.players().map((p) => ({
|
|
2552
|
+
id: p.info.id,
|
|
2553
|
+
kills: p.kills,
|
|
2554
|
+
deaths: p.deaths
|
|
2555
|
+
}))
|
|
2547
2556
|
});
|
|
2548
2557
|
this.players().forEach((p) => p.conn.send(end));
|
|
2558
|
+
this.players().forEach((p) => p.kills = p.deaths = 0);
|
|
2549
2559
|
[this.hard, this.runStart] = [true, this.ticks];
|
|
2550
2560
|
this.load(0);
|
|
2551
2561
|
}
|
|
@@ -2572,7 +2582,9 @@ var Room = class {
|
|
|
2572
2582
|
bank: 10,
|
|
2573
2583
|
ack: 65535,
|
|
2574
2584
|
hp: 9,
|
|
2575
|
-
hurt: -60
|
|
2585
|
+
hurt: -60,
|
|
2586
|
+
kills: 0,
|
|
2587
|
+
deaths: 0
|
|
2576
2588
|
};
|
|
2577
2589
|
this.peers.set(conn, player);
|
|
2578
2590
|
this.roster();
|
|
@@ -10,9 +10,9 @@ export interface Audio {
|
|
|
10
10
|
listen(eye: Vec3, yaw: number): void;
|
|
11
11
|
/**
|
|
12
12
|
* Plays the SOUND `id`. With `at`, panned left or right by its direction from the listener and
|
|
13
|
-
* fainter with distance; without, centred
|
|
13
|
+
* fainter with distance; without, centred (the own player's sounds). `gain` scales the volume.
|
|
14
14
|
*/
|
|
15
|
-
play(id: number, at?: Vec3): void;
|
|
15
|
+
play(id: number, at?: Vec3, gain?: number): void;
|
|
16
16
|
/** Mutes or unmutes everything, music included. */
|
|
17
17
|
mute(on: boolean): void;
|
|
18
18
|
readonly muted: boolean;
|
|
@@ -24,6 +24,15 @@ export declare const createAudio: () => Audio;
|
|
|
24
24
|
export declare const hear: (a: Audio, { type, id, x, y, z }: GameEvent, you: number) => void;
|
|
25
25
|
/** Returns a function that plays CLOCK once a second while called with `on`; `now` in ms. */
|
|
26
26
|
export declare const createClock: (a: Audio) => (on: boolean, now: number) => void;
|
|
27
|
+
/** The heart beats at this health or below, while alive. */
|
|
28
|
+
export declare const LOW_HP = 3;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a function called each frame with the own health (0 when dead) and `now` in ms. At 1 to
|
|
31
|
+
* LOW_HP health it plays HEART, every 0.8 s, and at 1 every 0.5 s and louder; the first beat
|
|
32
|
+
* comes the moment health gets low. Returns the beat for the screen: 1 at a thump, fading to 0 by
|
|
33
|
+
* the next, and 0 when the health is not low.
|
|
34
|
+
*/
|
|
35
|
+
export declare const createHeart: (a: Audio) => (hp: number, now: number) => number;
|
|
27
36
|
/** The mute choice of the last visit. Storage throws when blocked: no memory then. */
|
|
28
37
|
export declare const savedMute: () => boolean;
|
|
29
38
|
/** Flips mute, remembers it, and returns the new state. */
|
|
@@ -92,6 +92,9 @@ export interface Effects {
|
|
|
92
92
|
event(e: GameEvent, you: number): void;
|
|
93
93
|
}
|
|
94
94
|
export declare const BLAST = 0.3;
|
|
95
|
+
/** Seconds the hit vignette and the pickup fade take to go out. */
|
|
96
|
+
export declare const HURT = 0.45;
|
|
97
|
+
export declare const GAIN = 0.4;
|
|
95
98
|
/** Half the side of an explosion's glow: it swells fast, then shrinks to nothing as it ends. */
|
|
96
99
|
export declare const glow: ({ r, t }: Blast) => number;
|
|
97
100
|
/**
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
/** Slots of say(): a title, a hint under it
|
|
1
|
+
/** Slots of say(): a title, a hint under it; and seconds each stays up (the end screen is the third). */
|
|
2
2
|
export declare const SAY: {
|
|
3
3
|
readonly TITLE: 0;
|
|
4
4
|
readonly NOTE: 1;
|
|
5
|
-
readonly END: 2;
|
|
6
5
|
};
|
|
6
|
+
/** A player's line of the end screen. */
|
|
7
|
+
export type Score = [name: string, color: string, kills: number, deaths: number];
|
|
7
8
|
export declare const HUD_CSS: string;
|
|
8
9
|
export interface Hud {
|
|
9
|
-
/**
|
|
10
|
+
/** The own health: the bar's width, number and colour. It flashes on a rise and shakes on a fall. */
|
|
10
11
|
hp(n: number): void;
|
|
11
12
|
/** The keys held, as the snapshot's bit set (1 << ITEM.KEY_*). */
|
|
12
13
|
keys(bits: number): void;
|
|
13
|
-
/** The own player is dead
|
|
14
|
-
dead(
|
|
14
|
+
/** The own player is dead and respawns in `secs` seconds; 0 hides the death screen. */
|
|
15
|
+
dead(secs: number): void;
|
|
16
|
+
/**
|
|
17
|
+
* The screen fades, each 0 to 1: the red vignette of a hit, the low-health beat (0 when the
|
|
18
|
+
* health is not low), and the fade of a picked-up item's colour.
|
|
19
|
+
*/
|
|
20
|
+
fade(hurt: number, low: number, gain: number, color: number[]): void;
|
|
21
|
+
/** The title screen with `status` under the controls, "Click to play" or why not; '' hides it. */
|
|
22
|
+
title(status: string, level: string): void;
|
|
23
|
+
/** The end screen: `head`, the players' scores in the order given, `foot`. */
|
|
24
|
+
end(head: string, scores: Score[], foot: string): void;
|
|
15
25
|
/** Shows or hides the muted mark. */
|
|
16
26
|
mute(on: boolean): void;
|
|
17
27
|
/** Shows text in a SAY slot, for that slot's time. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Item, Level, MapDef, Snapshot } from '../shared/types';
|
|
1
|
+
import type { Item, Level, MapDef, PlayerInfo, Snapshot } from '../shared/types';
|
|
2
2
|
import type { Audio } from './audio';
|
|
3
3
|
import type { Effects } from './effects';
|
|
4
4
|
import type { Hud } from './hud';
|
|
@@ -11,20 +11,30 @@ export interface Progress {
|
|
|
11
11
|
readonly items: Item[];
|
|
12
12
|
/** The own player has no health left. */
|
|
13
13
|
readonly dead: boolean;
|
|
14
|
+
/** The own health: 0 when dead or unknown. */
|
|
15
|
+
readonly hp: number;
|
|
16
|
+
/** The level's number, name and mode, for the title screen. */
|
|
17
|
+
readonly name: string;
|
|
14
18
|
/** The level is in its RETURN phase: the team runs back to the exit. */
|
|
15
19
|
readonly returning: boolean;
|
|
16
20
|
/** False for a player the latest snapshot shows without health: not drawn. */
|
|
17
21
|
alive(id: number): boolean;
|
|
18
22
|
/** A snapshot, before the predictor sees it: a new level or `hard` switches everything. */
|
|
19
23
|
snapshot(s: Snapshot): void;
|
|
20
|
-
/** The run is won: the end screen with its time. */
|
|
21
|
-
end(ticks: number, hard: boolean
|
|
24
|
+
/** The run is won: the end screen with its time and the players' kills and deaths. */
|
|
25
|
+
end(ticks: number, hard: boolean, stats: {
|
|
26
|
+
id: number;
|
|
27
|
+
kills: number;
|
|
28
|
+
deaths: number;
|
|
29
|
+
}[]): void;
|
|
22
30
|
}
|
|
23
31
|
export interface Deps {
|
|
24
32
|
/** The level the predictor, renderer and effects were built with. */
|
|
25
33
|
lvl: Level;
|
|
26
34
|
/** The own player id, -1 while unknown. */
|
|
27
35
|
you(): number;
|
|
36
|
+
/** Everyone in the room. */
|
|
37
|
+
roster(): PlayerInfo[];
|
|
28
38
|
predictor: {
|
|
29
39
|
level(lvl: Level): void;
|
|
30
40
|
};
|
|
@@ -43,4 +53,4 @@ export interface Deps {
|
|
|
43
53
|
}
|
|
44
54
|
/** The yaw of the spawn nearest (x, z): where a player put back at the start should look. */
|
|
45
55
|
export declare const facing: ({ spawns }: MapDef, x: number, z: number) => number;
|
|
46
|
-
export declare const createProgress: ({ lvl, you, predictor, rd, delays, fx, hud, audio, }: Deps) => Progress;
|
|
56
|
+
export declare const createProgress: ({ lvl, you, roster, predictor, rd, delays, fx, hud, audio, }: Deps) => Progress;
|
|
@@ -14,6 +14,8 @@ export declare const SOUND: {
|
|
|
14
14
|
readonly CLOCK: 4;
|
|
15
15
|
/** A bullet bursting on a wall. */
|
|
16
16
|
readonly BURST: 5;
|
|
17
|
+
/** A heartbeat, looped by the client while the own health is low. */
|
|
18
|
+
readonly HEART: 6;
|
|
17
19
|
};
|
|
18
20
|
/**
|
|
19
21
|
* Renders the SOUND `id` as mono samples in [-1, 1] at RATE, deterministic (seeded noise), a few
|
|
@@ -12,12 +12,18 @@ export type ServerText = {
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* The last level of a run was won: the run took `ticks` host ticks; `hard` says whether that run
|
|
15
|
-
* was hard. The next run always is.
|
|
15
|
+
* was hard. The next run always is. `stats` has one row per player still in the room, kills and
|
|
16
|
+
* deaths over the whole run.
|
|
16
17
|
*/
|
|
17
18
|
| {
|
|
18
19
|
t: 'end';
|
|
19
20
|
ticks: number;
|
|
20
21
|
hard: boolean;
|
|
22
|
+
stats: {
|
|
23
|
+
id: number;
|
|
24
|
+
kills: number;
|
|
25
|
+
deaths: number;
|
|
26
|
+
}[];
|
|
21
27
|
};
|
|
22
28
|
export declare const MSG_INPUT = 1;
|
|
23
29
|
export declare const MSG_SNAPSHOT = 2;
|
|
@@ -18,7 +18,8 @@ import type { Conn, Every, MapDef, Rules } from './types';
|
|
|
18
18
|
* opens its gates for the team, a pack heals below full health.
|
|
19
19
|
* - Touching the goal turns the level from HUNT to RETURN (the exit opens); when every living
|
|
20
20
|
* player is in the exit the level is won: the next one starts, everyone respawned. After the
|
|
21
|
-
* last, every player gets { t: 'end' }
|
|
21
|
+
* last, every player gets { t: 'end' } with the run's kills and deaths per player, and a new
|
|
22
|
+
* run starts at level 0, hard from then on, the counts back at 0.
|
|
22
23
|
* - Every SNAP_EVERY ticks of TICK_HZ, one snapshot with every player, the shots resolved since
|
|
23
24
|
* the last one, the monsters, the bullets, the events since the last one and the items goes to
|
|
24
25
|
* every peer.
|
|
@@ -179,6 +179,8 @@ export interface Sector {
|
|
|
179
179
|
light?: number;
|
|
180
180
|
}
|
|
181
181
|
export interface MapDef {
|
|
182
|
+
/** Shown on the title screen after the level number. */
|
|
183
|
+
name?: string;
|
|
182
184
|
sectors: Sector[];
|
|
183
185
|
/** Spawn points: feet x, z (inside a sector, standing on its floor) and the yaw to face. */
|
|
184
186
|
spawns: [x: number, z: number, yaw: number][];
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@korial29/tiny-fps",
|
|
3
3
|
"description": "Tiny multiplayer first-person shooter for the browser: raw WebGL, zero runtime dependencies, WebSocket or same-browser multi-tab play.",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.7.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|