@korial29/tiny-fps 0.3.0 → 0.5.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.
@@ -59,14 +59,28 @@ export interface Effects {
59
59
  blasts: Blast[];
60
60
  /** Seconds of the red hurt tint left. */
61
61
  hurt: number;
62
+ /** Seconds left of the fade of a picked-up item's colour, and that colour (0 to 1 each). */
63
+ gain: number;
64
+ gainC: number[];
65
+ /** 0 to 1: how far the camera has sunk and tilted since the own player died; the gun hides. */
66
+ dead: number;
62
67
  /** Seconds of blow left at each monster, by id. */
63
68
  swings: Map<number, number>;
64
69
  /** Every monster seen so far, by id. Ids are bounded, so it is too. */
65
70
  herd: Map<number, Walker>;
66
71
  /** Unit heading of each bullet in flight, by id, once it has moved. */
67
72
  aim: Map<number, Vec3>;
68
- /** Advances dt seconds: the own player (eased, undefined before the first snapshot) and the held keys. */
69
- update(me: PlayerState | undefined, keys: number, dt: number): void;
73
+ /**
74
+ * Advances dt seconds: the own player (eased, undefined before the first snapshot), the held
75
+ * keys and whether the own player is dead.
76
+ */
77
+ update(me: PlayerState | undefined, keys: number, dt: number, dead?: boolean): void;
78
+ /** The own health dropped: the red tint. */
79
+ hit(): void;
80
+ /** An item of colour c was picked up near the own player: its colour fades over the screen. */
81
+ pickup(c: number[]): void;
82
+ /** A new level: drops every effect of the old one, and lets gibs land on the new `lvl`. */
83
+ reset(lvl: Level): void;
70
84
  /**
71
85
  * A shot, from the shooter's eye; own ones kick the camera and the gun. No sparks with
72
86
  * `sparks` false: a shot that hit the viewer would burst them inside the camera.
@@ -85,9 +99,11 @@ export declare const glow: ({ r, t }: Blast) => number;
85
99
  * who are drawn that far in the past. Keeps at most `max`: a hidden tab does not grow it.
86
100
  */
87
101
  export declare const createDelay: <T>(max?: number) => {
102
+ /** Forgets what is held: it belongs to a level that is gone. */
103
+ clear(): void;
88
104
  push(items: T[], now: number): void;
89
105
  /** What is due at `now`, oldest first. */
90
106
  due(now: number): T[];
91
107
  };
92
108
  /** rand in [0, 1): injectable so the tests are exact. The level lets gibs land and bounce off walls. */
93
- export declare const createEffects: (rand?: () => number, lvl?: Level) => Effects;
109
+ export declare const createEffects: (rand?: () => number, level?: Level) => Effects;
@@ -0,0 +1,21 @@
1
+ /** Slots of say(): a title, a hint under it, the end screen; and seconds each stays up. */
2
+ export declare const SAY: {
3
+ readonly TITLE: 0;
4
+ readonly NOTE: 1;
5
+ readonly END: 2;
6
+ };
7
+ export declare const HUD_CSS: string;
8
+ export interface Hud {
9
+ /** Health pips: the first n are lit. */
10
+ hp(n: number): void;
11
+ /** The keys held, as the snapshot's bit set (1 << ITEM.KEY_*). */
12
+ keys(bits: number): void;
13
+ /** The own player is dead: "Respawning…". */
14
+ dead(on: boolean): void;
15
+ /** Shows text in a SAY slot, for that slot's time. */
16
+ say(slot: number, text: string): void;
17
+ /** Advances dt seconds. */
18
+ update(dt: number): void;
19
+ }
20
+ /** Appends the HUD to `screen`, whose stylesheet has HUD_CSS. */
21
+ export declare const createHud: (screen: HTMLElement) => Hud;
@@ -0,0 +1,19 @@
1
+ import type { Item, Level } from '../shared/types';
2
+ /** Colour of each ITEM kind: the pickup, the bars of its gate, the HUD mark and the pickup fade. */
3
+ export declare const ITEM_COLOR: number[][];
4
+ /** A 0 to 1 colour as CSS, with alpha a. */
5
+ export declare const css: (c: number[], a?: number) => string;
6
+ /**
7
+ * A pickup, bobbing and spinning above its floor: HEALTH a white box with a red cross, a key a
8
+ * ring (glowing), a shaft and two teeth in its colour.
9
+ */
10
+ export declare const item: (out: number[], { id, kind, x, y, z }: Item, t: number) => void;
11
+ /**
12
+ * Every barred gate gets upright bars across the portal edges of its sector, in its key's colour:
13
+ * they go with the key. The exit, once open, gets a glowing frame on its portals, pulsing.
14
+ */
15
+ export declare const gates: (out: number[], lvl: Level, t: number) => void;
16
+ /** The goal: a pad on the floor that swells and fades with the clock, and a crystal above it. */
17
+ export declare const pad: (out: number[], lvl: Level, t: number) => void;
18
+ /** Items, gates, the exit frame and the goal pad. */
19
+ export declare const props: (out: number[], lvl: Level, items: Item[], t: number) => void;
@@ -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[];
@@ -11,11 +11,21 @@ export interface Predictor {
11
11
  */
12
12
  step(i: Omit<Input, 'seq' | 'view'>, now?: number): Input;
13
13
  /**
14
- * The shot the last step fired, resolved with fire() against others(now) and monsters(now) of
15
- * that step (a monster this predictor already shot dead, and the host has not acked yet, is not
16
- * a target); undefined when it did not fire. Replays on a snapshot never fire again.
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.
17
18
  */
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;
19
29
  /** A decoded snapshot, received at `now` (ms, performance.now()). */
20
30
  snapshot(s: Snapshot, now: number): void;
21
31
  /**
@@ -36,4 +46,4 @@ export interface Predictor {
36
46
  /** The bullets in flight at now - INTERP_DELAY, interpolated and kept the same way (until their BOOM). */
37
47
  bullets(now: number): Bullet[];
38
48
  }
39
- export declare const createPredictor: (lvl: Level) => Predictor;
49
+ export declare const createPredictor: (first: Level) => Predictor;
@@ -0,0 +1,41 @@
1
+ import type { Item, Level, MapDef, Snapshot } from '../shared/types';
2
+ import type { Effects } from './effects';
3
+ import type { Hud } from './hud';
4
+ /** Ticks as m:ss.s, the tenth cut, not rounded. */
5
+ export declare const clock: (ticks: number) => string;
6
+ export interface Progress {
7
+ /** The level of the latest snapshot. */
8
+ readonly lvl: Level;
9
+ /** The pickups lying in it. */
10
+ readonly items: Item[];
11
+ /** The own player has no health left. */
12
+ readonly dead: boolean;
13
+ /** False for a player the latest snapshot shows without health: not drawn. */
14
+ alive(id: number): boolean;
15
+ /** A snapshot, before the predictor sees it: a new level or `hard` switches everything. */
16
+ snapshot(s: Snapshot): void;
17
+ /** The run is won: the end screen with its time. */
18
+ end(ticks: number, hard: boolean): void;
19
+ }
20
+ export interface Deps {
21
+ /** The level the predictor, renderer and effects were built with. */
22
+ lvl: Level;
23
+ /** The own player id, -1 while unknown. */
24
+ you(): number;
25
+ predictor: {
26
+ level(lvl: Level): void;
27
+ };
28
+ /** Absent without WebGL. */
29
+ rd?: {
30
+ level(lvl: Level): void;
31
+ };
32
+ /** What the old level left waiting: shots and events. */
33
+ delays: {
34
+ clear(): void;
35
+ }[];
36
+ fx: Effects;
37
+ hud: Hud;
38
+ }
39
+ /** The yaw of the spawn nearest (x, z): where a player put back at the start should look. */
40
+ export declare const facing: ({ spawns }: MapDef, x: number, z: number) => number;
41
+ export declare const createProgress: ({ lvl, you, predictor, rd, delays, fx, hud }: Deps) => Progress;
@@ -1,23 +1,50 @@
1
- import type { Bullet, Edge, Level, Monster, PlayerState } from '../shared/types';
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
- /** Column-major view-projection matrix of basis(yaw, pitch, roll) at eye, 70° vertical field of view. */
5
- export declare const viewProj: (eye: Vec3, yaw: number, pitch: number, aspect: number, roll?: number) => Float32Array<ArrayBuffer>;
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. */
11
33
  export declare const levelVerts: (lvl: Level) => number[];
12
34
  export interface Renderer {
13
35
  /**
14
- * Draws one frame: the map, the others, the monsters, their bullets and the effects as seen from
15
- * eye, with the view model on top. colors maps player id to CSS.
36
+ * Draws one frame: the map, its gates, goal and items, the others, the monsters, their bullets
37
+ * and the effects as seen from eye, with the view model on top (not while fx.dead). colors maps
38
+ * player id to CSS.
16
39
  */
17
- frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects, monsters: Monster[], bullets: Bullet[]): void;
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;
43
+ /** Builds the geometry of another level, drawn from the next frame on. */
44
+ level(lvl: Level): void;
18
45
  /** A world point on screen as of the last frame, in [0, 1] from the top left. */
19
46
  project(x: number, y: number, z: number): [number, number] | undefined;
20
47
  destroy(): void;
21
48
  }
