@korial29/tiny-fps 0.18.0 → 0.19.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.
@@ -0,0 +1,39 @@
1
+ import type { Snapshot } from '../shared/types';
2
+ /** One thing that happened. `flag` is the team the flag belongs to. */
3
+ export type Beat = {
4
+ kind: 'take';
5
+ flag: number;
6
+ by: number;
7
+ } | {
8
+ kind: 'drop';
9
+ flag: number;
10
+ } | {
11
+ kind: 'return';
12
+ flag: number;
13
+ } | {
14
+ kind: 'capture';
15
+ team: number;
16
+ } | {
17
+ kind: 'start';
18
+ };
19
+ /**
20
+ * The beats from snapshot `a` to `b`. Nothing at the first snapshot, nothing while a match is
21
+ * over (the flags and the score are frozen), and a new match is one beat of its own, whatever
22
+ * its flags and score reset from. A capture is one beat: the carried flag going home with it is
23
+ * not a return.
24
+ */
25
+ export declare const beats: (a: Snapshot | undefined, b: Snapshot) => Beat[];
26
+ /** A line for the banner, and the team whose colour it is in. `me` is the own player. */
27
+ export declare const say: (beat: Beat, me: {
28
+ id: number;
29
+ team: number;
30
+ }, name: (id: number) => string) => {
31
+ text: string;
32
+ team?: number;
33
+ };
34
+ /**
35
+ * The sound of a beat and its speed: a lower pitch for bad news for the own team (its flag taken,
36
+ * the enemy flag dropped or returned, a point for the other side), the plain one for good news.
37
+ * Undefined for a beat with no sound.
38
+ */
39
+ export declare const cue: (beat: Beat, team: number) => [id: number, rate: number] | undefined;
@@ -0,0 +1,41 @@
1
+ import type { FlagState, PlayerState } from '../shared/types';
2
+ import type { Vec3 } from './mesh';
3
+ /** One flag to draw. */
4
+ export interface FlagDraw {
5
+ /** The team the flag belongs to: its colour. */
6
+ team: number;
7
+ /** The foot of the pole: the base, where it lies, or the feet of the carrier. */
8
+ at: Vec3;
9
+ /** On a carrier's back: where he looks (yaw) and his speed on x and z, which the cloth trails against. */
10
+ by?: {
11
+ yaw: number;
12
+ vx: number;
13
+ vz: number;
14
+ };
15
+ /** Lying where it was dropped. */
16
+ dropped?: boolean;
17
+ }
18
+ /** Height of a pole, metres. */
19
+ export declare const POLE = 2.4;
20
+ /** A team's colour as RGB in 0..1: TEAM_COLOR is always #rrggbb. */
21
+ export declare const teamRgb: (team: number) => number[];
22
+ /** What the renderer draws of the match: the base of each team and the flags in play. */
23
+ export interface CtfScene {
24
+ bases: readonly Vec3[];
25
+ flags: readonly FlagDraw[];
26
+ }
27
+ /** The flags to draw from a snapshot: each at its base, where it lies, or on the back of its carrier (none if he is not drawn). */
28
+ export declare const flagDraws: (flags: readonly FlagState[], bases: readonly Vec3[], who: (id: number) => PlayerState | undefined) => FlagDraw[];
29
+ /**
30
+ * A team's base at `at`: a low pad of the team colour under a glowing ring of FLAG_REACH, the
31
+ * radius within which a flag is touched and a capture counts. `t` is the clock in seconds: the
32
+ * ring pulses.
33
+ */
34
+ export declare const base: (out: number[], at: Vec3, rgb: number[], t: number) => void;
35
+ /**
36
+ * A flag. At rest on its base it stands upright with the cloth blowing out to one side. On a
37
+ * carrier's back it leans out behind him and the cloth trails away from where he runs, more
38
+ * stretched the faster he goes. Dropped, it lies on the ground, the pole leaning, with a ring
39
+ * on the ground where it is to be touched. `t` is the clock in seconds.
40
+ */
41
+ export declare const flag: (out: number[], f: FlagDraw, rgb: number[], t: number) => void;
@@ -1,9 +1,32 @@
1
+ import type { Result } from '../shared/protocol';
2
+ import type { Snapshot } from '../shared/types';
3
+ import type { Mark } from './marks';
1
4
  export declare const HUD_CSS: string;
