@korial29/tiny-fps 0.4.0 → 0.5.1
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 +239 -3
- package/dist/index.js +24 -8
- package/dist/types/client/lights.d.ts +47 -0
- package/dist/types/client/render.d.ts +27 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,245 @@
|
|
|
1
1
|
# tiny-fps
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@korial29/tiny-fps)
|
|
4
|
+
[](https://www.npmjs.com/package/@korial29/tiny-fps)
|
|
5
|
+
[](https://bundlephobia.com/package/@korial29/tiny-fps)
|
|
6
|
+
[](https://github.com/korial29/tiny-fps/actions/workflows/ci.yml)
|
|
7
|
+
[](package.json)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://korial29.github.io/tiny-fps/)
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
**▶ Play it now: https://korial29.github.io/tiny-fps/**
|
|
12
|
+
|
|
13
|
+
A tiny co-op first-person shooter for the browser, written in TypeScript with raw WebGL2, no game library and no runtime dependency. Players team up against walkers and flyers through five dark levels: find the keys, open the barred gates, reach the goal, then get everyone back to the start. Everything is generated in code: geometry, textures, lights. There are no images, fonts or assets to serve.
|
|
14
|
+
|
|
15
|
+
It is inspired by carlini's [Yet Another Doom Clone](https://github.com/carlini/js13k2019-yet-another-doom-clone) (js13k 2019), and adds multiplayer. Only the ideas are reused, not the code.
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+

|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
## Framework-agnostic, light to add
|
|
24
|
+
|
|
25
|
+
`tinyFps()` mounts the game into any element, inside its own Shadow DOM: React, Vue, Angular, Svelte or a plain page, nothing leaks in or out. The game draws everything on one WebGL2 canvas that fills the container.
|
|
26
|
+
|
|
27
|
+
| Entry | What it is | Size (gzip) |
|
|
28
|
+
| --------------------------- | ---------------------------------------------------------------------- | ----------- |
|
|
29
|
+
| `@korial29/tiny-fps` | The game client: rendering, lights and shadows, input, prediction, HUD | ~18 KB |
|
|
30
|
+
| `@korial29/tiny-fps/local` | Same-browser multiplayer, no server: the host runs in a tab | ~9.5 KB |
|
|
31
|
+
| `@korial29/tiny-fps/server` | Node WebSocket server (needs `ws`) | Node only |
|
|
32
|
+
|
|
33
|
+
CI checks the budgets (30 KB and 12 KB) on every pull request.
|
|
34
|
+
|
|
35
|
+
## Live demo
|
|
36
|
+
|
|
37
|
+
https://korial29.github.io/tiny-fps/
|
|
38
|
+
|
|
39
|
+
1. Open the page, pick a name and play: you are alone against the monsters.
|
|
40
|
+
2. For co-op on one machine, open it in a second tab of the same browser and join with another name: the tabs play together, with no server.
|
|
41
|
+
3. To play across devices, pick the server mode and give it the URL of a running `tiny-fps-server`.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```sh
|
|
6
48
|
npm install @korial29/tiny-fps
|
|
7
49
|
```
|
|
8
50
|
|
|
9
|
-
The unscoped name `tiny-fps` belongs to another package.
|
|
51
|
+
The unscoped name `tiny-fps` belongs to another package. The server entry also needs [`ws`](https://github.com/websockets/ws), an optional peer dependency:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
npm install ws
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Basic usage
|
|
60
|
+
|
|
61
|
+
### Tabs of the same browser, no server
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { tinyFps } from '@korial29/tiny-fps';
|
|
65
|
+
import { localSocket } from '@korial29/tiny-fps/local';
|
|
66
|
+
|
|
67
|
+
const game = tinyFps(document.getElementById('game')!, {
|
|
68
|
+
name: 'Ana',
|
|
69
|
+
socket: localSocket('my-room'),
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Every tab that opens `localSocket('my-room')` joins the same game over a [`BroadcastChannel`](https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel). One tab hosts the game, elected with [`navigator.locks`](https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_API); when it closes, another tab takes over with a fresh game. `navigator.locks` needs a secure context: on `http://` from a LAN address, each tab plays alone.
|
|
74
|
+
|
|
75
|
+
### Across devices, with a WebSocket server
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// server.ts (Node)
|
|
79
|
+
import { serve } from '@korial29/tiny-fps/server';
|
|
80
|
+
|
|
81
|
+
const stop = serve({ port: 8787 }); // or serve({ server: existingHttpServer })
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
// in the browser
|
|
86
|
+
import { tinyFps } from '@korial29/tiny-fps';
|
|
87
|
+
|
|
88
|
+
tinyFps(document.getElementById('game')!, {
|
|
89
|
+
name: 'Ana',
|
|
90
|
+
url: 'wss://your-host.example/my-room',
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Each URL path is its own room: `/my-room` and `/other` are two separate games. A ready-made server ships as a command:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
PORT=8787 npx tiny-fps-server
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Sizing
|
|
101
|
+
|
|
102
|
+
The canvas fills its container, at any size and ratio. Give the container a size:
|
|
103
|
+
|
|
104
|
+
```css
|
|
105
|
+
#game {
|
|
106
|
+
width: 100vw;
|
|
107
|
+
height: 100dvh;
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## API
|
|
114
|
+
|
|
115
|
+
### `tinyFps(container, options)`
|
|
116
|
+
|
|
117
|
+
Mounts the game and joins. Returns `{ on, players, destroy }`.
|
|
118
|
+
|
|
119
|
+
| Option | Type | Description |
|
|
120
|
+
| -------- | ------------ | -------------------------------------------------------------------------------------------- |
|
|
121
|
+
| `name` | `string` | Player name shown above your head (16 characters max). A taken name gets a suffix (`Bob 2`). |
|
|
122
|
+
| `url` | `string` | WebSocket URL, room in the path. Ignored when `socket` is given. |
|
|
123
|
+
| `socket` | `SocketLike` | Any WebSocket-like object, e.g. `localSocket('room')`. |
|
|
124
|
+
|
|
125
|
+
Without WebGL2 the game stays connected and says so on screen.
|
|
126
|
+
|
|
127
|
+
### `on(event, callback)`
|
|
128
|
+
|
|
129
|
+
| Event | When |
|
|
130
|
+
| -------- | -------------------------------------------------------- |
|
|
131
|
+
| `open` | Connected. |
|
|
132
|
+
| `close` | Disconnected. |
|
|
133
|
+
| `roster` | A player joined or left; read the list with `players()`. |
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
game.on('roster', () => console.log(game.players().map(p => p.name)));
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### `players()`
|
|
140
|
+
|
|
141
|
+
Everyone in the room, you included: `{ id, name, color }[]`. Each player has a colour of their own.
|
|
142
|
+
|
|
143
|
+
### `destroy()`
|
|
144
|
+
|
|
145
|
+
Leaves the game, stops rendering, releases the pointer and removes the game's DOM. Safe to call twice.
|
|
146
|
+
|
|
147
|
+
### `localSocket(room, rules?)`: `@korial29/tiny-fps/local`
|
|
148
|
+
|
|
149
|
+
A same-browser socket for `tinyFps`. `rules` apply to the game the tab hosts, so pass the same ones from every tab.
|
|
150
|
+
|
|
151
|
+
### `serve({ port | server, rules? })`: `@korial29/tiny-fps/server`
|
|
152
|
+
|
|
153
|
+
Starts the WebSocket server, one room per URL path, and returns an async `stop()`. `rules` apply to every room.
|
|
154
|
+
|
|
155
|
+
### `SocketLike`
|
|
156
|
+
|
|
157
|
+
The subset of `WebSocket` the client uses: `binaryType`, `onopen`, `onclose`, `onmessage`, `send(data)` and `close()`. A real `WebSocket` and `localSocket()` both fit, and so does a relay over a transport you already have. Text frames are JSON, and binary frames (inputs, snapshots) must arrive as an `ArrayBuffer` of exactly their bytes.
|
|
158
|
+
|
|
159
|
+
### Rules
|
|
160
|
+
|
|
161
|
+
| Rule | Default | Description |
|
|
162
|
+
| ------------ | ------- | ----------------------------------------------------------- |
|
|
163
|
+
| `maxPlayers` | `16` | Players in a room; the next ones are told the room is full. |
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Controls
|
|
168
|
+
|
|
169
|
+
| Action | Keys |
|
|
170
|
+
| ------ | ------------------------------------------------------------- |
|
|
171
|
+
| Look | Mouse (click the game to lock the pointer, Esc to release it) |
|
|
172
|
+
| Move | WASD, or the arrow keys |
|
|
173
|
+
| Jump | Space |
|
|
174
|
+
| Fire | Left mouse button, held |
|
|
175
|
+
|
|
176
|
+
Keys are read by their position (`KeyboardEvent.code`), so on an AZERTY keyboard WASD is ZQSD with nothing to set.
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## How a game plays
|
|
181
|
+
|
|
182
|
+
- **Co-op**: everyone fights the monsters together; there is no friendly fire. Up to 16 players.
|
|
183
|
+
- **Chaingun**: 12 shots a second, at half speed while you fire. The host decides every hit, and moves the targets back to where you saw them (lag compensation).
|
|
184
|
+
- **Monsters**:
|
|
185
|
+
- Walkers patrol the floors, fire bullets and strike up close.
|
|
186
|
+
- Flyers float over steps and pits.
|
|
187
|
+
- They spot you within 60° of where they face and never through a wall, then alert their neighbours. One shot kills.
|
|
188
|
+
- **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.
|
|
189
|
+
- **Keys and gates**: red, blue and yellow keys open the barred gates of their colour, for the whole team.
|
|
190
|
+
- **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.
|
|
191
|
+
- **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
|
+
- **Dark levels**: your flashlight casts shadows, and so do muzzle flashes. Explosions, hits, bullets, the goal and the open exit light up their surroundings.
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Features
|
|
197
|
+
|
|
198
|
+
Parity with the js13k game is tracked in [`docs/PARITY.md`](docs/PARITY.md).
|
|
199
|
+
|
|
200
|
+
- [x] Multiplayer over WebSocket, or between tabs of one browser with no server
|
|
201
|
+
- [x] Doom-style sector maps: steps, pits, low ceilings, balconies, procedural brick, tile, lava and stone textures
|
|
202
|
+
- [x] Client-side prediction, exact to the bit, and the other players interpolated
|
|
203
|
+
- [x] Chaingun with lag-compensated hitscan, spinning barrels, recoil, muzzle flash, head bob, sparks
|
|
204
|
+
- [x] Walkers and flyers: patrol, sight cone, alert, chase, bullets, melee, gibs and explosions
|
|
205
|
+
- [x] Health, hit cooldown, death and respawn, health drops, team keys and barred gates
|
|
206
|
+
- [x] Five levels, the goal and the way back, hard mode on the next run, end screen with the time
|
|
207
|
+
- [x] Flashlights with shadow maps, lit muzzle flashes, explosion, hit, bullet, goal and exit lights
|
|
208
|
+
- [ ] Sound: a small synthesiser, stereo by position, looped music
|
|
209
|
+
- [ ] HUD and screens: health bar, damage and pickup fades, low-health cue, title screen
|
|
210
|
+
- [x] Shadow DOM, zero runtime dependencies, size-gated in CI
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## How it works
|
|
215
|
+
|
|
216
|
+
- **The host is authoritative**: the Node server, or the host tab in local mode. It runs the players, the monsters, the bullets, the pickups and the levels.
|
|
217
|
+
- **Inputs, not positions**: each client sends one 11-byte input per step at 60 Hz, holding its keys, view angles and the moment it sees the others at. It predicts its own player at once and replays what the host has not acknowledged yet.
|
|
218
|
+
- **Snapshots** go out at 30 Hz: players, shots, monsters, bullets, events and pickups, in a compact binary format. The other players and the monsters are drawn 100 ms in the past, interpolated between snapshots.
|
|
219
|
+
- **Rendering**: one WebGL2 shader program and one vertex buffer, up to 16 lights, with up to 4 shadow maps drawn by the same program.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Development
|
|
224
|
+
|
|
225
|
+
Node 24 (see `.nvmrc`).
|
|
226
|
+
|
|
227
|
+
```sh
|
|
228
|
+
npm install
|
|
229
|
+
npm start # demo with hot reload (Vite)
|
|
230
|
+
npm run dev:server # WebSocket server on :8787
|
|
231
|
+
npm test # Vitest
|
|
232
|
+
npm run lint # Prettier, ESLint, tsc
|
|
233
|
+
npm run build # dist/: client, local, server, types
|
|
234
|
+
npm run size # gzip budgets
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
The demo reads `?name=`, `?mode=local|server` and `?url=` from its URL, which makes testing several players in several tabs quick.
|
|
238
|
+
|
|
239
|
+
Pull requests need one release label (`release:major`, `release:minor`, `release:patch` or `release:skip`). Merging one into `master` publishes the matching npm release. See [`.github/CI.md`](.github/CI.md).
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## License
|
|
244
|
+
|
|
245
|
+
[Apache-2.0](LICENSE)
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
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,ee=e=>({...e,yaw:P(A(e.yaw)),pitch:N(M(e.pitch)),...e.view!==void 0&&{view:F(e.view)/256}}),te=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},ne=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)}))}},re=e=>{try{let t=JSON.parse(e);return t&&typeof t.t==`string`?t:null}catch{return null}},I=1/60,L=Math.PI*2,R=1e-6,z=.01,B=e=>(e%L+L)%L,ie=e=>[-Math.sin(e),-Math.cos(e)],V=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+z||c-Math.max(o.floor,s.floor)<i-z||c<r+i-z},se=(e,t,n,r,i)=>{let a=(n-R)**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(y(e,t,n),0),{floor:u,ceil:d}=s.sectors[l],f=(i-R)**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]},le=(n,r,a,o,s)=>{n.x+=r,n.z+=a,se(n,s,e,t,i);let[c,l]=ce(s,n.x,n.z,n.y,e,t,i);n.ground&&o&&(n.vy=7);let u=n.vy-20*I;n.y+=(n.vy+u)/2*I,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+z:n.y<c)&&(n.y=c,n.vy<=0&&(n.vy=0,n.ground=!0)),n.x=V(n.x),n.y=V(n.y),n.z=V(n.z),n.vy=V(n.vy)},ue=(e,t,n)=>{let i=(t.keys&u.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=B(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*I*(i?.5:1)/(Math.hypot(a,o)||1),[c,l]=ie(e.yaw);return le(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},de=.55,fe=6,pe=(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*L/t),Math.sin(e*L/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},H=e=>{let t=[];for(let n=0;n<fe;n++){let r=n*L/fe;t.push(...pe([[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:pe([[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])}}},G=(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]}),K=(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))}},me=.3,he=3.6,q={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]},ge=[[q.body,q.arm,q.head,q.gore,q.gore,q.chase],[q.shell,q.fin,q.shell,q.gore,q.chase]],_e=e=>e?q.chase:q.calm,J=({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]},Y=(e,t,n,r,i,a)=>{let o=[];W(o,[0,-i[1],0],i,0,a),K(e,o,t,U(n,r),[0,0,0],1)},ve=e=>e<.25?-.8*Math.sin(e*4*Math.PI):2*Math.sin((e-.25)*Math.PI/.75),ye=(e,t,n,r)=>{let i=Math.sin(n*he)*.6,a=o*.44,s=o*.8,[c,l]=[-1,1].map(e=>J(t,e*.16,a,0));Y(e,c,t.yaw,i,[.09,a/2,.09],q.leg),Y(e,l,t.yaw,-i,[.09,a/2,.09],q.leg),Y(e,J(t,-.35,s,0),t.yaw,-i*.8,[.07,.34,.07],q.arm),Y(e,J(t,.35,s,0),t.yaw,i*.8+(r>0?ve(r):0),[.07,.34,.07],q.arm),W(e,J(t,0,1.142,0),[.26,.35,.16],t.yaw,q.body),W(e,J(t,0,1.6500000000000001,0),[.15,.15,.15],t.yaw,q.head);let u=t.chase?.06:.045;for(let n of[-1,1])W(e,J(t,n*.075,1.69,.15),[u,u*.7,.02],t.yaw,_e(t.chase),-2)},be=G(pe([[0,0],[.18,.06],[s,.32],[s*.93,.5],[.22,.78],[0,c]],8),q.shell),xe=(e,t,n)=>{let r=Math.sin(n*2+t.id)*.06,i=[t.x,t.y+r,t.z];K(e,be,i,U(0,Math.PI/2),[0,0,0],1);for(let r=0;r<4;r++){let a=n*1.5+r*L/4;W(e,[t.x+Math.cos(a)*.4,i[1]+.35,t.z+Math.sin(a)*.4],[.16,.03,.04],-a,q.fin)}let a=J({...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,_e(t.chase),-2)},Se=(e,t,n)=>{let r=[t.x,t.y,t.z];if(W(e,r,[l*.8,l*.8,l*.8],0,q.blob,-2),W(e,r,[l*.5,l*.5,l*.5],Math.PI/4,q.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,q.blob,-2)}},Ce=.05,we=.3,Te=96,Ee=64,De=12,Oe=.3,ke=.15,Ae=.4,je=.5,Me=.9,Ne=.3,Pe=14,Fe=4.4,Ie=.035,Le=.03,Re=30,ze=({r:e,t})=>{let n=t/Oe;return n<1?e*Math.sqrt(n)*(1-n*n*n):0},Be=(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)}}},Ve=(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<Te&&_.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()*L,d()],o=Math.sqrt(1-a*a)*r*(.5+e()*.5);m(t,[Math.cos(n)*o,a*r,Math.sin(n)*o],we*(.6+e()*.4),i)}},g=(e,t)=>{_.blasts.push({p:e,r:t,t:0}),_.blasts.splice(0,_.blasts.length-De)},_={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*Fe),a+=(+(m>.5*r&&m<1)-a)*p,l=e,_.dead=Math.max(0,Math.min(1,_.dead+(f?r:-r)/je));let h=_.dead*_.dead*(3-2*_.dead);_.bob=Math.sin(i)*Ie*a-h*(n-Ne);let g=+!!(t&u.RIGHT)-!!(t&u.LEFT);s+=(g*Le-s)*Math.min(1,r*8),_.roll=s+h*Me,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(Re,c+(t&u.FIRE?60:-25)*r)),_.spin=(_.spin+c*r)%L;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<Oe);for(let e of _.gibs)e.life-=r,e.rest||v(e,r);_.gibs=_.gibs.filter(e=>e.life>0)},hit(){_.hurt=ke},pickup(e){[_.gain,_.gainC]=[Ae,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=Ce,o=.012):_.flashes.set(t.id,Ce);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,we*(.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=ge[_.herd.get(n)?.kind??0]??ge[0],s=10+Math.floor(e()*7);for(let n=0;n<s;n++){let n=e()*L,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()*L,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-Ee),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,me)}},v=(e,t)=>{e.v[1]-=Pe*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 _},He=[[1,1,1],[.95,.15,.1],[.2,.4,1],[1,.85,.15]],Ue=(e,t=1)=>`rgba(${e.map(e=>Math.round(e*255))},${t})`,We=.3,Ge=[.25,1,.45],Ke=[.85,.1,.1],qe=[.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)];W(e,[t+i*f+o*d,n+a,r-i*d+o*f],s,c,l,u)},Je=(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=He[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,Ke)}else X(e,c,[0,.17,0],[.1,.1,.025],s,l,-2),X(e,c,[0,.17,0],[.04,.04,.035],s,qe),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)},Ye=({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)]},Xe=(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)},Ze=(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=He[i];for(let i of t.edges.filter(e=>e.front==n&&e.back>=0)){let[n,a]=Ye(t,i),o=Math.ceil(Math.hypot(i.bx-i.ax,i.bz-i.az)/We);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)}Xe(e,i,n+.1,.04,.04,r),Xe(e,i,a-.1,.04,.04,r)}}if(i!==void 0&&!t.barred.has(i)){let r=Ge.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]=Ye(t,n);for(let t of[i+.04,a-.04])Xe(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)}}},Qe=(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)},$e=(e,t,n,r)=>{for(let t of n)Je(e,t,r);Ze(e,t,r),Qe(e,t,r)},et={TITLE:0,NOTE:1,END:2},tt=[2,3,6],nt=`h1,h2,h3,h4,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}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}`,rt=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>`);let t=t=>[...e.querySelectorAll(t)],[n,r]=[t(`ul li`),t(`ol li`)],i=[`h1`,`h2`,`h3`].map(t=>e.querySelector(t)),a=e.querySelector(`h4`);r.forEach((e,t)=>e.style.background=Ue(He[t+1]));let o=tt.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,say(e,t){i[e].textContent=t,i[e].hidden=!1,o[e]=tt[e]},update(e){o.forEach((t,n)=>{t>0&&(o[n]=t-e)<=0&&(i[n].hidden=!0)})}}},it=.0025,at=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},st=e=>ot[e]??0,ct=e=>{let t=new AbortController,n=(e,n,r)=>e.addEventListener(n,r,{signal:t.signal}),i={yaw:0,pitch:0,keys:0,locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>t.abort()};n(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),n(document,`mousemove`,e=>{i.locked()&&(i.yaw=((i.yaw-e.movementX*it)%at+at)%at,i.pitch=Math.max(-1.55,Math.min(r,i.pitch-e.movementY*it)))}),n(document,`keydown`,e=>{let t=st(e.code);t&&i.locked()&&(i.keys|=t,e.preventDefault())}),n(document,`keyup`,e=>{i.keys&=~st(e.code)}),n(document,`mousedown`,e=>{e.button==0&&i.locked()&&(i.keys|=u.FIRE)}),n(document,`mouseup`,e=>{e.button==0&&(i.keys&=~u.FIRE)});let a=()=>{i.keys=0};return n(window,`blur`,a),n(document,`pointerlockchange`,()=>i.locked()||a()),i},lt=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},ut=(e,t,n)=>{let[r,i,o,s]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],c=lt(n+1),l=(c&65535)/65536*L,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]},dt=(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},ft=(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},pt=({id:n,x:r,y:i,z:a})=>({id:n,x:r,y:i,z:a,r:e,h:t}),mt=({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}},ht=(e,t,r,i)=>{let a=[t.x,t.y+n,t.z],o=ut(t.yaw,t.pitch,r),s=dt(e,a,o,100),c=-1;for(let e of i){let n=e.id===t.id?1/0:ft(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}},gt=120,_t=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}),vt=(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}),yt=(e,t,n)=>B(e+(((t-e+Math.PI)%L+L)%L-Math.PI)*n),bt=(e,t)=>(t-e&65535)<32768,xt=(e,t,n)=>({...t,...vt(e,t,n),yaw:yt(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),St=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?xt(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,...vt(e,t,n),yaw:yt(e.yaw,t.yaw,n)}));return{you:e=>{n=e},step:(e,n)=>{let d=ee({...e,seq:r,view:n===void 0?void 0:f(n)});if(s=void 0,r=r+1&65535,i.push(d),i.length>gt&&i.shift(),a&&(o=Z(a),c&&ue(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=ht(t,a,d.seq,[...o.map(pt),...r.map(mt)]),s.hit>=16&&l.set(s.hit,d.seq)}return d},snapshot:(e,r)=>{u.push({t:r,s:e}),u.length>_t&&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=>!bt(e.seq,s.ack)),l.forEach((t,n)=>{let r=e=>e.monsters.some(e=>e.id===n);bt(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&&ue(a,e,t)}))},monsters:h,bullets:e=>m(e,e=>e.bullets,(e,t,n)=>({...t,...vt(e,t,n)})),level:e=>{t=e,u.length=0,l.clear(),a=o=s=void 0},shot:()=>s,me:e=>a&&o?xt(o,a,Math.max(0,Math.min(1,e))):void 0,others:p}},Ct=1.5,wt=e=>{let t=Math.floor(e*10/60);return`${Math.floor(t/600)}:${String(Math.floor(t/10)%60).padStart(2,`0`)}.${t%10}`},Tt=({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],Et=({lvl:e,you:t,predictor:n,rd:r,delays:i,fx:a,hud:o})=>{let s=-1,c=-1,l=/* @__PURE__ */ new Map,u={lvl:e,items:[],dead:!1,alive:e=>l.get(e)!==0,snapshot(e){let d=t(),f=e.level*2+ +e.hard;if(f!=s){let t=O[e.level];if(!t)return;s=f,u.lvl=g(t),u.items=[],l=/* @__PURE__ */ new Map,c=-1,n.level(u.lvl),r?.level(u.lvl),a.reset(u.lvl),i.forEach(e=>e.clear()),o.say(et.TITLE,`Level ${e.level+1}${e.hard?`
|
|
2
|
-
Hard mode`:``}`)}let p=e.players.find(e=>e.id==d),h=l.get(d);p&&h!==void 0&&p.hp<h&&a.hit(),l=new Map(e.players.map(e=>[e.id,e.hp]));for(let t of u.items)p&&!e.items.some(e=>e.id==t.id)&&Math.hypot(t.x-p.x,t.z-p.z)<
|
|
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=1/60,z=Math.PI*2,B=1e-6,V=.01,H=e=>(e%z+z)%z,ne=e=>[-Math.sin(e),-Math.cos(e)],U=Math.fround,re=(e,t,n)=>Math.min(Math.max(e,t),n),ie=({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+V||c-Math.max(o.floor,s.floor)<i-V||c<r+i-V},ae=(e,t,n,r,i)=>{let a=(n-B)**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=re((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||!ie(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-B)**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=re((m*c+h*p)/(c*c+p*p),0,1);if((m-g*c)**2+(h-g*p)**2<f&&!ie(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]},se=(n,r,a,o,s)=>{n.x+=r,n.z+=a,ae(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*R;n.y+=(n.vy+u)/2*R,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+V:n.y<c)&&(n.y=c,n.vy<=0&&(n.vy=0,n.ground=!0)),n.x=U(n.x),n.y=U(n.y),n.z=U(n.z),n.vy=U(n.vy)},ce=(e,t,n)=>{let i=(t.keys&u.FIRE)!==0;e.cool=Math.max(0,e.cool-1),e.yaw=H(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*R*(i?.5:1)/(Math.hypot(a,o)||1),[c,l]=ne(e.yaw);return se(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},le=.55,ue=6,de=(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*z/t),Math.sin(e*z/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},fe=e=>{let t=[];for(let n=0;n<ue;n++){let r=n*z/ue;t.push(...de([[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:de([[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))}},pe=.3,me=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]},he=[[J.body,J.arm,J.head,J.gore,J.gore,J.chase],[J.shell,J.fin,J.shell,J.gore,J.chase]],ge=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]},_e=(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)},ve=e=>e<.25?-.8*Math.sin(e*4*Math.PI):2*Math.sin((e-.25)*Math.PI/.75),ye=(e,t,n,r)=>{let i=Math.sin(n*me)*.6,a=o*.44,s=o*.8,[c,l]=[-1,1].map(e=>Y(t,e*.16,a,0));_e(e,c,t.yaw,i,[.09,a/2,.09],J.leg),_e(e,l,t.yaw,-i,[.09,a/2,.09],J.leg),_e(e,Y(t,-.35,s,0),t.yaw,-i*.8,[.07,.34,.07],J.arm),_e(e,Y(t,.35,s,0),t.yaw,i*.8+(r>0?ve(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,ge(t.chase),-2)},be=K(de([[0,0],[.18,.06],[s,.32],[s*.93,.5],[.22,.78],[0,c]],8),J.shell),xe=(e,t,n)=>{let r=Math.sin(n*2+t.id)*.06,i=[t.x,t.y+r,t.z];q(e,be,i,W(0,Math.PI/2),[0,0,0],1);for(let r=0;r<4;r++){let a=n*1.5+r*z/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,ge(t.chase),-2)},Se=(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)}},Ce=.05,we=.3,Te=96,Ee=64,De=12,Oe=.3,ke=.15,Ae=.4,je=.5,Me=.9,Ne=.3,Pe=14,Fe=4.4,Ie=.035,Le=.03,Re=30,ze=({r:e,t})=>{let n=t/Oe;return n<1?e*Math.sqrt(n)*(1-n*n*n):0},Be=(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)}}},Ve=(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<Te&&_.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()*z,d()],o=Math.sqrt(1-a*a)*r*(.5+e()*.5);m(t,[Math.cos(n)*o,a*r,Math.sin(n)*o],we*(.6+e()*.4),i)}},g=(e,t)=>{_.blasts.push({p:e,r:t,t:0}),_.blasts.splice(0,_.blasts.length-De)},_={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*Fe),a+=(+(m>.5*r&&m<1)-a)*p,l=e,_.dead=Math.max(0,Math.min(1,_.dead+(f?r:-r)/je));let h=_.dead*_.dead*(3-2*_.dead);_.bob=Math.sin(i)*Ie*a-h*(n-Ne);let g=+!!(t&u.RIGHT)-!!(t&u.LEFT);s+=(g*Le-s)*Math.min(1,r*8),_.roll=s+h*Me,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(Re,c+(t&u.FIRE?60:-25)*r)),_.spin=(_.spin+c*r)%z;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<Oe);for(let e of _.gibs)e.life-=r,e.rest||v(e,r);_.gibs=_.gibs.filter(e=>e.life>0)},hit(){_.hurt=ke},pickup(e){[_.gain,_.gainC]=[Ae,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=Ce,o=.012):_.flashes.set(t.id,Ce);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,we*(.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=he[_.herd.get(n)?.kind??0]??he[0],s=10+Math.floor(e()*7);for(let n=0;n<s;n++){let n=e()*z,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()*z,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-Ee),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,pe)}},v=(e,t)=>{e.v[1]-=Pe*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 _},He=[[1,1,1],[.95,.15,.1],[.2,.4,1],[1,.85,.15]],Ue=(e,t=1)=>`rgba(${e.map(e=>Math.round(e*255))},${t})`,We=.3,Ge=[.25,1,.45],Ke=[.85,.1,.1],qe=[.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)},Je=(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=He[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,Ke)}else X(e,c,[0,.17,0],[.1,.1,.025],s,l,-2),X(e,c,[0,.17,0],[.04,.04,.035],s,qe),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)},Ye=({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)]},Xe=(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)},Ze=(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=He[i];for(let i of t.edges.filter(e=>e.front==n&&e.back>=0)){let[n,a]=Ye(t,i),o=Math.ceil(Math.hypot(i.bx-i.ax,i.bz-i.az)/We);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)}Xe(e,i,n+.1,.04,.04,r),Xe(e,i,a-.1,.04,.04,r)}}if(i!==void 0&&!t.barred.has(i)){let r=Ge.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]=Ye(t,n);for(let t of[i+.04,a-.04])Xe(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)}}},Qe=(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)},$e=(e,t,n,r)=>{for(let t of n)Je(e,t,r);Ze(e,t,r),Qe(e,t,r)},et={TITLE:0,NOTE:1,END:2},tt=[2,3,6],nt=`h1,h2,h3,h4,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}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}`,rt=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>`);let t=t=>[...e.querySelectorAll(t)],[n,r]=[t(`ul li`),t(`ol li`)],i=[`h1`,`h2`,`h3`].map(t=>e.querySelector(t)),a=e.querySelector(`h4`);r.forEach((e,t)=>e.style.background=Ue(He[t+1]));let o=tt.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,say(e,t){i[e].textContent=t,i[e].hidden=!1,o[e]=tt[e]},update(e){o.forEach((t,n)=>{t>0&&(o[n]=t-e)<=0&&(i[n].hidden=!0)})}}},it=.0025,at=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},st=e=>ot[e]??0,ct=e=>{let t=new AbortController,n=(e,n,r)=>e.addEventListener(n,r,{signal:t.signal}),i={yaw:0,pitch:0,keys:0,locked:()=>e.getRootNode().pointerLockElement==e,destroy:()=>t.abort()};n(e,`click`,()=>{Promise.resolve(e.requestPointerLock()).catch(()=>{})}),n(document,`mousemove`,e=>{i.locked()&&(i.yaw=((i.yaw-e.movementX*it)%at+at)%at,i.pitch=Math.max(-1.55,Math.min(r,i.pitch-e.movementY*it)))}),n(document,`keydown`,e=>{let t=st(e.code);t&&i.locked()&&(i.keys|=t,e.preventDefault())}),n(document,`keyup`,e=>{i.keys&=~st(e.code)}),n(document,`mousedown`,e=>{e.button==0&&i.locked()&&(i.keys|=u.FIRE)}),n(document,`mouseup`,e=>{e.button==0&&(i.keys&=~u.FIRE)});let a=()=>{i.keys=0};return n(window,`blur`,a),n(document,`pointerlockchange`,()=>i.locked()||a()),i},lt=e=>{for(let t=0;t<2;t++)e=Math.imul(e^e>>>16,73244475);return(e^e>>>16)>>>0},ut=(e,t,n)=>{let[r,i,o,s]=[Math.sin(e),Math.cos(e),Math.sin(t),Math.cos(t)],c=lt(n+1),l=(c&65535)/65536*z,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]},dt=(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},ft=(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},pt=({id:n,x:r,y:i,z:a})=>({id:n,x:r,y:i,z:a,r:e,h:t}),mt=({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}},ht=(e,t,r,i)=>{let a=[t.x,t.y+n,t.z],o=ut(t.yaw,t.pitch,r),s=dt(e,a,o,100),c=-1;for(let e of i){let n=e.id===t.id?1/0:ft(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}},gt=120,_t=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}),vt=(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}),yt=(e,t,n)=>H(e+(((t-e+Math.PI)%z+z)%z-Math.PI)*n),bt=(e,t)=>(t-e&65535)<32768,xt=(e,t,n)=>({...t,...vt(e,t,n),yaw:yt(e.yaw,t.yaw,n),pitch:e.pitch+(t.pitch-e.pitch)*n}),St=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?xt(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,...vt(e,t,n),yaw:yt(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>gt&&i.shift(),a&&(o=Z(a),c&&ce(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=ht(t,a,d.seq,[...o.map(pt),...r.map(mt)]),s.hit>=16&&l.set(s.hit,d.seq)}return d},snapshot:(e,r)=>{u.push({t:r,s:e}),u.length>_t&&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=>!bt(e.seq,s.ack)),l.forEach((t,n)=>{let r=e=>e.monsters.some(e=>e.id===n);bt(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&&ce(a,e,t)}))},monsters:h,bullets:e=>m(e,e=>e.bullets,(e,t,n)=>({...t,...vt(e,t,n)})),level:e=>{t=e,u.length=0,l.clear(),a=o=s=void 0},shot:()=>s,me:e=>a&&o?xt(o,a,Math.max(0,Math.min(1,e))):void 0,others:p}},Ct={SPOT:0,POINT:1},wt=[1.2,1.1,.9],Tt=[3,1.4,.4],Et=Math.cos(.436),Dt=.5,Ot=2,kt=4,Q=(e,t,n)=>({kind:Ct.POINT,p:e,d:[0,0,0],cone:0,range:t,color:n,shadow:!1}),At=(e,t,n,r,i,a=!1)=>({...Q(e,r,i),kind:Ct.SPOT,d:t,cone:n,shadow:a}),jt=(e,...t)=>e.map((e,n)=>e+t.reduce((e,[t,r])=>e+t[n]*r,0)),Mt=(e,t)=>e.map(e=>e*t),Nt=({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(At(jt(e,[u,.2],[d,-.2]),f,Et,25,wt,!0)),o.flash>0&&p.push(At(jt(e,[u,.26],[d,-.24],[f,.6+le*.8]),f,Dt,8,Tt,!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(At(jt(t,[a,.35]),a,Et,25,wt,n<Ot)),o.flashes.has(e.id)&&h.push(Q(jt([e.x,e.y+1.25,e.z],[r,.36],[i,-.12],[a,.8]),6,Tt))});for(let e of o.blasts){let t=ze(e);t>0&&h.push(Q(e.p,6,Mt(Tt,t*6)))}o.hurt>0&&h.push(Q(e,4,Mt([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,kt).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,Mt([.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,Mt([.2,1.5,.3],e)))}}}return p.concat(h.sort((e,t)=>m(e.p)-m(t.p)).slice(0,16-p.length))},Pt=1.5,Ft=e=>{let t=Math.floor(e*10/60);return`${Math.floor(t/600)}:${String(Math.floor(t/10)%60).padStart(2,`0`)}.${t%10}`},It=({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],Lt=({lvl:e,you:t,predictor:n,rd:r,delays:i,fx:a,hud:o})=>{let s=-1,c=-1,l=/* @__PURE__ */ new Map,u={lvl:e,items:[],dead:!1,alive:e=>l.get(e)!==0,snapshot(e){let d=t(),f=e.level*2+ +e.hard;if(f!=s){let t=O[e.level];if(!t)return;s=f,u.lvl=g(t),u.items=[],l=/* @__PURE__ */ new Map,c=-1,n.level(u.lvl),r?.level(u.lvl),a.reset(u.lvl),i.forEach(e=>e.clear()),o.say(et.TITLE,`Level ${e.level+1}${e.hard?`
|
|
2
|
+
Hard mode`:``}`)}let p=e.players.find(e=>e.id==d),h=l.get(d);p&&h!==void 0&&p.hp<h&&a.hit(),l=new Map(e.players.map(e=>[e.id,e.hp]));for(let t of u.items)p&&!e.items.some(e=>e.id==t.id)&&Math.hypot(t.x-p.x,t.z-p.z)<Pt&&a.pickup(He[t.kind]);u.items=e.items,e.phase!=c&&(c=e.phase,o.say(et.NOTE,c==m.RETURN?`Back to the start!`:`Find the exit`)),u.dead=p?.hp===0,o.hp(p?.hp??0),o.keys(e.keys),o.dead(u.dead)},end:(e,t)=>o.say(et.END,`Run complete\n${Ft(e)}${t?` (hard)`:``}\nNext run: Hard mode`)};return u},Rt=Object.keys(h).length,zt=(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},Bt=(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)=>zt((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},Vt=(e,t,n,r,i)=>{let[a,o]=[0,.5];for(let s=0;s<r;s++,o/=2)a+=o*Bt(e*(1<<s),t*(1<<s),n<<s,i+s);return a/(1-o*2)},Ht=(e,t,n)=>e.map((e,r)=>e+(t[r]-e)*n),$=(e,t)=>e.map(e=>e*t),Ut=[];Ut[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*Bt(e*16,t*16,16,5);return a<.04||o<.08?$([165,160,150],.7+.3*s):$([170,78,56],(.8+.4*zt(i,n,1))*s*(.85+.15*o))},Ut[h.TILE]=(e,t)=>{let[n,r]=[Math.floor(e*4),Math.floor(t*4)],i=.9+.2*Bt(e*16,t*16,16,7);return e*4%1<.04||t*4%1<.04?$([85,85,80],i):$([196,190,172],i*(.88+.08*(n+r&1)+.1*zt(n,r,2)))},Ut[h.LAVA]=(e,t)=>{let n=Vt(e*4,t*4,4,4,11),r=Math.max(0,1-Math.abs(n-.5)*7)**2;return Ht(Ht([55,8,4],[230,70,8],n),[255,215,90],r)},Ut[h.STONE]=(e,t)=>$([128,124,120],.45+.7*(Vt(e*8,t*8,8,4,3)*1.3+.1*zt(Math.floor(e*128),Math.floor(t*128),4)));var Wt=()=>{let e=new Uint8ClampedArray(Rt*128*128*4);return Ut.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},Gt=[.05,.045,.05],Kt=1<<18,qt=2,Jt=512,Yt=.3,Xt=.55,Zt=`#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);}`,
|
|
6
|
-
precision highp float;precision highp sampler2DArray;
|
|
7
|
-
in vec3 P,N;in vec4 C;uniform vec3 E;uniform float T;uniform
|
|
5
|
+
void main(){P=p;N=n;C=c;gl_Position=m*vec4(p,1);}`,Qt=`#version 300 es
|
|
6
|
+
precision highp float;precision highp sampler2DArray;precision highp sampler2DArrayShadow;
|
|
7
|
+
in vec3 P,N;in vec4 C;uniform vec3 E;uniform float T,Z;uniform int Q;
|
|
8
|
+
uniform vec4 A[16],B[16],K[16];uniform mat4 M[4];
|
|
9
|
+
uniform sampler2DArray S;uniform sampler2DArrayShadow D;out vec4 o;
|
|
8
10
|
void main(){
|
|
11
|
+
if(Z<0.)return;
|
|
9
12
|
float L=C.z,s=step(0.,L),g=step(abs(L-${h.LAVA}.),.5)+step(L,-1.5);
|
|
10
|
-
vec3 c=mix(vec3(C.xy,C.w),texture(S,vec3(C.xy/${
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
vec3 c=mix(vec3(C.xy,C.w),texture(S,vec3(C.xy/${qt}.+vec2(g*T*.01,0),max(L,0.))).rgb,s);
|
|
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
|
+
for(int i=0;i<16;i++){
|
|
16
|
+
if(i>=Q||g>0.)break;
|
|
17
|
+
vec3 d=A[i].xyz-P;float r=length(d),k=K[i].w,u=B[i].w;
|
|
18
|
+
d/=r;
|
|
19
|
+
float w=max(1.-r*r/(A[i].w*A[i].w),0.);
|
|
20
|
+
w*=w*smoothstep(u,u+(1.-u)*.4,-dot(d,B[i].xyz))*max(dot(n,d),0.);
|
|
21
|
+
if(w>0.&&k>=0.){
|
|
22
|
+
vec4 q=M[int(k)]*vec4(P+n*.03,1);q.xyz=q.xyz/q.w*.5+.5;
|
|
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/Jt},k,q.z-.0005));
|
|
25
|
+
w*=v/4.;}
|
|
26
|
+
l+=K[i].rgb*w;}
|
|
27
|
+
c*=mix(l,vec3(1.4),g);
|
|
28
|
+
o=vec4(mix(c,vec3(${Gt}),1.-exp(-.02*length(P-E))),1);}`,$t=(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])},en=(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)]},tn=({p:e,d:t,cone:n,range:r})=>$t(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]),nn=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==Ct.SPOT&&a<4?a++:-1;t.set([...e.p,e.range],o*4),n.set([...e.d,e.kind==Ct.POINT?-9:e.cone],o*4),r.set([...e.color,s],o*4),s>=0&&i.set(tn(e),s*16)}),{n:o.length,maps:a,a:t,b:n,k:r,m:i}},rn=({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)},an=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 rn(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=an(i),u=Wt(),f=l.length*4,p=f+Kt,[m,h]=[[.55,.55,.6],[.2,.2,.23]],g={barrels:K(fe(10).barrels,m),body:K(fe(10).body,h)},_={barrels:K(fe(5).barrels,m),body:K(fe(5).body,h)},v=[],y=[];for(let e of[[.1,.01,.03],[.01,.1,.03],[.03,.03,.05]])G(v,[0,0,-le-.04],e,0,[1,.85,.4],-2),G(y,[0,0,-le-.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,Zt],[a.FRAGMENT_SHADER,Qt]]){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,Jt,Jt,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,Rt,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(Gt[0],Gt[1],Gt[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=an(i),f=l.length*4,p=f+Kt,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=$t(r,o,s,j/M,h.roll);let N=[];for(let n of u){let[r,i]=ne(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)xe(N,e,P);else{let t=h.swings.get(e.id);ye(N,e,h.herd.get(e.id)?.walked??0,t?1-t/pe:0)}$e(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)Se(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]=[ze(e),e.t/Oe],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=nn(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,Jt,Jt),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,Yt),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,Xt),a.drawArrays(a.TRIANGLES,R+I/10,(N.length-I)/10)},project:(e,t,n)=>en(w,e,t,n),destroy(){n.removeEventListener(`webglcontextlost`,D),n.removeEventListener(`webglcontextrestored`,O),a.getExtension(`WEBGL_lose_context`)?.loseContext()}}},sn=1/60,cn=5,ln=(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}`+nt+`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=rt(f),m={roster:[],open:[],close:[]},h=e=>m[e].forEach(e=>e()),_=g(O[0]),v=St(_),y=ct(s),x=Ve(Math.random,_),S=Be(),C=Be(),w=-1,T;try{T=on(s,_)}catch{}let E=Lt({lvl:_,you:()=>w,predictor:v,rd:T,delays:[S,C],fx:x,hud:p}),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(),z=0,B=0,V=!1,H=i.socket??new WebSocket(i.url);H.binaryType=`arraybuffer`,H.onopen=()=>{M=!0,H.send(JSON.stringify({t:`join`,name:i.name})),h(`open`)},H.onclose=()=>{M=!1,N||=`Connection closed`,h(`close`)},H.onmessage=({data:e})=>{if(typeof e!=`string`){let t=te(e);if(t){let e=performance.now();E.snapshot(t),v.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]=[It(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])),v.you(w=t.you),c.textContent=`Players: ${D.length}`,h(`roster`)):t?.t==`full`?N=`Room is full`:t?.t==`end`&&E.end(t.ticks,t.hard)};let ne=e=>{let t=j.get(e);return t||(j.set(e,t=document.createElement(`b`)),f.append(t)),t},U=()=>{B=requestAnimationFrame(U);let e=performance.now(),i=R;if(z=Math.min(z+(e-R)/1e3,cn*sn),R=e,!P){let e=v.me(0);e&&([y.yaw,y.pitch,P]=[e.yaw,e.pitch,!0]),z=0}for(;P&&z>=sn;z-=sn){let t=E.dead?0:y.keys,r=v.step({keys:t,yaw:y.yaw,pitch:y.pitch},e);M&&H.send(ee(r));let i=v.shot(),a=i&&v.me(1);i&&a&&x.shot(i,[a.x,a.y+n,a.z],!0)}let a=v.me(z/sn),o=v.others(e).filter(e=>E.alive(e.id)),s=v.monsters(e),c=v.bullets(e),f=a?[a.x,a.y+n,a.z]:[0,0,0];x.track(s,c);for(let t of S.due(e)){let e=o.find(e=>e.id==t.id);e&&x.shot(t,[e.x,e.y+n,e.z],!1,t.hit!=w)}for(let t of C.due(e))x.event(t,w);let m=Math.min((e-i)/1e3,.1);if(x.update(a,y.keys,m,E.dead),p.update(m),a&&T){let t=Math.max(-1.55,Math.min(r,y.pitch+x.shakePitch));T.frame([f[0],f[1]+x.bob,f[2]],y.yaw+x.shakeYaw,t,o,k,x,s,c,E.items,Nt({eye:[f[0],f[1]+x.bob,f[2]],yaw:y.yaw,pitch:y.pitch,dead:E.dead,others:o,fx:x,bullets:c,lvl:E.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(E.lvl,f,n)?T?.project(...n):void 0,i=ne(e.id);h.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)h.has(e)||(t.remove(),j.delete(e));for(let[e,t]of[[u,x.hurt*2],[d,x.gain*.8]])e.style.opacity=String(t);d.style.background=Ue(x.gainC);let g=N||(M?P?y.locked()?``:`Click to play`:`Joining…`:`Connecting…`);l.textContent!=g&&(l.textContent=g)};return B=requestAnimationFrame(U),{on:(e,t)=>void m[e].push(t),players:()=>D,destroy(){V||(V=!0,cancelAnimationFrame(B),y.destroy(),T?.destroy(),H.onopen=H.onclose=H.onmessage=null,H.close(),document.exitPointerLock(),a.remove())}}};export{ln as tinyFps};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Bullet, Level, PlayerState } from '../shared/types';
|
|
2
|
+
import type { Effects } from './effects';
|
|
3
|
+
import type { Vec3 } from './mesh';
|
|
4
|
+
export declare const LIGHT: {
|
|
5
|
+
/** A cone from p along d: flashlights, muzzle flashes. */
|
|
6
|
+
readonly SPOT: 0;
|
|
7
|
+
/** All around p: explosions, bursts, the exit, the goal. */
|
|
8
|
+
readonly POINT: 1;
|
|
9
|
+
};
|
|
10
|
+
export interface Light {
|
|
11
|
+
/** LIGHT kind. */
|
|
12
|
+
kind: number;
|
|
13
|
+
p: Vec3;
|
|
14
|
+
/** SPOT: unit direction of the cone's axis. Ignored for a POINT. */
|
|
15
|
+
d: Vec3;
|
|
16
|
+
/** SPOT: cosine of the cone's half-angle. Ignored for a POINT. */
|
|
17
|
+
cone: number;
|
|
18
|
+
/** Metres at which it has faded to nothing. */
|
|
19
|
+
range: number;
|
|
20
|
+
/** Linear RGB; above 1 for a bright flash. */
|
|
21
|
+
color: Vec3;
|
|
22
|
+
/** Casts shadows. Only SPOT lights do; the first MAX_SHADOWS of them in the list get a map. */
|
|
23
|
+
shadow: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** Lights the renderer takes at most, in list order: put the important ones first. */
|
|
26
|
+
export declare const MAX_LIGHTS = 16;
|
|
27
|
+
/** Shadow maps the renderer keeps, one per shadowed SPOT. */
|
|
28
|
+
export declare const MAX_SHADOWS = 4;
|
|
29
|
+
export interface Scene {
|
|
30
|
+
/** The own eye (bob included) and look angles, as the camera has them. */
|
|
31
|
+
eye: Vec3;
|
|
32
|
+
yaw: number;
|
|
33
|
+
pitch: number;
|
|
34
|
+
/** The own player is dead: no flashlight. */
|
|
35
|
+
dead: boolean;
|
|
36
|
+
/** The living other players, interpolated. */
|
|
37
|
+
others: PlayerState[];
|
|
38
|
+
fx: Effects;
|
|
39
|
+
/** The monster bullets in flight, as drawn. */
|
|
40
|
+
bullets: Bullet[];
|
|
41
|
+
/** The level, with its live `barred` (the exit is open once it is not barred). */
|
|
42
|
+
lvl: Level;
|
|
43
|
+
/** Seconds, for pulsing lights. */
|
|
44
|
+
t: number;
|
|
45
|
+
}
|
|
46
|
+
/** The lights of this frame, most important first. */
|
|
47
|
+
export declare const gather: ({ eye, yaw, pitch, dead, others, fx, bullets, lvl, t }: Scene) => Light[];
|
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
import type { Bullet, Edge, Item, Level, Monster, PlayerState } from '../shared/types';
|
|
2
2
|
import type { Effects } from './effects';
|
|
3
|
+
import type { Light } from './lights';
|
|
3
4
|
import type { Vec3 } from './mesh';
|
|
4
|
-
/**
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Column-major view-projection matrix of basis(yaw, pitch, roll) at eye. t is the tangent of half the
|
|
7
|
+
* vertical field of view (70° by default), [N, F] the near and far clip distances.
|
|
8
|
+
*/
|
|
9
|
+
export declare const viewProj: (eye: Vec3, yaw: number, pitch: number, aspect: number, roll?: number, t?: number, [N, F]?: [number, number]) => Float32Array<ArrayBuffer>;
|
|
6
10
|
/** A world point on screen, in [0, 1] from the top left; undefined behind the camera. */
|
|
7
11
|
export declare const project: (m: Float32Array, x: number, y: number, z: number) => [number, number] | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The view-projection of a spot's shadow map: from its position along its axis, a square window
|
|
14
|
+
* just wide enough for the cone, clipped from 0.3 m (a flashlight sits inside its player's head)
|
|
15
|
+
* to its range.
|
|
16
|
+
*/
|
|
17
|
+
export declare const lightProj: ({ p, d, cone, range }: Light) => Float32Array<ArrayBuffer>;
|
|
18
|
+
/**
|
|
19
|
+
* The lights as the shader's uniform arrays (see FRAG): at most MAX_LIGHTS of them, and the first
|
|
20
|
+
* MAX_SHADOWS shadowed spots get a slot, whose matrix goes in m at 16 floats a slot.
|
|
21
|
+
*/
|
|
22
|
+
export declare const pack: (lights: Light[]) => {
|
|
23
|
+
n: number;
|
|
24
|
+
maps: number;
|
|
25
|
+
a: Float32Array<ArrayBuffer>;
|
|
26
|
+
b: Float32Array<ArrayBuffer>;
|
|
27
|
+
k: Float32Array<ArrayBuffer>;
|
|
28
|
+
m: Float32Array<ArrayBuffer>;
|
|
29
|
+
};
|
|
8
30
|
/** Vertical spans [y0, y1] an edge draws on its own side: the wall, or the steps of a portal. */
|
|
9
31
|
export declare const spans: ({ map }: Level, { front, back }: Edge) => [number, number][];
|
|
10
32
|
/** Floors and ceilings as fans, then every edge's walls as quads, in the vertex format above. */
|
|
@@ -15,7 +37,9 @@ export interface Renderer {
|
|
|
15
37
|
* and the effects as seen from eye, with the view model on top (not while fx.dead). colors maps
|
|
16
38
|
* player id to CSS.
|
|
17
39
|
*/
|
|
18
|
-
frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects, monsters: Monster[], bullets: Bullet[], items: Item[]
|
|
40
|
+
frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects, monsters: Monster[], bullets: Bullet[], items: Item[],
|
|
41
|
+
/** gather() in lights.ts: at most MAX_LIGHTS, the first MAX_SHADOWS shadowed spots mapped. */
|
|
42
|
+
lights: Light[]): void;
|
|
19
43
|
/** Builds the geometry of another level, drawn from the next frame on. */
|
|
20
44
|
level(lvl: Level): void;
|
|
21
45
|
/** A world point on screen as of the last frame, in [0, 1] from the top left. */
|
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.5.1",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|