@korial29/tiny-fps 0.6.0 → 0.8.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/README.md +3 -3
- package/dist/index.js +19 -10
- package/dist/local.js +1 -1
- package/dist/server.js +112 -95
- package/dist/types/client/audio.d.ts +11 -2
- package/dist/types/client/effects.d.ts +3 -0
- package/dist/types/client/hud.d.ts +15 -5
- package/dist/types/client/progress.d.ts +14 -4
- package/dist/types/client/render.d.ts +9 -0
- package/dist/types/client/sfx.d.ts +2 -0
- package/dist/types/shared/protocol.d.ts +7 -1
- package/dist/types/shared/room.d.ts +2 -1
- package/dist/types/shared/types.d.ts +10 -0
- package/package.json +1 -1
|
@@ -10,9 +10,9 @@ export interface Audio {
|
|
|
10
10
|
listen(eye: Vec3, yaw: number): void;
|
|
11
11
|
/**
|
|
12
12
|
* Plays the SOUND `id`. With `at`, panned left or right by its direction from the listener and
|
|
13
|
-
* fainter with distance; without, centred
|
|
13
|
+
* fainter with distance; without, centred (the own player's sounds). `gain` scales the volume.
|
|
14
14
|
*/
|
|
15
|
-
play(id: number, at?: Vec3): void;
|
|
15
|
+
play(id: number, at?: Vec3, gain?: number): void;
|
|
16
16
|
/** Mutes or unmutes everything, music included. */
|
|
17
17
|
mute(on: boolean): void;
|
|
18
18
|
readonly muted: boolean;
|
|
@@ -24,6 +24,15 @@ export declare const createAudio: () => Audio;
|
|
|
24
24
|
export declare const hear: (a: Audio, { type, id, x, y, z }: GameEvent, you: number) => void;
|
|
25
25
|
/** Returns a function that plays CLOCK once a second while called with `on`; `now` in ms. */
|
|
26
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;
|
|
27
36
|
/** The mute choice of the last visit. Storage throws when blocked: no memory then. */
|
|
28
37
|
export declare const savedMute: () => boolean;
|
|
29
38
|
/** Flips mute, remembers it, and returns the new state. */
|
|
@@ -92,6 +92,9 @@ export interface Effects {
|
|
|
92
92
|
event(e: GameEvent, you: number): void;
|
|
93
93
|
}
|
|
94
94
|
export declare const BLAST = 0.3;
|
|
95
|
+
/** Seconds the hit vignette and the pickup fade take to go out. */
|
|
96
|
+
export declare const HURT = 0.45;
|
|
97
|
+
export declare const GAIN = 0.4;
|
|
95
98
|
/** Half the side of an explosion's glow: it swells fast, then shrinks to nothing as it ends. */
|
|
96
99
|
export declare const glow: ({ r, t }: Blast) => number;
|
|
97
100
|
/**
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
/** Slots of say(): a title, a hint under it
|
|
1
|
+
/** Slots of say(): a title, a hint under it; and seconds each stays up (the end screen is the third). */
|
|
2
2
|
export declare const SAY: {
|
|
3
3
|
readonly TITLE: 0;
|
|
4
4
|
readonly NOTE: 1;
|
|
5
|
-
readonly END: 2;
|
|
6
5
|
};
|
|
6
|
+
/** A player's line of the end screen. */
|
|
7
|
+
export type Score = [name: string, color: string, kills: number, deaths: number];
|
|
7
8
|
export declare const HUD_CSS: string;
|
|
8
9
|
export interface Hud {
|
|
9
|
-
/**
|
|
10
|
+
/** The own health: the bar's width, number and colour. It flashes on a rise and shakes on a fall. */
|
|
10
11
|
hp(n: number): void;
|
|
11
12
|
/** The keys held, as the snapshot's bit set (1 << ITEM.KEY_*). */
|
|
12
13
|
keys(bits: number): void;
|
|
13
|
-
/** The own player is dead
|
|
14
|
-
dead(
|
|
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
|
+
/** 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;
|
|
15
25
|
/** Shows or hides the muted mark. */
|
|
16
26
|
mute(on: boolean): void;
|
|
17
27
|
/** Shows text in a SAY slot, for that slot's time. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Item, Level, MapDef, Snapshot } from '../shared/types';
|
|
1
|
+
import type { Item, Level, MapDef, PlayerInfo, Snapshot } from '../shared/types';
|
|
2
2
|
import type { Audio } from './audio';
|
|
3
3
|
import type { Effects } from './effects';
|
|
4
4
|
import type { Hud } from './hud';
|
|
@@ -11,20 +11,30 @@ export interface Progress {
|
|
|
11
11
|
readonly items: Item[];
|
|
12
12
|
/** The own player has no health left. */
|
|
13
13
|
readonly dead: boolean;
|
|
14
|
+
/** The own health: 0 when dead or unknown. */
|
|
15
|
+
readonly hp: number;
|
|
16
|
+
/** The level's number, name and mode, for the title screen. */
|
|
17
|
+
readonly name: string;
|
|
14
18
|
/** The level is in its RETURN phase: the team runs back to the exit. */
|
|
15
19
|
readonly returning: boolean;
|
|
16
20
|
/** False for a player the latest snapshot shows without health: not drawn. */
|
|
17
21
|
alive(id: number): boolean;
|
|
18
22
|
/** A snapshot, before the predictor sees it: a new level or `hard` switches everything. */
|
|
19
23
|
snapshot(s: Snapshot): void;
|
|
20
|
-
/** The run is won: the end screen with its time. */
|
|
21
|
-
end(ticks: number, hard: boolean
|
|
24
|
+
/** The run is won: the end screen with its time and the players' kills and deaths. */
|
|
25
|
+
end(ticks: number, hard: boolean, stats: {
|
|
26
|
+
id: number;
|
|
27
|
+
kills: number;
|
|
28
|
+
deaths: number;
|
|
29
|
+
}[]): void;
|
|
22
30
|
}
|
|
23
31
|
export interface Deps {
|
|
24
32
|
/** The level the predictor, renderer and effects were built with. */
|
|
25
33
|
lvl: Level;
|
|
26
34
|
/** The own player id, -1 while unknown. */
|
|
27
35
|
you(): number;
|
|
36
|
+
/** Everyone in the room. */
|
|
37
|
+
roster(): PlayerInfo[];
|
|
28
38
|
predictor: {
|
|
29
39
|
level(lvl: Level): void;
|
|
30
40
|
};
|
|
@@ -43,4 +53,4 @@ export interface Deps {
|
|
|
43
53
|
}
|
|
44
54
|
/** The yaw of the spawn nearest (x, z): where a player put back at the start should look. */
|
|
45
55
|
export declare const facing: ({ spawns }: MapDef, x: number, z: number) => number;
|
|
46
|
-
export declare const createProgress: ({ lvl, you, predictor, rd, delays, fx, hud, audio, }: Deps) => Progress;
|
|
56
|
+
export declare const createProgress: ({ lvl, you, roster, predictor, rd, delays, fx, hud, audio, }: Deps) => Progress;
|
|
@@ -2,6 +2,11 @@ import type { Bullet, Edge, Item, Level, Monster, PlayerState } from '../shared/
|
|
|
2
2
|
import type { Effects } from './effects';
|
|
3
3
|
import type { Light } from './lights';
|
|
4
4
|
import type { Vec3 } from './mesh';
|
|
5
|
+
/**
|
|
6
|
+
* Blinn-Phong strength and exponent: a row per TEX id in order (brick, tile, lava, stone, metal, wood,
|
|
7
|
+
* moss, grate), then the flat bodies. Lava and glows never get here: they light themselves.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SPEC: number[][];
|
|
5
10
|
/**
|
|
6
11
|
* Column-major view-projection matrix of basis(yaw, pitch, roll) at eye. t is the tangent of half the
|
|
7
12
|
* vertical field of view (70° by default), [N, F] the near and far clip distances.
|
|
@@ -46,5 +51,9 @@ export interface Renderer {
|
|
|
46
51
|
project(x: number, y: number, z: number): [number, number] | undefined;
|
|
47
52
|
destroy(): void;
|
|
48
53
|
}
|
|
54
|
+
/** Pixels drawn at most (1080p): every one is lit per light and shadow map, so a 4K screen at a pixel ratio of 2 would pay for 8 million. */
|
|
55
|
+
export declare const MAX_PIXELS: number;
|
|
56
|
+
/** The canvas size in device pixels: the CSS size times the pixel ratio (2 at most), scaled down to MAX_PIXELS. */
|
|
57
|
+
export declare const backing: (cw: number, ch: number, dpr: number) => [number, number];
|
|
49
58
|
/** Throws when the browser has no WebGL2. */
|
|
50
59
|
export declare const createRenderer: (canvas: HTMLCanvasElement, first: Level) => Renderer;
|
|
@@ -14,6 +14,8 @@ export declare const SOUND: {
|
|
|
14
14
|
readonly CLOCK: 4;
|
|
15
15
|
/** A bullet bursting on a wall. */
|
|
16
16
|
readonly BURST: 5;
|
|
17
|
+
/** A heartbeat, looped by the client while the own health is low. */
|
|
18
|
+
readonly HEART: 6;
|
|
17
19
|
};
|
|
18
20
|
/**
|
|
19
21
|
* Renders the SOUND `id` as mono samples in [-1, 1] at RATE, deterministic (seeded noise), a few
|
|
@@ -12,12 +12,18 @@ export type ServerText = {
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
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.
|
|
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.
|
|
16
17
|
*/
|
|
17
18
|
| {
|
|
18
19
|
t: 'end';
|
|
19
20
|
ticks: number;
|
|
20
21
|
hard: boolean;
|
|
22
|
+
stats: {
|
|
23
|
+
id: number;
|
|
24
|
+
kills: number;
|
|
25
|
+
deaths: number;
|
|
26
|
+
}[];
|
|
21
27
|
};
|
|
22
28
|
export declare const MSG_INPUT = 1;
|
|
23
29
|
export declare const MSG_SNAPSHOT = 2;
|
|
@@ -18,7 +18,8 @@ import type { Conn, Every, MapDef, Rules } from './types';
|
|
|
18
18
|
* opens its gates for the team, a pack heals below full health.
|
|
19
19
|
* - Touching the goal turns the level from HUNT to RETURN (the exit opens); when every living
|
|
20
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' }
|
|
21
|
+
* last, every player gets { t: 'end' } with the run's kills and deaths per player, and a new
|
|
22
|
+
* run starts at level 0, hard from then on, the counts back at 0.
|
|
22
23
|
* - Every SNAP_EVERY ticks of TICK_HZ, one snapshot with every player, the shots resolved since
|
|
23
24
|
* the last one, the monsters, the bullets, the events since the last one and the items goes to
|
|
24
25
|
* every peer.
|
|
@@ -155,6 +155,14 @@ export declare const TEX: {
|
|
|
155
155
|
readonly TILE: 1;
|
|
156
156
|
readonly LAVA: 2;
|
|
157
157
|
readonly STONE: 3;
|
|
158
|
+
/** Riveted metal plates. */
|
|
159
|
+
readonly METAL: 4;
|
|
160
|
+
/** Planks, the grain running along u. */
|
|
161
|
+
readonly WOOD: 5;
|
|
162
|
+
/** Stone blocks with moss in the joints. */
|
|
163
|
+
readonly MOSS: 6;
|
|
164
|
+
/** Metal floor grating over darkness. */
|
|
165
|
+
readonly GRATE: 7;
|
|
158
166
|
};
|
|
159
167
|
/**
|
|
160
168
|
* A room, Doom style: a convex polygon on the floor plane with a flat floor and a flat ceiling.
|
|
@@ -179,6 +187,8 @@ export interface Sector {
|
|
|
179
187
|
light?: number;
|
|
180
188
|
}
|
|
181
189
|
export interface MapDef {
|
|
190
|
+
/** Shown on the title screen after the level number. */
|
|
191
|
+
name?: string;
|
|
182
192
|
sectors: Sector[];
|
|
183
193
|
/** Spawn points: feet x, z (inside a sector, standing on its floor) and the yaw to face. */
|
|
184
194
|
spawns: [x: number, z: number, yaw: number][];
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@korial29/tiny-fps",
|
|
3
3
|
"description": "Tiny multiplayer first-person shooter for the browser: raw WebGL, zero runtime dependencies, WebSocket or same-browser multi-tab play.",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.8.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|