22
49
  /** Throws when the browser has no WebGL2. */
23
- export declare const createRenderer: (canvas: HTMLCanvasElement, lvl: Level) => Renderer;
50
+ export declare const createRenderer: (canvas: HTMLCanvasElement, first: Level) => Renderer;
@@ -66,8 +66,20 @@ export declare const BULLET_SPEED = 12;
66
66
  export declare const BULLET_R = 0.15;
67
67
  /** Ticks a bullet lives at most. */
68
68
  export declare const BULLET_LIFE = 300;
69
- /** Ticks after the last monster dies before the map's monsters come back (until step 4). */
70
- export declare const RESPAWN_AFTER = 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;
71
83
  /** Longest player name, in characters (code points). */
72
84
  export declare const MAX_NAME = 16;
73
85
  export declare const RULES: Rules;
@@ -1,6 +1,8 @@
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;
4
6
  /** Whether (x, z) is inside the sector, its edges included. */
5
7
  export declare const inside: ({ pts }: Sector, x: number, z: number) => boolean;
6
8
  /** Index of the first sector holding (x, z), -1 outside the map. */
@@ -0,0 +1,2 @@
1
+ import type { MapDef } from './types';
2
+ export declare const LEVELS: MapDef[];
@@ -1,6 +1,7 @@
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.
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.
5
6
  */