5
+ /** What the end screen shows: the final captures and what each player did. */
6
+ export interface Summary {
7
+ score: [number, number];
8
+ players: Result[];
9
+ }
2
10
  export interface Hud {
3
11
  /** The title screen with `status` under the controls, "Click to play" or why not; '' hides it. */
4
12
  title(status: string, name: string): void;
5
13
  /** Shows or hides the muted mark. */
6
14
  mute(on: boolean): void;
15
+ /**
16
+ * The score and the clock at the top, and under them the state of both flags: at home, taken by
17
+ * a player (`who` gives his name) or dropped with the seconds left. Over, the clock reads END.
18
+ */
19
+ match(m: Pick<Snapshot, 'score' | 'clock' | 'over' | 'flags'>, who: (id: number) => string): void;
20
+ /** The markers of this frame (see marks.ts), in the order given; the ones before are removed. */
21
+ marks(list: Mark[]): void;
22
+ /** A line in the middle of the top of the screen in `team`'s colour, for a few seconds; a newer one replaces it. */
23
+ banner(text: string, team?: number): void;
24
+ /** The end screen with the result and each player's captures and returns, `next` seconds before the next match; undefined hides it. */
25
+ end(sum: Summary | undefined, next: number): void;
7
26
  }
27
+ /** Milliseconds a banner stays. */
28
+ export declare const BANNER_MS = 2800;
29
+ /** m:ss. */
30
+ export declare const clock: (s: number) => string;
8
31
  /** Appends the HUD to `screen`, whose stylesheet has HUD_CSS. */
9
32
  export declare const createHud: (screen: HTMLElement) => Hud;
@@ -1,4 +1,5 @@
1
1
  import type { PlayerState } from '../shared/types';
2
+ import type { CtfScene } from './flag';
2
3
  import type { Vec3 } from './mesh';
