@korial29/tiny-fps 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +6 -5
- package/dist/local.js +1 -1
- package/dist/server.js +2106 -272
- package/dist/types/client/effects.d.ts +79 -7
- package/dist/types/client/hud.d.ts +21 -0
- package/dist/types/client/items.d.ts +19 -0
- package/dist/types/client/mesh.d.ts +24 -0
- package/dist/types/client/monsters.d.ts +36 -0
- package/dist/types/client/predict.d.ts +24 -4
- package/dist/types/client/progress.d.ts +41 -0
- package/dist/types/client/render.d.ts +9 -17
- package/dist/types/shared/constants.d.ts +39 -0
- package/dist/types/shared/level.d.ts +2 -0
- package/dist/types/shared/levels.d.ts +2 -0
- package/dist/types/shared/map.d.ts +2 -1
- package/dist/types/shared/monsters.d.ts +23 -0
- package/dist/types/shared/physics.d.ts +22 -5
- package/dist/types/shared/protocol.d.ts +15 -2
- package/dist/types/shared/room.d.ts +50 -10
- package/dist/types/shared/shoot.d.ts +12 -3
- package/dist/types/shared/types.d.ts +128 -1
- package/package.json +1 -1
|
@@ -1,10 +1,41 @@
|
|
|
1
|
-
import type { PlayerState, Shot } from '../shared/types';
|
|
2
|
-
type Vec3
|
|
1
|
+
import type { Bullet, GameEvent, Level, Monster, PlayerState, Shot } from '../shared/types';
|
|
2
|
+
import type { Vec3 } from './mesh';
|
|
3
3
|
export interface Spark {
|
|
4
4
|
p: Vec3;
|
|
5
5
|
v: Vec3;
|
|
6
6
|
/** Seconds left. */
|
|
7
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
|
+
/** What the client keeps of each monster it has drawn. */
|
|
33
|
+
export interface Walker {
|
|
34
|
+
x: number;
|
|
35
|
+
z: number;
|
|
36
|
+
/** Distance covered, metres: the limbs swing with it. */
|
|
37
|
+
walked: number;
|
|
38
|
+
kind: number;
|
|
8
39
|
}
|
|
9
40
|
/** What the renderer and the camera read; update and shot move it. */
|
|
10
41
|
export interface Effects {
|
|
@@ -24,14 +55,55 @@ export interface Effects {
|
|
|
24
55
|
/** Seconds of flash left at each other shooter, by player id. */
|
|
25
56
|
flashes: Map<number, number>;
|
|
26
57
|
sparks: Spark[];
|
|
27
|
-
|
|
28
|
-
|
|
58
|
+
gibs: Gib[];
|
|
59
|
+
blasts: Blast[];
|
|
60
|
+
/** Seconds of the red hurt tint left. */
|
|
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;
|
|
67
|
+
/** Seconds of blow left at each monster, by id. */
|
|
68
|
+
swings: Map<number, number>;
|
|
69
|
+
/** Every monster seen so far, by id. Ids are bounded, so it is too. */
|
|
70
|
+
herd: Map<number, Walker>;
|
|
71
|
+
/** Unit heading of each bullet in flight, by id, once it has moved. */
|
|
72
|
+
aim: Map<number, Vec3>;
|
|
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;
|
|
29
84
|
/**
|
|
30
85
|
* A shot, from the shooter's eye; own ones kick the camera and the gun. No sparks with
|
|
31
86
|
* `sparks` false: a shot that hit the viewer would burst them inside the camera.
|
|
32
87
|
*/
|
|
33
88
|
shot(s: Shot, from: Vec3, own: boolean, sparks?: boolean): void;
|
|
89
|
+
/** The monsters and bullets drawn this frame: how far each walked, which way each bullet flies. */
|
|
90
|
+
track(monsters: Monster[], bullets: Bullet[]): void;
|
|
91
|
+
/** A host event, once delayed to line up with the drawn monsters; `you` is the own player id. */
|
|
92
|
+
event(e: GameEvent, you: number): void;
|
|
34
93
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export {};
|
|
94
|
+
export declare const BLAST = 0.3;
|
|
95
|
+
/** Half the side of an explosion's glow: it swells fast, then shrinks to nothing as it ends. */
|
|
96
|
+
export declare const glow: ({ r, t }: Blast) => number;
|
|
97
|
+
/**
|
|
98
|
+
* Holds what the host reported at `now` for INTERP_DELAY ms, so it fires in step with the others,
|
|
99
|
+
* who are drawn that far in the past. Keeps at most `max`: a hidden tab does not grow it.
|
|
100
|
+
*/
|
|
101
|
+
export declare const createDelay: <T>(max?: number) => {
|
|
102
|
+
/** Forgets what is held: it belongs to a level that is gone. */
|
|
103
|
+
clear(): void;
|
|
104
|
+
push(items: T[], now: number): void;
|
|
105
|
+
/** What is due at `now`, oldest first. */
|
|
106
|
+
due(now: number): T[];
|
|
107
|
+
};
|
|
108
|
+
/** rand in [0, 1): injectable so the tests are exact. The level lets gibs land and bounce off walls. */
|
|
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,24 @@
|
|
|
1
|
+
export type Vec3 = [number, number, number];
|
|
2
|
+
/**
|
|
3
|
+
* Floats per vertex: position, normal, then c. A map vertex has c = (u, v, texture layer, light),
|
|
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).
|
|
6
|
+
*/
|
|
7
|
+
export declare const STRIDE = 10;
|
|
8
|
+
/**
|
|
9
|
+
* Camera axes [right, up, forward]: forward is (-sin yaw cos pitch, sin pitch, -cos yaw cos pitch),
|
|
10
|
+
* y up at roll 0. A positive roll leans the camera right: up tilts toward right.
|
|
11
|
+
*/
|
|
12
|
+
export declare const basis: (yaw: number, pitch: number, roll?: number) => [Vec3, Vec3, Vec3];
|
|
13
|
+
/**
|
|
14
|
+
* Appends the 36 vertices of a box centred on (cx, cy, cz) with half sizes (hx, hy, hz), turned
|
|
15
|
+
* by yaw about its own vertical axis (local forward, -z, ends up along forward(yaw)).
|
|
16
|
+
*/
|
|
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. */
|
|
19
|
+
export declare const dress: (v: number[], [r, g, b]: number[]) => number[];
|
|
20
|
+
/**
|
|
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.
|
|
23
|
+
*/
|
|
24
|
+
export declare const place: (out: number[], src: number[], eye: Vec3, [r, u, f]: Vec3[], off: Vec3, k: number, spin?: number) => void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Bullet, Monster } from '../shared/types';
|
|
2
|
+
import type { Vec3 } from './mesh';
|
|
3
|
+
/** Seconds a walker's blow takes. */
|
|
4
|
+
export declare const SWING = 0.3;
|
|
5
|
+
/** Limb phase per metre walked: a full stride every 1.75 m. */
|
|
6
|
+
export declare const GAIT = 3.6;
|
|
7
|
+
/** Flat colours, shared with the gibs. Eyes are the unlit layer: they glow in the dark. */
|
|
8
|
+
export declare const COLOR: {
|
|
9
|
+
body: number[];
|
|
10
|
+
arm: number[];
|
|
11
|
+
leg: number[];
|
|
12
|
+
head: number[];
|
|
13
|
+
shell: number[];
|
|
14
|
+
fin: number[];
|
|
15
|
+
gore: number[];
|
|
16
|
+
calm: number[];
|
|
17
|
+
chase: number[];
|
|
18
|
+
blob: number[];
|
|
19
|
+
core: number[];
|
|
20
|
+
};
|
|
21
|
+
/** What a monster of each MONSTER kind bursts into. */
|
|
22
|
+
export declare const CHUNKS: number[][][];
|
|
23
|
+
/** Arm angle during a blow, `s` in (0, 1] the share of SWING elapsed: wind up, then strike. */
|
|
24
|
+
export declare const strike: (s: number) => number;
|
|
25
|
+
/**
|
|
26
|
+
* Appends a walker: `walked` is the distance it has covered (the limbs swing with it, so a
|
|
27
|
+
* standing one is still), `blow` the share of SWING elapsed, 0 when not swinging.
|
|
28
|
+
*/
|
|
29
|
+
export declare const walker: (out: number[], m: Monster, walked: number, blow: number) => void;
|
|
30
|
+
/** Appends a flyer at time t (seconds): it bobs on a slow sine and its fins spin. */
|
|
31
|
+
export declare const flyer: (out: number[], m: Monster, t: number) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Appends a bullet: a glowing blob with a short tail behind it when `dir` (unit, its heading) is
|
|
34
|
+
* known.
|
|
35
|
+
*/
|
|
36
|
+
export declare const bullet: (out: number[], b: Bullet, dir?: Vec3) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Input, Level, PlayerState, Shot, Snapshot } from '../shared/types';
|
|
1
|
+
import type { Bullet, Input, Level, Monster, PlayerState, Shot, 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;
|
|
@@ -11,10 +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)
|
|
15
|
-
*
|
|
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.
|
|
16
18
|
*/
|
|
17
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;
|
|
18
29
|
/** A decoded snapshot, received at `now` (ms, performance.now()). */
|
|
19
30
|
snapshot(s: Snapshot, now: number): void;
|
|
20
31
|
/**
|
|
@@ -25,5 +36,14 @@ export interface Predictor {
|
|
|
25
36
|
me(alpha: number): PlayerState | undefined;
|
|
26
37
|
/** The other players at now - INTERP_DELAY; a player missing from the latest snapshot is gone. */
|
|
27
38
|
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[];
|
|
28
48
|
}
|
|
29
|
-
export declare const createPredictor: (
|
|
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,34 +1,26 @@
|
|
|
1
|
-
import type { Edge, Level, PlayerState } from '../shared/types';
|
|
1
|
+
import type { Bullet, Edge, Item, Level, Monster, PlayerState } from '../shared/types';
|
|
2
2
|
import type { Effects } from './effects';
|
|
3
|
-
type Vec3
|
|
4
|
-
/**
|
|
5
|
-
* Camera axes [right, up, forward]: forward is (-sin yaw cos pitch, sin pitch, -cos yaw cos pitch),
|
|
6
|
-
* y up at roll 0. A positive roll leans the camera right: up tilts toward right.
|
|
7
|
-
*/
|
|
8
|
-
export declare const basis: (yaw: number, pitch: number, roll?: number) => [Vec3, Vec3, Vec3];
|
|
3
|
+
import type { Vec3 } from './mesh';
|
|
9
4
|
/** Column-major view-projection matrix of basis(yaw, pitch, roll) at eye, 70° vertical field of view. */
|
|
10
5
|
export declare const viewProj: (eye: Vec3, yaw: number, pitch: number, aspect: number, roll?: number) => Float32Array<ArrayBuffer>;
|
|
11
6
|
/** A world point on screen, in [0, 1] from the top left; undefined behind the camera. */
|
|
12
7
|
export declare const project: (m: Float32Array, x: number, y: number, z: number) => [number, number] | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* Appends the 36 vertices of a box centred on (cx, cy, cz) with half sizes (hx, hy, hz), turned
|
|
15
|
-
* by yaw about its own vertical axis (local forward, -z, ends up along forward(yaw)).
|
|
16
|
-
*/
|
|
17
|
-
export declare const pushBox: (out: number[], [cx, cy, cz]: Vec3, [hx, hy, hz]: Vec3, yaw: number, color: number[], layer?: number) => void;
|
|
18
8
|
/** Vertical spans [y0, y1] an edge draws on its own side: the wall, or the steps of a portal. */
|
|
19
9
|
export declare const spans: ({ map }: Level, { front, back }: Edge) => [number, number][];
|
|
20
10
|
/** Floors and ceilings as fans, then every edge's walls as quads, in the vertex format above. */
|
|
21
11
|
export declare const levelVerts: (lvl: Level) => number[];
|
|
22
12
|
export interface Renderer {
|
|
23
13
|
/**
|
|
24
|
-
* Draws one frame: the map,
|
|
25
|
-
*
|
|
14
|
+
* Draws one frame: the map, its gates, goal and items, the others, the monsters, their bullets
|
|
15
|
+
* and the effects as seen from eye, with the view model on top (not while fx.dead). colors maps
|
|
16
|
+
* player id to CSS.
|
|
26
17
|
*/
|
|
27
|
-
frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects): void;
|
|
18
|
+
frame(eye: Vec3, yaw: number, pitch: number, others: PlayerState[], colors: ReadonlyMap<number, string>, fx: Effects, monsters: Monster[], bullets: Bullet[], items: Item[]): void;
|
|
19
|
+
/** Builds the geometry of another level, drawn from the next frame on. */
|
|
20
|
+
level(lvl: Level): void;
|
|
28
21
|
/** A world point on screen as of the last frame, in [0, 1] from the top left. */
|
|
29
22
|
project(x: number, y: number, z: number): [number, number] | undefined;
|
|
30
23
|
destroy(): void;
|
|
31
24
|
}
|
|
32
25
|
/** Throws when the browser has no WebGL2. */
|
|
33
|
-
export declare const createRenderer: (canvas: HTMLCanvasElement,
|
|
34
|
-
export {};
|
|
26
|
+
export declare const createRenderer: (canvas: HTMLCanvasElement, first: Level) => Renderer;
|
|
@@ -41,6 +41,45 @@ export declare const MAX_REWIND = 30;
|
|
|
41
41
|
*/
|
|
42
42
|
export declare const INPUT_BURST = 10;
|
|
43
43
|
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;
|
|
44
83
|
/** Longest player name, in characters (code points). */
|
|
45
84
|
export declare const MAX_NAME = 16;
|
|
46
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. */
|
|
@@ -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;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Bullet, GameEvent, Level, Monster, PlayerState } from './types';
|
|
2
|
+
/** Mulberry32: a small seeded generator, uniform in [0, 1). */
|
|
3
|
+
export declare const mulberry32: (seed: number) => (() => number);
|
|
4
|
+
export interface Horde {
|
|
5
|
+
/** The living monsters, copied. */
|
|
6
|
+
monsters(): Monster[];
|
|
7
|
+
/** The bullets in flight, copied. */
|
|
8
|
+
bullets(): Bullet[];
|
|
9
|
+
/** What happened since the owner last emptied it: the owner takes events off the front. */
|
|
10
|
+
events: GameEvent[];
|
|
11
|
+
/** One host tick, with the players' states. */
|
|
12
|
+
step(players: PlayerState[]): 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;
|
|
18
|
+
}
|
|
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;
|
|
@@ -1,16 +1,32 @@
|
|
|
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'>;
|
|
2
5
|
export declare const TAU: number;
|
|
3
6
|
/** An angle in [0, 2π). */
|
|
4
7
|
export declare const norm: (a: number) => number;
|
|
5
8
|
/** Unit vector the player faces at yaw, on the floor plane: yaw 0 looks toward -z. */
|
|
6
9
|
export declare const forward: (yaw: number) => [x: number, z: number];
|
|
10
|
+
/**
|
|
11
|
+
* Moves the feet by (dx, dz) for 1 / TICK_HZ s, then a jump from the ground, GRAVITY and the
|
|
12
|
+
* collisions of the cylinder (PLAYER_R, PLAYER_H) with the sectors of the level: it slides along
|
|
13
|
+
* shut edges (see shut and push), stands on the highest floor under the circle (a step up to
|
|
14
|
+
* 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.
|
|
16
|
+
*/
|
|
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;
|
|
7
27
|
/**
|
|
8
28
|
* Applies one input for 1 / TICK_HZ s, in place: yaw and pitch from the input (pitch clamped to
|
|
9
|
-
* MAX_PITCH), RUN_SPEED along the held keys (diagonals not faster),
|
|
10
|
-
* GRAVITY, then collisions of the cylinder (PLAYER_R, PLAYER_H) with the sectors of the level:
|
|
11
|
-
* it slides along shut edges (see shut and push), stands on the highest floor under the circle
|
|
12
|
-
* (a step up to STEP_H is climbed at once, a higher one needs a jump, a ledge is a fall), and
|
|
13
|
-
* bumps its head on the lowest ceiling.
|
|
29
|
+
* MAX_PITCH), RUN_SPEED along the held keys (diagonals not faster), then walk().
|
|
14
30
|
* The chaingun: `cool` counts down one per step, RUN_SPEED is scaled by FIRE_SLOW while KEY.FIRE
|
|
15
31
|
* is held, and the step that finds it held with `cool` at 0 re-arms it to FIRE_EVERY and returns
|
|
16
32
|
* true: the caller resolves a shot (one every FIRE_EVERY steps, the first at once).
|
|
@@ -18,3 +34,4 @@ export declare const forward: (yaw: number) => [x: number, z: number];
|
|
|
18
34
|
export declare const move: (p: PlayerState, i: Input, lvl: Level) => boolean;
|
|
19
35
|
/** A player standing on the floor at spawn point n of the map (modulo the count). */
|
|
20
36
|
export declare const spawn: (id: number, lvl: Level, n: number) => PlayerState;
|
|
37
|
+
export {};
|
|
@@ -9,13 +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 =
|
|
17
|
-
export declare const SNAP_PLAYER =
|
|
25
|
+
export declare const SNAP_HEAD = 7;
|
|
26
|
+
export declare const SNAP_PLAYER = 25;
|
|
18
27
|
export declare const SNAP_SHOT = 14;
|
|
28
|
+
export declare const SNAP_MONSTER = 16;
|
|
29
|
+
export declare const SNAP_BULLET = 13;
|
|
30
|
+
export declare const SNAP_EVENT = 14;
|
|
31
|
+
export declare const SNAP_ITEM = 14;
|
|
19
32
|
/**
|
|
20
33
|
* The input as the host will read it after encodeInput and decodeInput: yaw, pitch and view
|
|
21
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.
|
|
@@ -9,23 +9,49 @@ import type { Conn, Every, Rules } from './types';
|
|
|
9
9
|
* - Each input frame moves its player at once with move(); the INPUT_BURST bank drops the excess.
|
|
10
10
|
* A step that fires resolves its shot at once with fire(), the other players rewound to the
|
|
11
11
|
* view tick of the input (lag compensation, at most MAX_REWIND ticks back).
|
|
12
|
-
* -
|
|
13
|
-
*
|
|
12
|
+
* - The room owns the horde (monsters.ts), stepped every tick while a player is present. A shot
|
|
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.
|
|
22
|
+
* - Every SNAP_EVERY ticks of TICK_HZ, one snapshot with every player, the shots resolved since
|
|
23
|
+
* the last one, the monsters, the bullets, the events since the last one and the items goes to
|
|
24
|
+
* every peer.
|
|
14
25
|
*/
|
|
15
26
|
export declare class Room {
|
|
16
27
|
/** Every connected peer; null until it joins. */
|
|
17
28
|
private peers;
|
|
18
29
|
private ticks;
|
|
19
|
-
/** The players as each snapshot of the last MAX_REWIND ticks sent them. */
|
|
30
|
+
/** The players and monsters as each snapshot of the last MAX_REWIND ticks sent them. */
|
|
20
31
|
private history;
|
|
32
|
+
private maps;
|
|
33
|
+
private lvl;
|
|
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;
|
|
21
47
|
/** Shots resolved since the last snapshot. */
|
|
22
48
|
private shots;
|
|
23
49
|
private halt;
|
|
24
50
|
private rules;
|
|
25
51
|
/** Round-robin cursor over the spawn points, used once they are all taken. */
|
|
26
52
|
private rr;
|
|
27
|
-
/** Missing rules fall back to RULES. */
|
|
28
|
-
constructor(rules?: Partial<Rules
|
|
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[]);
|
|
29
55
|
/** Number of joined players. */
|
|
30
56
|
get size(): number;
|
|
31
57
|
/** A peer opened. Nothing is sent until it joins. */
|
|
@@ -46,12 +72,26 @@ export declare class Room {
|
|
|
46
72
|
start(every?: Every): void;
|
|
47
73
|
stop(): void;
|
|
48
74
|
/**
|
|
49
|
-
* The
|
|
50
|
-
* read against the current tick and clamped to the kept history):
|
|
51
|
-
* the two snapshots around it like the client
|
|
52
|
-
* where it is.
|
|
75
|
+
* The bodies a shot of `shooter` can hit as the shooter drew them at `view` (a u16 tick,
|
|
76
|
+
* fractional, read against the current tick and clamped to the kept history): the other players
|
|
77
|
+
* and the monsters, x, y, z interpolated between the two snapshots around it like the client
|
|
78
|
+
* does. One the history does not hold stands where it is.
|
|
53
79
|
*/
|
|
54
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;
|
|
55
95
|
private players;
|
|
56
96
|
private join;
|
|
57
97
|
/** Each joined peer gets the full roster with its own id. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Level, PlayerState, Shot } from './types';
|
|
1
|
+
import type { Body, Level, Monster, PlayerState, Shot } from './types';
|
|
2
2
|
type Vec3 = [number, number, number];
|
|
3
3
|
/**
|
|
4
4
|
* Unit direction of a shot: the view direction at yaw and pitch (yaw 0, pitch 0 is -z; pitch > 0
|
|
@@ -15,10 +15,19 @@ export declare const aim: (yaw: number, pitch: number, seq: number) => Vec3;
|
|
|
15
15
|
* ceiling. A solid edge, or a portal whose opening does not hold the crossing height, ends it.
|
|
16
16
|
*/
|
|
17
17
|
export declare const trace: (lvl: Level, o: Vec3, d: Vec3, max: number) => number;
|
|
18
|
+
/**
|
|
19
|
+
* Distance at which the ray enters the upright cylinder of t (sides and caps), Infinity on a miss:
|
|
20
|
+
* the span of the ray inside the infinite cylinder, cut to the span between the cap planes.
|
|
21
|
+
*/
|
|
22
|
+
export declare const hit: (o: Vec3, d: Vec3, t: Body) => number;
|
|
23
|
+
/** The body a shot sees of a player. */
|
|
24
|
+
export declare const body: ({ id, x, y, z }: PlayerState) => Body;
|
|
25
|
+
/** The body a shot sees of a monster. */
|
|
26
|
+
export declare const monsterBody: ({ id, kind, x, y, z }: Monster) => Body;
|
|
18
27
|
/**
|
|
19
28
|
* Resolves one shot of `shooter` (state after the step that fired) from its eye (feet + EYE)
|
|
20
29
|
* along aim(yaw, pitch, seq): the nearest of the level (trace) and the upright cylinders
|
|
21
|
-
* (
|
|
30
|
+
* of `targets` (bodies: players, monsters) other than the shooter, within RANGE.
|
|
22
31
|
*/
|
|
23
|
-
export declare const fire: (lvl: Level, shooter: PlayerState, seq: number, targets:
|
|
32
|
+
export declare const fire: (lvl: Level, shooter: PlayerState, seq: number, targets: Body[]) => Shot;
|
|
24
33
|
export {};
|