@korial29/tiny-fps 0.10.0 → 0.12.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.
@@ -1,5 +1,5 @@
1
- import type { GameEvent } from '../shared/types';
2
1
  import type { Vec3 } from './mesh';
2
+ import type { Voice } from './sfx';
3
3
  export interface Audio {
4
4
  /**
5
5
  * Starts the AudioContext on a user gesture (browsers keep it suspended until one); the first
@@ -9,7 +9,7 @@ export interface Audio {
9
9
  /** Where the listener is and looks, each frame (yaw as a player's: 0 looks toward -z). */
10
10
  listen(eye: Vec3, yaw: number): void;
11
11
  /**
12
- * Plays the SOUND `id`. With `at`, panned left or right by its direction from the listener and
12
+ * Plays the sound `id` (an index into the layers). With `at`, panned left or right by its direction from the listener and
13
13
  * fainter with distance; without, centred (the own player's sounds). `gain` scales the volume.
14
14
  */
15
15
  play(id: number, at?: Vec3, gain?: number): void;
@@ -19,20 +19,7 @@ export interface Audio {
19
19
  /** Stops the music and closes the AudioContext. */
20
20
  destroy(): void;
21
21
  }
22
- export declare const createAudio: () => Audio;
23
- /** Plays the sound of a host event: where it happened, centred for the own player's hurt. */
24
- export declare const hear: (a: Audio, { type, id, x, y, z }: GameEvent, you: number) => void;
25
- /** Returns a function that plays CLOCK once a second while called with `on`; `now` in ms. */
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;
22
+ export declare const createAudio: (layers?: Voice[][]) => Audio;
36
23
  /** The mute choice of the last visit. Storage throws when blocked: no memory then. */
37
24
  export declare const savedMute: () => boolean;
38
25
  /** Flips mute, remembers it, and returns the new state. */
@@ -1,137 +1,22 @@
1
- import type { Bullet, GameEvent, Level, Monster, PlayerState, Shot } from '../shared/types';
1
+ import type { PlayerState } from '../shared/types';
2
2
  import type { Vec3 } from './mesh';
3
- export interface Spark {
4
- p: Vec3;
5
- v: Vec3;
6
- /** Seconds left. */
7
- life: number;
8
- /** Flat colour, orange when absent. */
9
- c?: number[];
10
- }
11
- /** A chunk of a dead monster: it flies, lands on the floor below, then shrinks away. */
12
- export interface Gib {
13
- p: Vec3;
14
- v: Vec3;
15
- yaw: number;
16
- /** Half the side of its cube, metres. */
17
- size: number;
18
- c: number[];
19
- /** Seconds left. */
20
- life: number;
21
- /** Floor height under it, as of the last sector it was in. */
22
- floor: number;
23
- /** Landed for good. */
24
- rest: boolean;
25
- }
26
- /** An explosion: a glow of radius r at its biggest, t seconds old. */
27
- export interface Blast {
28
- p: Vec3;
29
- r: number;
30
- t: number;
31
- }
32
- /** A puff of smoke: it rises and drifts, swells, then shrinks away over `life` seconds. */
33
- export interface Puff {
34
- p: Vec3;
35
- v: Vec3;
36
- /** Half the side of its cube at its biggest, metres. */
37
- r: number;
38
- yaw: number;
39
- /** Age and lifetime, seconds. */
40
- t: number;
41
- life: number;
42
- }
43
- /** What the client keeps of each monster it has drawn. */
44
- export interface Walker {
45
- x: number;
46
- z: number;
47
- /** Distance covered, metres: the limbs swing with it. */
48
- walked: number;
49
- kind: number;
50
- }
51
- /** What the renderer and the camera read; update and shot move it. */
3
+ /** What the renderer and the camera read; update moves it. */
52
4
  export interface Effects {
53
5
  /** Vertical eye offset, metres. */
54
6
  bob: number;
55
7
  /** Radians, positive leans right (strafing right). */
56
8
  roll: number;
57
- /** Camera yaw and pitch jitter, radians. */
58
- shakeYaw: number;
59
- shakePitch: number;
60
- /** Recoil, 1 at a shot down to 0. */
61
- kick: number;
62
- /** Barrel angle, radians. */
63
- spin: number;
64
- /** Seconds of own muzzle flash left. */
65
- flash: number;
66
- /** Seconds of flash left at each other shooter, by player id. */
67
- flashes: Map<number, number>;
68
- sparks: Spark[];
69
- gibs: Gib[];
70
- blasts: Blast[];
71
- smoke: Puff[];
72
9
  /** Dust motes, x y z each, in a box around the own eye; `lit` says which the flashlight shows. */
73
10
  motes: Float32Array;
74
- /** Seconds of the red hurt tint left. */
75
- hurt: number;
76
- /** Seconds left of the fade of a picked-up item's colour, and that colour (0 to 1 each). */
77
- gain: number;
78
- gainC: number[];
79
- /** 0 to 1: how far the camera has sunk and tilted since the own player died; the gun hides. */
80
- dead: number;
81
- /** Seconds of blow left at each monster, by id. */
82
- swings: Map<number, number>;
83
- /** Every monster seen so far, by id. Ids are bounded, so it is too. */
84
- herd: Map<number, Walker>;
85
- /** Unit heading of each bullet in flight, by id, once it has moved. */
86
- aim: Map<number, Vec3>;
87
- /**
88
- * Advances dt seconds: the own player (eased, undefined before the first snapshot), the held
89
- * keys and whether the own player is dead.
90
- */
91
- update(me: PlayerState | undefined, keys: number, dt: number, dead?: boolean): void;
92
- /** The own health dropped: the red tint. */
93
- hit(): void;
94
- /** An item of colour c was picked up near the own player: its colour fades over the screen. */
95
- pickup(c: number[]): void;
96
- /** A new level: drops every effect of the old one, and lets gibs land on the new `lvl`. */
97
- reset(lvl: Level): void;
98
- /**
99
- * A shot, from the shooter's eye; own ones kick the camera and the gun. No sparks with
100
- * `sparks` false: a shot that hit the viewer would burst them inside the camera.
101
- */
102
- shot(s: Shot, from: Vec3, own: boolean, sparks?: boolean): void;
103
- /** The monsters and bullets drawn this frame: how far each walked, which way each bullet flies. */
104
- track(monsters: Monster[], bullets: Bullet[]): void;
105
- /** A host event, once delayed to line up with the drawn monsters; `you` is the own player id. */
106
- event(e: GameEvent, you: number): void;
11
+ /** Advances dt seconds: the own player (eased, undefined before the first snapshot) and the held keys. */
12
+ update(me: PlayerState | undefined, keys: number, dt: number): void;
107
13
  }
108
14
  /** Motes, and the half sides of the box they live in: they wrap round it as the eye moves. */
109
15
  export declare const MOTES = 128;
110
- export declare const BLAST = 0.3;
111
- /** Seconds the hit vignette and the pickup fade take to go out. */
112
- export declare const HURT = 0.45;
113
- export declare const GAIN = 0.4;
114
- /** Half the side of an explosion's glow: it swells fast, then shrinks to nothing as it ends. */
115
- export declare const glow: ({ r, t }: Blast) => number;
116
- /** Half the side of a puff of smoke: it starts at a third, swells for half its life, then shrinks to nothing. */
117
- export declare const puff: ({ r, t, life }: Puff) => number;
118
- /** How opaque a puff of smoke is, 0 to 1: it comes in over a tenth of its life, then thins out to nothing. */
119
- export declare const fade: ({ t, life }: Puff) => number;
120
16
  /**
121
17
  * The motes the own flashlight shows, from the eye along the unit view direction f: x, y, z and a
122
- * brightness in (0, 1] each, fuller near the axis and the eye. None while the own player is dead.
18
+ * brightness in (0, 1] each, fuller near the axis and the eye.
123
19
  */
124
20
  export declare const lit: (fx: Effects, eye: Vec3, f: Vec3) => number[];
125
- /**
126
- * Holds what the host reported at `now` for INTERP_DELAY ms, so it fires in step with the others,
127
- * who are drawn that far in the past. Keeps at most `max`: a hidden tab does not grow it.
128
- */
129
- export declare const createDelay: <T>(max?: number) => {
130
- /** Forgets what is held: it belongs to a level that is gone. */
131
- clear(): void;
132
- push(items: T[], now: number): void;
133
- /** What is due at `now`, oldest first. */
134
- due(now: number): T[];
135
- };
136
- /** rand in [0, 1): injectable so the tests are exact. The level lets gibs land and bounce off walls. */
137
- export declare const createEffects: (rand?: () => number, level?: Level) => Effects;
21
+ /** rand in [0, 1): injectable so the tests are exact. */
22
+ export declare const createEffects: (rand?: () => number) => Effects;
@@ -1,33 +1,9 @@
1
- /** Slots of say(): a title, a hint under it; and seconds each stays up (the end screen is the third). */
2
- export declare const SAY: {
3
- readonly TITLE: 0;
4
- readonly NOTE: 1;
5
- };
6
- /** A player's line of the end screen. */
7
- export type Score = [name: string, color: string, kills: number, deaths: number];
8
1
  export declare const HUD_CSS: string;
9
2
  export interface Hud {
10
- /** The own health: the bar's width, number and colour. It flashes on a rise and shakes on a fall. */
11
- hp(n: number): void;
12
- /** The keys held, as the snapshot's bit set (1 << ITEM.KEY_*). */
13
- keys(bits: number): void;
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
3
  /** 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;
4
+ title(status: string, name: string): void;
25
5
  /** Shows or hides the muted mark. */
26
6
  mute(on: boolean): void;
27
- /** Shows text in a SAY slot, for that slot's time. */
28
- say(slot: number, text: string): void;
29
- /** Advances dt seconds. */
30
- update(dt: number): void;
31
7
  }
32
8
  /** Appends the HUD to `screen`, whose stylesheet has HUD_CSS. */
33
9
  export declare const createHud: (screen: HTMLElement) => Hud;
@@ -14,7 +14,7 @@ export interface Controls {
14
14
  destroy(): void;
15
15
  }
16
16
  /**
17
- * Click the canvas to lock the pointer; while locked the mouse looks, the keys move, the left
18
- * button fires and M calls `onMute`.
17
+ * Click the canvas to lock the pointer; while locked the mouse looks, the keys move and M calls
18
+ * `onMute`.
19
19
  */
20
20
  export declare const createInput: (canvas: HTMLCanvasElement, onMute?: () => void) => Controls;
@@ -1,10 +1,9 @@
1
- import type { Bullet, Level, PlayerState } from '../shared/types';
2
- import type { Effects } from './effects';
1
+ import type { Level, PlayerState } from '../shared/types';
3
2
  import type { Vec3 } from './mesh';
4
3
  export declare const LIGHT: {
5
- /** A cone from p along d: flashlights, muzzle flashes. */
4
+ /** A cone from p along d: flashlights. */
6
5
  readonly SPOT: 0;
7
- /** All around p: explosions, bursts, the exit, the goal. */
6
+ /** All around p: the lava. */
8
7
  readonly POINT: 1;
9
8
  };
10
9
  export interface Light {
@@ -31,14 +30,9 @@ export interface Scene {
31
30
  eye: Vec3;
32
31
  yaw: number;
33
32
  pitch: number;
34
- /** The own player is dead: no flashlight. */
35
- dead: boolean;
36
- /** The living other players, interpolated. */
33
+ /** The other players, interpolated. */
37
34
  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). */
35
+ /** The level, for its lava. */
42
36
  lvl: Level;
43
37
  /** Seconds, for pulsing lights. */
44
38
  t: number;
@@ -51,5 +45,5 @@ interface Pool {
51
45
  /** The lava sectors of a level, derived once per Level object: they never change. */
52
46
  export declare const lava: (lvl: Level) => Pool[];
53
47
  /** The lights of this frame, most important first. */
54
- export declare const gather: ({ eye, yaw, pitch, dead, others, fx, bullets, lvl, t }: Scene) => Light[];
48
+ export declare const gather: ({ eye, yaw, pitch, others, lvl, t }: Scene) => Light[];
55
49
  export {};
@@ -2,7 +2,7 @@ export type Vec3 = [number, number, number];
2
2
  /**
3
3
  * Floats per vertex: position, normal, then c. A map vertex has c = (u, v, texture layer, light),
4
4
  * u and v in metres. A player vertex has layer -1 and its flat colour in c.x, c.y, c.w; layer -2 is
5
- * the same colour, bright and unlit (flashes, sparks, eyes).
5
+ * the same colour, bright and unlit (dust, visors, markers).
6
6
  */
7
7
  export declare const STRIDE = 10;
8
8
  /**
@@ -15,10 +15,24 @@ export declare const basis: (yaw: number, pitch: number, roll?: number) => [Vec3
15
15
  * by yaw about its own vertical axis (local forward, -z, ends up along forward(yaw)).
16
16
  */
17
17
  export declare const pushBox: (out: number[], [cx, cy, cz]: Vec3, [hx, hy, hz]: Vec3, yaw: number, color: number[], layer?: number) => void;
18
- /** gun.ts vertices (position, normal) given a flat colour, in the vertex format above. */
18
+ /**
19
+ * Revolves a profile of [radius, length] points around the axis through `at` along -z: `length`
20
+ * runs forward from `at`. Returns triangles as x, y, z, nx, ny, nz per vertex, `sides` quads of 2
21
+ * triangles per profile segment. The profile goes from back to front and closes on the axis, so
22
+ * the normals (smooth around the ring, flat along the profile) point outward.
23
+ */
24
+ export declare const lathe: (profile: [number, number][], sides: number, at?: Vec3) => number[];
25
+ /** lathe() vertices (position, normal) given a flat colour, in the vertex format above. */
19
26
  export declare const dress: (v: number[], [r, g, b]: number[]) => number[];
20
27
  /**
21
- * Appends gun-space vertices (x right, y up, -z forward) scaled by k, turned by spin about z, then
22
- * carried to the world: axes `[r, u, f]` at eye, moved by off = (right, up, forward) along them.
28
+ * Appends model-space vertices (x right, y up, -z forward) scaled by k (one factor, or one per
29
+ * axis), then carried to the world: axes `[r, u, f]` at eye, moved by off = (right, up, forward)
30
+ * along them. `tint` multiplies the flat colour. Written without allocations: a body is placed a
31
+ * thousand vertices at a time.
32
+ */
33
+ export declare const place: (out: number[], src: number[], eye: Vec3, [r, u, f]: Vec3[], off: Vec3, k: number | Vec3, tint?: number[]) => void;
34
+ /**
35
+ * Axes [r, u, f] with f along the unit vector `to` and r as near `side` as it can be: the frame of
36
+ * a bone, which `place` takes. Right-handed like `basis`.
23
37
  */
24
- export declare const place: (out: number[], src: number[], eye: Vec3, [r, u, f]: Vec3[], off: Vec3, k: number, spin?: number) => void;
38
+ export declare const aim: (to: Vec3, side: Vec3) => [Vec3, Vec3, Vec3];
@@ -1,4 +1,4 @@
1
- import type { Bullet, Input, Level, Monster, PlayerState, Shot, Snapshot } from '../shared/types';
1
+ import type { Input, Level, PlayerState, Snapshot } from '../shared/types';
2
2
  export interface Predictor {
3
3
  /** The own player id, from the roster. Snapshots before it are only used for the others. */
4
4
  you(id: number): void;
@@ -10,22 +10,6 @@ export interface Predictor {
10
10
  * With `now` (ms, performance.now()) the input carries the view tick the others are drawn at.
11
11
  */
12
12
  step(i: Omit<Input, 'seq' | 'view'>, now?: number): Input;
13
- /**
14
- * The shot the last step fired, resolved with fire() against the living others(now) and
15
- * monsters(now) of that step (a monster this predictor already shot dead, and the host has not
16
- * acked yet, is not a target); undefined when it did not fire (a dead own player never does).
17
- * Replays on a snapshot never fire again.
18
- */
19
- shot(): Shot | undefined;
20
- /**
21
- * Switches to another level (a snapshot with a new `level` or `hard`): prediction, replay and
22
- * interpolation use it from now on, and the snapshots of the previous level are dropped; the own
23
- * player waits for the next snapshot, as at the start. Each snapshot also bars the level with
24
- * its keys and phase (bar() in level.ts) before the replay. A gate that opens between a
25
- * snapshot and the inputs the host has not applied yet is the one thing prediction cannot know:
26
- * it corrects at the next snapshot.
27
- */
28
- level(lvl: Level): void;
29
13
  /** A decoded snapshot, received at `now` (ms, performance.now()). */
30
14
  snapshot(s: Snapshot, now: number): void;
31
15
  /**
@@ -36,14 +20,5 @@ export interface Predictor {
36
20
  me(alpha: number): PlayerState | undefined;
37
21
  /** The other players at now - INTERP_DELAY; a player missing from the latest snapshot is gone. */
38
22
  others(now: number): PlayerState[];
39
- /**
40
- * The living monsters at now - INTERP_DELAY, interpolated like others() (yaw along the shortest
41
- * arc). Unlike others(), presence follows the newer snapshot of the interpolation pair, not the
42
- * latest: a monster is drawn until the pair reaches the first snapshot that lacks it, as late
43
- * as its DIE event is shown.
44
- */
45
- monsters(now: number): Monster[];
46
- /** The bullets in flight at now - INTERP_DELAY, interpolated and kept the same way (until their BOOM). */
47
- bullets(now: number): Bullet[];
48
23
  }
49
- export declare const createPredictor: (first: Level) => Predictor;
24
+ export declare const createPredictor: (lvl: Level) => Predictor;
@@ -1,4 +1,4 @@
1
- import type { Bullet, Edge, Item, Level, Monster, PlayerState } from '../shared/types';
1
+ import type { Edge, Level, PlayerState } from '../shared/types';
2
2
  import type { Effects } from './effects';
3
3
  import type { Light } from './lights';
4
4
  import type { Vec3 } from './mesh';
@@ -48,15 +48,12 @@ export declare const palette: ({ map }: Level) => Vec3[];
48
48
  export declare const levelVerts: (lvl: Level) => number[];
49
49
  export interface Renderer {
50
50
  /**
51
- * Draws one frame: the map, its gates, goal and items, the others, the monsters, their bullets
52
- * and the effects as seen from eye, with the view model on top (not while fx.dead). colors maps
53
- * player id to CSS.
51
+ * Draws one frame: the map, the others and the dust as seen from eye. colors maps player id to
52
+ * CSS.
54
53
  */
55
- frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects, monsters: Monster[], bullets: Bullet[], items: Item[],
54
+ frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects,
56
55
  /** gather() in lights.ts: at most MAX_LIGHTS, the first MAX_SHADOWS shadowed spots mapped. */
57
56
  lights: Light[]): void;
58
- /** Builds the geometry of another level, drawn from the next frame on. */
59
- level(lvl: Level): void;
60
57
  /** A world point on screen as of the last frame, in [0, 1] from the top left. */
61
58
  project(x: number, y: number, z: number): [number, number] | undefined;
62
59
  destroy(): void;
@@ -66,4 +63,4 @@ export declare const MAX_PIXELS: number;
66
63
  /** The canvas size in device pixels: the CSS size times the pixel ratio (2 at most), scaled down to MAX_PIXELS. */
67
64
  export declare const backing: (cw: number, ch: number, dpr: number) => [number, number];
68
65
  /** Throws when the browser has no WebGL2. */
69
- export declare const createRenderer: (canvas: HTMLCanvasElement, first: Level) => Renderer;
66
+ export declare const createRenderer: (canvas: HTMLCanvasElement, lvl: Level) => Renderer;
@@ -1,27 +1,34 @@
1
+ /**
2
+ * One oscillator: wave (0 square, 1 saw, 2 sine, 3 noise held for one period), hz, slide in octaves
3
+ * per second, attack, sustain and decay in seconds, vibrato depth, low-pass (0..1, 1 is off),
4
+ * arpeggio time and frequency multiplier, volume; optionally the seconds it starts late.
5
+ */
6
+ export type Voice = [
7
+ number,
8
+ number,
9
+ number,
10
+ number,
11
+ number,
12
+ number,
13
+ number,
14
+ number,
15
+ number,
16
+ number,
17
+ number,
18
+ number?
19
+ ];
1
20
  /** Sample rate of everything rendered here; audio.ts resamples through AudioBuffer if needed. */
2
21
  export declare const RATE = 44100;
3
- /** The sounds of the game. */
4
- export declare const SOUND: {
5
- /** The chaingun, one per shot. */
6
- readonly SHOT: 0;
7
- /** A monster's death. */
8
- readonly BOOM: 1;
9
- /** A player hurt: a blow or a bullet. */
10
- readonly HIT: 2;
11
- /** A pickup taken: health or a key. */
12
- readonly COLLECT: 3;
13
- /** A tick, once a second while the team runs back to the exit (RETURN). */
14
- readonly CLOCK: 4;
15
- /** A bullet bursting on a wall. */
16
- readonly BURST: 5;
17
- /** A heartbeat, looped by the client while the own health is low. */
18
- readonly HEART: 6;
19
- };
20
22
  /**
21
- * Renders the SOUND `id` as mono samples in [-1, 1] at RATE, deterministic (seeded noise), a few
22
- * tenths of a second long, silent at both ends (no click).
23
+ * The sounds of the game: one entry per sound, its voices layered, an index per sound for
24
+ * audio.play. None yet: the footsteps, the dash and the grab of the next steps go here.
25
+ */
26
+ export declare const LAYERS: Voice[][];
27
+ /**
28
+ * Renders the sound `id` of `layers` as mono samples in [-1, 1] at RATE, deterministic (seeded
29
+ * noise), silent at both ends (no click).
23
30
  */
24
- export declare const render: (id: number) => Float32Array;
31
+ export declare const render: (id: number, layers?: Voice[][]) => Float32Array;
25
32
  /**
26
33
  * The music: a loop of four bars in A minor at 108 bpm (whole beats, whole samples), mono samples
27
34
  * in [-1, 1] at RATE, deterministic, whose end joins its start without a click. Quiet enough to
@@ -0,0 +1,21 @@
1
+ import type { PlayerState } from '../shared/types';
2
+ /** What the client keeps of each body it draws: the limbs follow the distance, the pace the speed. */
3
+ export interface Gait {
4
+ x: number;
5
+ z: number;
6
+ /** Distance covered, metres. */
7
+ walked: number;
8
+ /** Eased velocity on x and z, m/s. */
9
+ vx: number;
10
+ vz: number;
11
+ }
12
+ /** Moves the gait of `id` to (x, z) after dt seconds. A jump of metres (a respawn) is not a walk. */
13
+ export declare const follow: (book: Map<number, Gait>, id: number, x: number, z: number, dt: number) => Gait;
14
+ /** 0 standing to 1 striding: the limbs swing less when slow. */
15
+ export declare const pace: (g: Gait) => number;
16
+ /**
17
+ * Appends another player as a soldier: `color` (r, g, b) for the body, darker for the legs, the
18
+ * helmet and the gloves, a visor that glows in it. The legs stride with `walked` and `pace`, and
19
+ * each arm swings against the leg on its side, empty handed.
20
+ */
21
+ export declare const soldier: (out: number[], p: PlayerState, color: number[], walked: number, pace: number) => void;
@@ -22,17 +22,9 @@ export declare const GRAVITY = 20;
22
22
  export declare const MAX_PITCH = 1.55;
23
23
  /** A floor at most this much higher is walked onto; a higher one needs a jump. */
24
24
  export declare const STEP_H = 0.5;
25
- /** Steps between two chaingun shots while the trigger is held: 60 / 5 = 12 shots per second. */
26
- export declare const FIRE_EVERY = 5;
27
- /** Speed factor while the trigger is held. */
28
- export declare const FIRE_SLOW = 0.5;
29
- /** Metres a shot reaches. */
30
- export declare const RANGE = 100;
31
- /** Largest angle, in radians, between a shot and the view direction. */
32
- export declare const SPREAD = 0.02;
33
25
  /**
34
- * Host ticks a shot may look back (0.5 s): the host rewinds the targets to the view tick of the
35
- * input that fired, clamped to this.
26
+ * Host ticks the history of the players goes back (0.5 s): the host rewinds the others to the
27
+ * view tick of an input, clamped to this.
36
28
  */
37
29
  export declare const MAX_REWIND = 30;
38
30
  /**
@@ -41,45 +33,6 @@ export declare const MAX_REWIND = 30;
41
33
  */
42
34
  export declare const INPUT_BURST = 10;
43
35
  export declare const MAX_PLAYERS = 16;
44
- /** Monsters alive at once at most; their ids run from MAX_PLAYERS to MAX_PLAYERS + MAX_MONSTERS - 1. */
45
- export declare const MAX_MONSTERS = 64;
46
- export declare const WALKER_R = 0.4;
47
- export declare const WALKER_H = 1.8;
48
- export declare const WALKER_SPEED = 2.5;
49
- export declare const FLYER_R = 0.45;
50
- export declare const FLYER_H = 0.9;
51
- /** A flyer's underside floats this high above the floor below it, ceilings allowing. */
52
- export declare const FLYER_HOVER = 1.2;
53
- export declare const FLYER_SPEED = 3.5;
54
- /** Each monster looks for players once per SIGHT_EVERY ticks (staggered), in a cone this wide. */
55
- export declare const SIGHT_EVERY = 60;
56
- export declare const SIGHT_COS: number;
57
- export declare const SIGHT_RANGE = 30;
58
- /** A monster that sees a player or dies alerts the others within ALERT_R that can see it. */
59
- export declare const ALERT_R = 12;
60
- /** A chasing monster this close (centre to centre, on the floor plane) swings, once per MELEE_EVERY. */
61
- export declare const MELEE_R = 1.4;
62
- export declare const MELEE_EVERY = 45;
63
- /** A chasing walker that sees its target fires once per SHOOT_EVERY ticks. */
64
- export declare const SHOOT_EVERY = 90;
65
- export declare const BULLET_SPEED = 12;
66
- export declare const BULLET_R = 0.15;
67
- /** Ticks a bullet lives at most. */
68
- export declare const BULLET_LIFE = 300;
69
- export declare const HEALTH = 9;
70
- /** A hit takes 1 health, then the player cannot be hurt for HIT_COOLDOWN ticks. */
71
- export declare const HIT_COOLDOWN = 60;
72
- /** Every DROP_EVERY-th kill of the team leaves a HEALTH pickup where the monster died. */
73
- export declare const DROP_EVERY = 4;
74
- export declare const HEAL = 3;
75
- /** A player whose axis comes this close to a pickup (on the floor plane) takes it. */
76
- export declare const PICKUP_R = 0.8;
77
- export declare const GOAL_R = 1;
78
- /** A dead player comes back at the level start after this long. */
79
- export declare const PLAYER_RESPAWN = 180;
80
- /** Hard mode (second run on): monster speed factor, and the share of SHOOT_EVERY and MELEE_EVERY. */
81
- export declare const HARD_SPEED = 1.3;
82
- export declare const HARD_RATE = 0.6;
83
36
  /** Longest player name, in characters (code points). */
84
37
  export declare const MAX_NAME = 16;
85
38
  export declare const RULES: Rules;
@@ -1,8 +1,6 @@
1
1
  import type { Level, MapDef, Sector } from './types';
2
2
  /** Joins every edge a→b with the sector that has b→a, if any: that edge is a portal. */
3
3
  export declare const compile: (map: MapDef) => Level;
4
- /** Bars the gates whose key is not in `keys` (bits 1 << ITEM.KEY_*), and the exit before RETURN. */
5
- export declare const bar: ({ map, barred }: Level, keys: number, phase: number) => void;
6
4
  /** Whether (x, z) is inside the sector, its edges included. */
7
5
  export declare const inside: ({ pts }: Sector, x: number, z: number) => boolean;
8
6
  /** Index of the first sector holding (x, z), -1 outside the map. */
@@ -1,7 +1,12 @@
1
1
  import type { MapDef } from './types';
2
2
  /**
3
3
  * The first sector map, a test bed for heights: a start room, a low corridor, a tall hall around a
4
- * lava pit, stairs up to a balcony. Each spot is reachable on foot; the pit is a 1 m drop. The goal
5
- * is on the balcony, the exit is the start room, and a health pack lies in the hall.
4
+ * lava pit, stairs up to a balcony. Each spot is reachable on foot; the pit is a 1 m drop.
6
5
  */
7
6
  export declare const HALL: MapDef;
7
+ /**
8
+ * The first rooftop, for the capture-the-flag game: a flat 40 x 40 m deck in the open, a 1 m
9
+ * parapet round it, a crate, a block and a platform with steps. Built as a grid of cells, one
10
+ * sector each: neighbours at one height are open to each other, and the edge is solid wall.
11
+ */
12
+ export declare const ROOF: MapDef;
@@ -1,7 +1,4 @@
1
1
  import type { Input, Level, PlayerState } from './types';
2
- type Pos = Pick<PlayerState, 'x' | 'y' | 'z'>;
3
- /** What walk() moves: a player, or a walker with the same feet, speed and floor contact. */
4
- type Walker = Pos & Pick<PlayerState, 'vy' | 'ground'>;
5
2
  export declare const TAU: number;
6
3
  /** An angle in [0, 2π). */
7
4
  export declare const norm: (a: number) => number;
@@ -12,26 +9,13 @@ export declare const forward: (yaw: number) => [x: number, z: number];
12
9
  * collisions of the cylinder (PLAYER_R, PLAYER_H) with the sectors of the level: it slides along
13
10
  * shut edges (see shut and push), stands on the highest floor under the circle (a step up to
14
11
  * STEP_H is climbed at once, a higher one needs a jump, a ledge is a fall), and bumps its head on
15
- * the lowest ceiling. Players and walkers share it, in place.
12
+ * the lowest ceiling, in place.
16
13
  */
17
- export declare const walk: (p: Walker, dx: number, dz: number, jump: boolean, lvl: Level) => void;
18
- /**
19
- * Moves a flyer (underside at p.y, radius FLYER_R, height FLYER_H) by (dx, dy, dz): sideways it is
20
- * stopped by solid walls and by openings too small for it, and it never steps (it flies over
21
- * steps and pits); then y is held between FLYER_HOVER above the highest floor under it and the
22
- * lowest ceiling minus FLYER_H, the ceiling winning in a low room. Below the hover height it
23
- * rises at FLYER_SPEED, so crossing from a pit to a ledge is not a jump; the floor itself is
24
- * never entered.
25
- */
26
- export declare const fly: (p: Pos, dx: number, dy: number, dz: number, lvl: Level) => void;
14
+ export declare const walk: (p: PlayerState, dx: number, dz: number, jump: boolean, lvl: Level) => void;
27
15
  /**
28
16
  * Applies one input for 1 / TICK_HZ s, in place: yaw and pitch from the input (pitch clamped to
29
17
  * MAX_PITCH), RUN_SPEED along the held keys (diagonals not faster), then walk().
30
- * The chaingun: `cool` counts down one per step, RUN_SPEED is scaled by FIRE_SLOW while KEY.FIRE
31
- * is held, and the step that finds it held with `cool` at 0 re-arms it to FIRE_EVERY and returns
32
- * true: the caller resolves a shot (one every FIRE_EVERY steps, the first at once).
33
18
  */
34
- export declare const move: (p: PlayerState, i: Input, lvl: Level) => boolean;
19
+ export declare const move: (p: PlayerState, i: Input, lvl: Level) => void;
35
20
  /** A player standing on the floor at spawn point n of the map (modulo the count). */
36
21
  export declare const spawn: (id: number, lvl: Level, n: number) => PlayerState;
37
- export {};
@@ -9,32 +9,12 @@ export type ServerText = {
9
9
  players: PlayerInfo[];
10
10
  } | {
11
11
  t: 'full';
12
- }
13
- /**
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. `stats` has one row per player still in the room, kills and
16
- * deaths over the whole run.
17
- */
18
- | {
19
- t: 'end';
20
- ticks: number;
21
- hard: boolean;
22
- stats: {
23
- id: number;
24
- kills: number;
25
- deaths: number;
26
- }[];
27
12
  };
28
13
  export declare const MSG_INPUT = 1;
29
14
  export declare const MSG_SNAPSHOT = 2;
30
15
  export declare const INPUT_BYTES = 11;
31
- export declare const SNAP_HEAD = 7;
32
- export declare const SNAP_PLAYER = 25;
33
- export declare const SNAP_SHOT = 14;
34
- export declare const SNAP_MONSTER = 16;
35
- export declare const SNAP_BULLET = 13;
36
- export declare const SNAP_EVENT = 14;
37
- export declare const SNAP_ITEM = 14;
16
+ export declare const SNAP_HEAD = 4;
17
+ export declare const SNAP_PLAYER = 24;
38
18
  /**
39
19
  * The input as the host will read it after encodeInput and decodeInput: yaw, pitch and view
40
20
  * rounded to the wire (an absent view stays absent here, and reads 0 on the host). The client