3
4
  export declare const LIGHT: {
4
5
  /** A cone from p along d. */
@@ -34,6 +35,8 @@ export interface Scene {
34
35
  others: PlayerState[];
35
36
  /** Seconds, for pulsing lights. */
36
37
  t: number;
38
+ /** The bases and the flags in play: each base and each lying flag lights the roof around it. */
39
+ ctf?: CtfScene;
37
40
  }
38
- /** The lights of this frame, most important first: none yet. */
41
+ /** The lights of this frame, most important first: the two bases, then the flags that lie on the ground. */
39
42
  export declare const gather: (scene: Scene) => Light[];
@@ -0,0 +1,40 @@
1
+ import type { FlagState } from '../shared/types';
2
+ import type { Vec3 } from './mesh';
3
+ export interface Mark {
4
+ /** The team whose flag or base it is: its colour. */
5
+ team: number;
6
+ kind: 'flag' | 'base';
7
+ /** Where it is on the screen, in [0, 1] from the top left. */
8
+ x: number;
9
+ y: number;
10
+ /** Radians clockwise from straight up that the arrow points at; absent when the mark is over its target. */
11
+ arrow?: number;
12
+ /** The label: the distance in metres. */
13
+ text: string;
14
+ }
15
+ /**
16
+ * The angle to the right of straight ahead, in radians (0 ahead, π/2 to the right, ±π behind), at
17
+ * which the point (x, z) is seen from the eye (ex, ez) looking along `yaw`.
18
+ */
19
+ export declare const bearing: (ex: number, ez: number, yaw: number, x: number, z: number) => number;
20
+ /** The point of the screen's box the direction `angle` (see bearing) leaves it by, from its centre. */
21
+ export declare const edge: (angle: number) => [number, number];
22
+ /** What the markers read. */
23
+ export interface MarkScene {
24
+ /** The own player: eye position and id, and the camera yaw. */
25
+ eye: Vec3;
26
+ id: number;
27
+ team: number;
28
+ yaw: number;
29
+ flags: readonly FlagState[];
30
+ bases: readonly Vec3[];
31
+ /** Where a player is (his feet), for the carrier of a flag. */
32
+ where(id: number): Vec3 | undefined;
33
+ /** A world point on the screen as of the last frame, or undefined behind the camera. */
34
+ project(x: number, y: number, z: number): [number, number] | undefined;
35
+ }
36
+ /**
37
+ * The markers of a frame: each flag but one the player carries, and the own base while he carries
38
+ * (which stands for his own flag too while it is home there).
39
+ */
40
+ export declare const marks: (s: MarkScene) => Mark[];
@@ -1,8 +1,11 @@
1
1
  import type { Input, PlayerState, Snapshot } from '../shared/types';
2
2
  import type { World } from '../shared/world';
3
3
  export interface Predictor {
4
- /** The own player id, from the roster. Snapshots before it are only used for the others. */
5
- you(id: number): void;
4
+ /**
5
+ * The own player id and team, from the roster. Snapshots before it are only used for the others.
6
+ * The team picks the spawn a fall puts the player back at.
7
+ */
8
+ you(id: number, team?: number): void;
6
9
  /**
7
10
  * One local step: gives the input the next seq, rounds its yaw and pitch to the wire, moves the
8
11
  * own player with it, keeps it for replay, and returns it for the caller to send (the very
@@ -2,6 +2,7 @@ import type { PlayerState } from '../shared/types';
2
2
  import type { World, WorldDef } from '../shared/world';
3
3
  import type { Body } from './body';
4
4
  import type { Effects } from './effects';
5
+ import type { CtfScene } from './flag';
5
6
  import type { Light } from './lights';
6
7
  import type { Vec3 } from './mesh';
7
8
  /** Tints a world can use at once, white included (see palette). */
@@ -82,7 +83,9 @@ export interface Renderer {
82
83
  */
83
84
  frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects,
84
85
  /** gather() in lights.ts: at most MAX_LIGHTS, the first MAX_SHADOWS shadowed spots mapped, besides the sun. */
85
- lights: Light[], body?: Body): void;
86
+ lights: Light[], body?: Body,
87
+ /** The bases and the flags: drawn lit, casting shadows, with the other players. */
88
+ ctf?: CtfScene): void;
86
89
  /** A world point on screen as of the last frame, in [0, 1] from the top left. */
87
90
  project(x: number, y: number, z: number): [number, number] | undefined;
88
91
  destroy(): void;
@@ -32,6 +32,11 @@ export declare const SOUND: {
32
32
  readonly SCUFF: 7;
33
33
  readonly WIND: 8;
34
34
  readonly SCRAPE: 9;
35
+ /** Capture the flag: a flag taken, dropped, returned home, and a capture. */
36
+ readonly TAKE: 10;
37
+ readonly DROP: 11;
38
+ readonly RETURN: 12;
39
+ readonly CAPTURE: 13;
35
40
  };
36
41
  /**
37
42
  * The sounds of the game: one entry per sound, its voices layered, in SOUND order. A low-passed
@@ -139,6 +139,19 @@ export declare const MAX_REWIND = 30;
139
139
  */
140
140
  export declare const INPUT_BURST = 10;
141
141
  export declare const MAX_PLAYERS = 16;
142
+ /** Team names and colours (CSS), red then blue: the runners, the flags, the bases and the HUD wear them. */
143
+ export declare const TEAM_NAME: string[];
144
+ export declare const TEAM_COLOR: string[];
145
+ /** Capture the flag. Reach: horizontal metres from a flag stand or a lying flag within which the player touches it. */
146
+ export declare const FLAG_REACH = 1.5;
147
+ /** A flag is as tall as this above its foot: a body touches it only if it overlaps that height. */
148
+ export declare const FLAG_H = 2.2;
149
+ /** Seconds a dropped flag lies before it goes home by itself. */
150
+ export declare const FLAG_RETURN = 10;
151
+ /** Seconds a carrier who is made to drop the flag cannot take it again: he would pick it up where he stands. */
152
+ export declare const FLAG_LOCK = 2;
153
+ /** Seconds the end screen of a match stays, then a new match starts. */
154
+ export declare const END_SCREEN = 10;
142
155
  /** Longest player name, in characters (code points). */
143
156
  export declare const MAX_NAME = 16;
144
157
  export declare const RULES: Rules;
@@ -0,0 +1,72 @@
1
+ import type { FlagState, PlayerState, Rules, Snapshot } from './types';
2
+ import type { World } from './world';
3
+ type Vec3 = [number, number, number];
4
+ /** A player as the rules see him. */
5
+ export interface Runner {
6
+ id: number;
7
+ team: number;
8
+ state: PlayerState;
9
+ }
10
+ /** What a tick of the match ended or began. */
11
+ export type Turn = 'end' | 'start';
12
+ /** The captures and returns of one player this match. */
13
+ export interface Tally {
14
+ id: number;
15
+ caps: number;
16
+ returns: number;
17
+ }
18
+ export declare class Ctf {
19
+ /** Captures per team, red then blue. */
20
+ score: [number, number];
21
+ /** The match is over and the end screen shows. */
22
+ over: boolean;
23
+ /** The flag of each team, red then blue. */
24
+ flags: [FlagState, FlagState];
25
+ private world;
26
+ private rules;
27
+ private mates;
28
+ /** Ticks to the end of the match, or to the next one while it is over. */
29
+ private clock;
30
+ /** Ticks before each dropped flag goes home. */
31
+ private back;
32
+ /** Who may not take each flag, and for how many more ticks: the carrier that was made to drop it. */
33
+ private lock;
34
+ constructor(world: World, rules: Rules);
35
+ /** A player joined, standing at `at`. */
36
+ join(id: number, team: number, at: PlayerState): void;
37
+ /** A player left: a flag he carried is dropped where he last stood. */
38
+ leave(id: number): void;
39
+ /** A player was put at `at` (a new match): his last ground is there. */
40
+ place(id: number, at: PlayerState): void;
41
+ /**
42
+ * The player's state after one move. Under the kill floor and put back at a spawn (EV.RESPAWN),
43
+ * a carrier drops the flag where he last stood; then a floor under him is his last ground.
44
+ */
45
+ moved(p: PlayerState): void;
46
+ /**
47
+ * Makes the player drop the flag he carries (the tackle of step 7). It lies under him: where he
48
+ * stands, or on the first floor below him, or at his last ground when there is none (over the
49
+ * void). False when he carried nothing.
50
+ */
51
+ drop(p: PlayerState): boolean;
52
+ /** The team whose flag the player carries, or -1. */
53
+ carrying(id: number): number;
54
+ /** The winning team of a match that is over, or -1 for a draw. */
55
+ winner(): number;
56
+ /** What every player has done this match. */
57
+ tally(): Tally[];
58
+ /** The room is empty: the next match starts from scratch. */
59
+ reset(): void;
60
+ /** The part of a snapshot that is the match's. */
61
+ wire(): Pick<Snapshot, 'score' | 'clock' | 'over' | 'flags'>;
62
+ /**
63
+ * One host tick over the players: the dropped flags run down, flags are taken, returned and
64
+ * captured, the clock runs. 'end' when the match has just ended, 'start' when the end screen is
65
+ * done and a new match begins (the room puts everyone back at a spawn).
66
+ */
67
+ tick(players: Runner[]): Turn | undefined;
68
+ private dropAt;
69
+ }
70
+ /** Whether the player's body reaches the flag foot at `at`: close enough, and overlapping its height. */
71
+ export declare const touches: (p: PlayerState, at: Vec3) => boolean;
72
+ export {};
@@ -5,7 +5,7 @@ import type { WorldDef } from './world';
5
5
  * sprint jump 6.3 m, and reaches a box 1.7 m high; the hands catch a top 1.2 to 2.4 m above the
6
6
  * feet, and a fall that reaches a face within about 3.5 m is caught by them.
7
7
  *
8
- * - A: the start roof (10 m), with the spawns. B: a roof at 10 m, across a 4.2 m gap from A (a
8
+ * - A: the start roof (10 m), red's base, with its spawns. B: a roof at 10 m, across a 4.2 m gap from A (a
9
9
  * run and a jump: walking off the edge falls).
10
10
  * - On B, a platform floating at 12.2 to 12.6 m (an overhang to walk under, a bump for a jump) and
11
11
  * a stair of six 0.4 m steps up to it. 3 m north of it, C (12.4 m): the south face of C above B
@@ -15,5 +15,7 @@ import type { WorldDef } from './world';
15
15
  * - G (8 m) is across a 10 m drop from E, reached by a 0.5 m wide beam; it has a 1.6 m ledge.
16
16
  * - F (12.4 m) is 13 m north of C: a sprint and a jump fall short of it, and so does a walk with
17
17
  * the dash or the double jump; it takes the sprint and the jump and the dash or the double jump.
18
+ * F is blue's base, with its spawns: the flags are 90 m and the chasm apart, and the way back is
19
+ * the same line in reverse, then a drop to B and the A gap jumped south.
18
20
  */
19
21
  export declare const ROOFTOPS: WorldDef;
@@ -22,8 +22,8 @@ export declare const STILL: {
22
22
  ev: number;
23
23
  fall: number;
24
24
  };
25
- /** A player standing on spawn point n of the world (modulo the count). */
26
- export declare const spawn: (id: number, w: World, n: number) => PlayerState;
25
+ /** A player standing on spawn point n of a team (modulo the count): the red team's by default. */
26
+ export declare const spawn: (id: number, w: World, n: number, team?: number) => PlayerState;
27
27
  /** The height of the cylinder in this mode. */
28
28
  export declare const heightOf: (p: Pick<PlayerState, "mode">) => number;
29
29
  /** The camera height above the feet in this mode. */
@@ -35,6 +35,6 @@ export declare const sprinting: (p: Pick<PlayerState, "mode" | "vx" | "vz">) =>
35
35
  /**
36
36
  * Applies one input for 1 / TICK_HZ s, in place: yaw and pitch from the input (pitch clamped to
37
37
  * MAX_PITCH), then the step of the current mode (see the top of the file). Feet under the world's
38
- * kill floor put the player back at a spawn.
38
+ * kill floor put the player back at a spawn of his `team` (EV.RESPAWN).
39
39
  */
40
- export declare const move: (p: PlayerState, i: Input, w: World) => void;
40
+ export declare const move: (p: PlayerState, i: Input, w: World, team?: number) => void;
@@ -3,18 +3,34 @@ export type ClientText = {
3
3
  t: 'join';
4
4
  name: string;
5
5
  };
6
+ /** What a player did in a match, for the end screen: it carries the name and the team, which a leaver takes out of the roster. */
7
+ export interface Result {
8
+ id: number;
9
+ name: string;
10
+ team: number;
11
+ caps: number;
12
+ returns: number;
13
+ }
6
14
  export type ServerText = {
7
15
  t: 'roster';
8
16
  you: number;
9
17
  players: PlayerInfo[];
10
18
  } | {
11
19
  t: 'full';
20
+ }
21
+ /** The match is over: the final captures of red and blue, and every player's result. */
22
+ | {
23
+ t: 'end';
24
+ score: [number, number];
25
+ players: Result[];
12
26
  };
13
27
  export declare const MSG_INPUT = 1;
14
28
  export declare const MSG_SNAPSHOT = 2;
15
29
  export declare const INPUT_BYTES = 11;
16
30
  export declare const SNAP_HEAD = 4;
17
31
  export declare const SNAP_PLAYER = 39;
32
+ /** The match block after the players: the captures, the clock; the flags follow (2 to 16 bytes). */
33
+ export declare const SNAP_MATCH = 4;
18
34
  /**
19
35
  * The input as the host will read it after encodeInput and decodeInput: yaw, pitch and view
20
36
  * rounded to the wire (an absent view stays absent here, and reads 0 on the host). The client
@@ -4,13 +4,18 @@ import type { WorldDef } from './world';
4
4
  * One game, transport-agnostic. The Node server and the local host tab both drive a Room: they
5
5
  * feed it connections and frames, the room answers through Conn.send.
6
6
  *
7
- * - A peer joins with { t: 'join', name }: unique name (`Bob 2`), unique colour, a spawn point not
8
- * taken by another player; 'full' beyond rules.maxPlayers. Everyone gets a fresh 'roster' on
9
- * every join and leave.
7
+ * - A peer joins with { t: 'join', name }: unique name (`Bob 2`), the smaller team (red on a tie)
8
+ * and its colour, a spawn point of the team not taken by another player; 'full' beyond
9
+ * rules.maxPlayers. Everyone gets a fresh 'roster' on every join and leave. Teams are not
10
+ * rebalanced when someone leaves: the next join fills the smaller one.
10
11
  * - Each input frame moves its player at once with move(); the INPUT_BURST bank drops the excess.
11
12
  * rewind() answers where the others were drawn at the view tick of an input (lag compensation,
12
13
  * at most MAX_REWIND ticks back).
13
- * - Every SNAP_EVERY ticks of TICK_HZ, one snapshot with every player goes to every peer.
14
+ * - Every SNAP_EVERY ticks of TICK_HZ, one snapshot with every player, the score, the clock and
15
+ * the two flags goes to every peer. The flag rules and the match are ctf.ts's: a match ends at
16
+ * rules.scoreLimit or rules.timeLimit ('end' text to everyone), the end screen runs END_SCREEN
17
+ * seconds, then everyone is put back at a spawn of his team and the score starts again.
18
+ * drop(id) makes a carrier drop the flag: the hook of the tackle (step 7).
14
19
  */
15
20
  export declare class Room {
16
21
  /** Every connected peer; null until it joins. */
@@ -19,9 +24,10 @@ export declare class Room {
19
24
  /** The players as each snapshot of the last MAX_REWIND ticks sent them. */
20
25
  private history;
21
26
  private world;
27
+ private ctf;
22
28
  private halt;
23
29
  private rules;
24
- /** Round-robin cursor over the spawn points, used once they are all taken. */
30
+ /** Round-robin cursor over the spawn points of each team, used once they are all taken. */
25
31
  private rr;
26
32
  /** Missing rules fall back to RULES. */
27
33
  constructor(rules?: Partial<Rules>, map?: WorldDef);
@@ -33,6 +39,11 @@ export declare class Room {
33
39
  receive(conn: Conn, data: string | ArrayBuffer): void;
34
40
  /** A peer left: its player goes, the roster goes out again. */
35
41
  disconnect(conn: Conn): void;
42
+ /**
43
+ * Makes the player `id` drop the flag he carries, where he stands (the tackle of step 7).
44
+ * False when he carries none or is not there.
45
+ */
46
+ drop(id: number): boolean;
36
47
  /** One host tick. Public so tests can drive the room without a timer. */
37
48
  tick(): void;
38
49
  /**
@@ -51,8 +62,12 @@ export declare class Room {
51
62
  * One the history does not hold stands where it is.
52
63
  */
53
64
  rewind(id: number, view?: number): PlayerState[];
54
- /** The first spawn point with none of `others` within SPAWN_CLEAR, else the next one round-robin. */
65
+ /** The first spawn point of the team with none of `others` within SPAWN_CLEAR, else the next one round-robin. */
55
66
  private place;
67
+ /** The match is over: everyone gets the result and what each player did. */
68
+ private end;
69
+ /** A new match: everyone back at a spawn of his team. */
70
+ private restart;
56
71
  private players;
57
72
  private join;
58
73
  /** Each joined peer gets the full roster with its own id. */
@@ -1,7 +1,20 @@
1
+ /** The two teams: an index into WorldDef.teams, TEAM_NAME and TEAM_COLOR. */
2
+ export declare const TEAM: {
3
+ readonly RED: 0;
4
+ readonly BLUE: 1;
5
+ };
6
+ /** Where a team's flag is: at its base, on a carrier's back, or on the ground where it was dropped. */
7
+ export declare const FLAG: {
8
+ readonly HOME: 0;
9
+ readonly CARRIED: 1;
10
+ readonly DROPPED: 2;
11
+ };
1
12
  export interface PlayerInfo {
2
13
  id: number;
3
14
  name: string;
4
- /** CSS colour, unique within the room. */
15
+ /** TEAM, set when the player joins and kept for the room's life. */
16
+ team: number;
17
+ /** CSS colour: the team's (TEAM_COLOR). */
5
18
  color: string;
6
19
  }
7
20
  /** Bits of Input.keys. Keys are read by KeyboardEvent.code, so WASD is ZQSD on AZERTY. */
@@ -61,6 +74,8 @@ export declare const EV: {
61
74
  readonly WALLRUN_END: 128;
62
75
  readonly SLIDE_START: 256;
63
76
  readonly SLIDE_END: 512;
77
+ /** Fell under the kill floor and was put back at a spawn: the host drops a carried flag. */
78
+ readonly RESPAWN: 1024;
64
79
  };
65
80
  /** One client step: what the player held during 1 / TICK_HZ s, and where they looked. */
66
81
  export interface Input {
@@ -139,14 +154,38 @@ export interface SnapPlayer extends PlayerState {
139
154
  /** Seq of the last input of this player the host applied: the client replays the ones after. */
140
155
  ack: number;
141
156
  }
157
+ /** The flag of a team as a snapshot carries it: only the fields of its state are meaningful, the rest read 0. */
158
+ export interface FlagState {
159
+ /** FLAG. */
160
+ state: number;
161
+ /** CARRIED: the carrier's player id. */
162
+ by: number;
163
+ /** DROPPED: where it lies, metres (the wire keeps 1/16 m), and the whole seconds left before it goes home. */
164
+ x: number;
165
+ y: number;
166
+ z: number;
167
+ left: number;
168
+ }
142
169
  export interface Snapshot {
143
170
  /** Host tick, u16, wraps. */
144
171
  tick: number;
145
172
  players: SnapPlayer[];
173
+ /** Captures per team, red then blue (u8). */
174
+ score: [number, number];
175
+ /** Whole seconds to the end of the match, or, once it is over, to the next one (15 bits). */
176
+ clock: number;
177
+ /** The match is over: the end screen shows until the clock runs out. */
178
+ over: boolean;
179
+ /** The flag of each team, red then blue. */
180
+ flags: [FlagState, FlagState];
146
181
  }
147
182
  /** Room rules, set by the host. Defaults in constants.ts (RULES). */
148
183
  export interface Rules {
149
184
  maxPlayers: number;
185
+ /** Captures that end the match at once. */
186
+ scoreLimit: number;
187
+ /** Seconds a match lasts: the team with more captures wins, a tie is a draw. */
188
+ timeLimit: number;
150
189
  }
151
190
  /**
152
191
  * The subset of WebSocket the client relies on. A real WebSocket (with
@@ -10,13 +10,22 @@ export interface Brush {
10
10
  /** Colour of its ambient light, linear RGB 0 to 1. Absent: white. */
11
11
  tint?: Vec3;
12
12
  }
13
+ /** Feet x, y, z (standing on a top) and the yaw to face. */
14
+ export type Spawn = [x: number, y: number, z: number, yaw: number];
15
+ /** What one team owns on a map. */
16
+ export interface TeamDef {
17
+ /** Where its flag stands (a point on a top, the foot of the pole) and where its carriers score. */
18
+ base: Vec3;
19
+ /** Where its players start, and come back to after a fall. */
20
+ spawns: Spawn[];
21
+ }
13
22
  export interface WorldDef {
14
23
  /** Shown on the title screen. */
15
24
  name?: string;
16
25
  brushes: Brush[];
17
- /** Feet x, y, z (standing on a top) and the yaw to face. */
18
- spawns: [x: number, y: number, z: number, yaw: number][];
19
- /** Feet below this height have fallen off the roofs: the player is put back at a spawn. */
26
+ /** The red team, then the blue one (TEAM). */
27
+ teams: [red: TeamDef, blue: TeamDef];
28
+ /** Feet below this height have fallen off the roofs: the player is put back at a spawn of the team. */
20
29
  floor: number;
21
30
  /** Unit direction toward the sun, and its colour (linear RGB, may exceed 1). */
22
31
  sun: {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@korial29/tiny-fps",
3
3
  "description": "Tiny multiplayer first-person rooftop game for the browser: raw WebGL, zero runtime dependencies, WebSocket or same-browser multi-tab play.",
4
4
  "license": "Apache-2.0",
5
- "version": "0.18.0",
5
+ "version": "0.19.0",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"