6
7
  export declare const HALL: MapDef;
@@ -10,8 +10,14 @@ export interface Horde {
10
10
  events: GameEvent[];
11
11
  /** One host tick, with the players' states. */
12
12
  step(players: PlayerState[]): void;
13
- /** A player's shot killed monster `id`: it dies at once, and the monsters that see it hunt `by`. */
14
- kill(id: number, by: number): void;
13
+ /**
14
+ * A player's shot killed monster `id`: it dies at once, and the monsters that see it hunt `by`.
15
+ * Returns the monster, undefined when `id` is not alive.
16
+ */
17
+ kill(id: number, by: number): Monster | undefined;
15
18
  }
16
- /** The monsters of the level's map, from the first spawn. */
17
- export declare const createHorde: (lvl: Level, rand: () => number) => Horde;
19
+ /**
20
+ * The monsters of the level's map, from the first spawn. In hard mode they move HARD_SPEED faster
21
+ * and swing and shoot HARD_RATE as often.
22
+ */
23
+ export declare const createHorde: (lvl: Level, rand: () => number, hard?: boolean) => Horde;
@@ -9,16 +9,26 @@ 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.
16
+ */
17
+ | {
18
+ t: 'end';
19
+ ticks: number;
20
+ hard: boolean;
12
21
  };
13
22
  export declare const MSG_INPUT = 1;
14
23
  export declare const MSG_SNAPSHOT = 2;
15
24
  export declare const INPUT_BYTES = 11;
16
- export declare const SNAP_HEAD = 4;
17
- export declare const SNAP_PLAYER = 24;
25
+ export declare const SNAP_HEAD = 7;
26
+ export declare const SNAP_PLAYER = 25;
18
27
  export declare const SNAP_SHOT = 14;
19
28
  export declare const SNAP_MONSTER = 16;
20
29
  export declare const SNAP_BULLET = 13;
21
30
  export declare const SNAP_EVENT = 14;
31
+ export declare const SNAP_ITEM = 14;
22
32
  /**
23
33
  * The input as the host will read it after encodeInput and decodeInput: yaw, pitch and view
24
34
  * rounded to the wire (an absent view stays absent here, and reads 0 on the host). The client
@@ -1,4 +1,4 @@
1
- import type { Conn, Every, Rules } from './types';
1
+ import type { Conn, Every, MapDef, Rules } from './types';
2
2
  /**
3
3
  * One game, transport-agnostic. The Node server and the local host tab both drive a Room: they
4
4
  * feed it connections and frames, the room answers through Conn.send.
@@ -11,8 +11,17 @@ import type { Conn, Every, Rules } from './types';
11
11
  * view tick of the input (lag compensation, at most MAX_REWIND ticks back).
12
12
  * - The room owns the horde (monsters.ts), stepped every tick while a player is present. A shot
13
13
  * rewinds the monsters with the players, and one that hits a monster kills it.
14
+ * - A player has HEALTH. A monster's blow or bullet takes 1, then HIT_COOLDOWN ticks of grace
15
+ * (only a hit that took health is told as a HURT event). A dead player moves, shoots and
16
+ * counts for nothing until PLAYER_RESPAWN ticks later, when it is back at a spawn.
17
+ * - The level's items lie in it, and every DROP_EVERY-th kill leaves a HEALTH pack. A key taken
18
+ * opens its gates for the team, a pack heals below full health.
19
+ * - Touching the goal turns the level from HUNT to RETURN (the exit opens); when every living
20
+ * player is in the exit the level is won: the next one starts, everyone respawned. After the
21
+ * last, every player gets { t: 'end' } and a new run starts at level 0, hard from then on.
14
22
  * - Every SNAP_EVERY ticks of TICK_HZ, one snapshot with every player, the shots resolved since
15
- * the last one, the monsters, the bullets and the events since the last one goes to every peer.
23
+ * the last one, the monsters, the bullets, the events since the last one and the items goes to
24
+ * every peer.
16
25
  */
17
26
  export declare class Room {
18
27
  /** Every connected peer; null until it joins. */
@@ -20,15 +29,29 @@ export declare class Room {
20
29
  private ticks;
21
30
  /** The players and monsters as each snapshot of the last MAX_REWIND ticks sent them. */
22
31
  private history;
32
+ private maps;
33
+ private lvl;
23
34
  private horde;
35
+ private rand;
36
+ private level;
37
+ private hard;
38
+ private phase;
39
+ /** The team's key bits (1 << ITEM.KEY_*). */
40
+ private keys;
41
+ private items;
42
+ private nextItem;
43
+ /** Monsters the team killed in this level. */
44
+ private kills;
45
+ /** Host tick the run started at. */
46
+ private runStart;
24
47
  /** Shots resolved since the last snapshot. */
25
48
  private shots;
26
49
  private halt;
27
50
  private rules;
28
51
  /** Round-robin cursor over the spawn points, used once they are all taken. */
29
52
  private rr;
30
- /** Missing rules fall back to RULES. The seed drives the monsters. */
31
- constructor(rules?: Partial<Rules>, seed?: number);
53
+ /** Missing rules fall back to RULES. The seed drives the monsters. `levels` is the campaign. */
54
+ constructor(rules?: Partial<Rules>, seed?: number, levels?: MapDef[]);
32
55
  /** Number of joined players. */
33
56
  get size(): number;
34
57
  /** A peer opened. Nothing is sent until it joins. */
@@ -55,6 +78,20 @@ export declare class Room {
55
78
  * does. One the history does not hold stands where it is.
56
79
  */
57
80
  private rewind;
81
+ /** Resets everything a level owns, and puts every player on a spawn of it with full health. */
82
+ private load;
83
+ /** The first spawn point with none of `others` within SPAWN_CLEAR, else the next one round-robin. */
84
+ private place;
85
+ /** The floor of the sector holding (x, z). */
86
+ private floor;
87
+ /** Leaves an item of `kind` on the floor at (x, z). */
88
+ private drop;
89
+ /** Takes 1 health off player `id` unless it was hurt less than HIT_COOLDOWN ticks ago. */
90
+ private wound;
91
+ /** What the living players do to the level: pick things up, touch the goal, win. */
92
+ private progress;
93
+ /** The level is won: the next one, or the end of the run and a new, hard one. */
94
+ private win;
58
95
  private players;
59
96
  private join;
60
97
  /** Each joined peer gets the full roster with its own id. */
@@ -117,6 +117,38 @@ export interface Body {
117
117
  r: number;
118
118
  h: number;
119
119
  }
120
+ /** Pickup kinds. A key is shared by the team: once anyone takes it, its gates open for all. */
121
+ export declare const ITEM: {
122
+ /** Gives HEAL health, up to HEALTH. Left in the level by every DROP_EVERY-th kill. */
123
+ readonly HEALTH: 0;
124
+ readonly KEY_RED: 1;
125
+ readonly KEY_BLUE: 2;
126
+ readonly KEY_YELLOW: 3;
127
+ };
128
+ /** A pickup lying in the level. Ids are unique within a level, u8. */
129
+ export interface Item {
130
+ id: number;
131
+ /** ITEM kind. */
132
+ kind: number;
133
+ /** Where it rests: on the floor of the sector under it. */
134
+ x: number;
135
+ y: number;
136
+ z: number;
137
+ }
138
+ /** A barred doorway: bodies cannot enter the sector until the team holds the key. */
139
+ export interface Gate {
140
+ /** Sector index, a thin doorway between two rooms. */
141
+ sector: number;
142
+ /** ITEM.KEY_* kind that opens it. */
143
+ key: number;
144
+ }
145
+ /** Where a level stands. */
146
+ export declare const PHASE: {
147
+ /** Find the goal: the exit sector is barred. */
148
+ readonly HUNT: 0;
149
+ /** The goal was touched: the exit sector is open; the level is won when every living player is in it. */
150
+ readonly RETURN: 1;
151
+ };
120
152
  /** Procedural textures, generated by the client. A sector names one per surface. */
121
153
  export declare const TEX: {
122
154
  readonly BRICK: 0;
@@ -152,6 +184,17 @@ export interface MapDef {
152
184
  spawns: [x: number, z: number, yaw: number][];
153
185
  /** Monsters at the start: x, z inside a sector, the yaw they face, their MONSTER kind. Absent: none. */
154
186
  monsters?: [x: number, z: number, yaw: number, kind: number][];
187
+ /** Pickups at the start: x, z inside a sector, their ITEM kind. Absent: none. */
188
+ items?: [x: number, z: number, kind: number][];
189
+ /** Barred doorways. Absent: none. */
190
+ gates?: Gate[];
191
+ /** The goal pad, far from the start: touching it (within GOAL_R) turns the level to RETURN. */
192
+ goal?: [x: number, z: number];
193
+ /**
194
+ * Sector index of the exit, barred until the goal is touched. Usually the start room: players
195
+ * spawn in it and can walk out, but not back in until RETURN.
196
+ */
197
+ exit?: number;
155
198
  }
156
199
  /** One directed edge of a sector, see compile in level.ts. */
157
200
  export interface Edge {
@@ -169,6 +212,11 @@ export interface Level {
169
212
  map: MapDef;
170
213
  /** Every edge of every sector, in sector then point order. */
171
214
  edges: Edge[];
215
+ /**
216
+ * Sectors that bodies cannot enter now: gates without their key, the exit before RETURN.
217
+ * Mutable: set it with bar() in level.ts (host and client alike); sight and shots ignore it.
218
+ */
219
+ barred: Set<number>;
172
220
  }
173
221
  /** One player in a snapshot. */
174
222
  export interface SnapPlayer {
@@ -181,6 +229,8 @@ export interface SnapPlayer {
181
229
  pitch: number;
182
230
  ground: boolean;
183
231
  cool: number;
232
+ /** Health, HEALTH at most; 0 is dead, waiting PLAYER_RESPAWN ticks to respawn at the start. */
233
+ hp: number;
184
234
  /** Seq of the last input of this player the host applied: the client replays the ones after. */
185
235
  ack: number;
186
236
  }
@@ -196,6 +246,16 @@ export interface Snapshot {
196
246
  bullets: Bullet[];
197
247
  /** Events since the previous snapshot, in order. */
198
248
  events: GameEvent[];
249
+ /** Index of the level in LEVELS (levels.ts). A change means a new level: clients rebuild. */
250
+ level: number;
251
+ /** The second run and later: monsters are faster and fire more often. */
252
+ hard: boolean;
253
+ /** PHASE of the level. */
254
+ phase: number;
255
+ /** Keys the team holds: bit (1 << ITEM.KEY_*). */
256
+ keys: number;
257
+ /** Pickups lying in the level. */
258
+ items: Item[];
199
259
  }
200
260
  /** Room rules, set by the host. Defaults in constants.ts (RULES). */
201
261
  export interface Rules {
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.3.0",
5
+ "version": "0.5.0",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"