@korial29/tiny-fps 0.33.0 → 0.34.1

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.
@@ -4,7 +4,9 @@ import type { Quat } from './rig';
4
4
  /** Where the blade starts and ends along the model's forward axis, metres from the right hand: a metre from the guard to the point. */
5
5
  export declare const BASE: number, TIP: number;
6
6
  /** The left hand grips this far behind the right one: a gap between the two fists. */
7
- export declare const BEHIND = 0.14;
7
+ export declare const BEHIND = 0.1;
8
+ /** The tilt between the grip and the hand's thumb: the blade rises off the forearm's line. */
9
+ export declare const S: number, C: number;
8
10
  /**
9
11
  * The katana at a level of detail (0 far, 1 near), built once, in the vertex format of mesh.ts: the
10
12
  * blade (bevelled edge, a ridge, a spine, a point), a thin cyan glow along its edge, a collar, a
@@ -29,21 +31,16 @@ export declare const held: (out: number[], pos: Vec3, q: Quat, lod: number, t?:
29
31
  /** The root of the blade and its point, in the world, for the hand at `pos` turned by `q`. */
30
32
  export declare const ends: (pos: Vec3, q: Quat) => Vec3[];
31
33
  /**
32
- * The axes [right, up, forward] in the camera's space (right, up, forward: a mirror of the world's)
33
- * for a blade along `d`, rolled by `roll` about it: right as near (cos, sin, 0) as it can be, up
34
- * forward cross right, so that the frame is a proper turn whichever way the blade points.
35
- */
36
- export declare const frameOf: (d: Vec3, roll: number) => Vec3[];
37
- /**
38
- * The cuts. Each is keys of [share of the swing, grip x, y, z, blade direction x, y, z, roll] in
39
- * the camera's space (right, up, forward), the guard first and last: a wind-up, the strike at its
40
- * tick (every cut passes the middle of the view there) and a follow-through, with the hands taking
41
- * the slope between their neighbours' keys (fastest through the strike). Both hands hold the grip,
42
- * the left BEHIND the right. The wind-ups and follow-throughs go out of the view. The guard is
43
- * rolled a little, its flat toward the eye.
34
+ * The cuts, held the way Jedi Knight 2 holds its saber in the first person: the hands stay low at
35
+ * the right, close together on the grip, and the blade makes the wide arcs. Each cut is keys of
36
+ * [share of the swing, grip x, y, z, blade direction x, y, z] in the camera's space (right, up,
37
+ * forward), the guard first and last: a wind-up, the strike at its tick (every cut passes the
38
+ * middle of the view there) and a follow-through, with the hands taking the slope between their
39
+ * neighbours' keys (fastest through the strike). The right hand holds the grip at the guard, the
40
+ * left BEHIND it. In the guard the blade rises across the view, up and to the left.
44
41
  */
45
42
  export declare const GUARD: number[];
46
- /** The grip and the blade direction (x, y, z each) and the roll of cut `cut` at `p` of the swing: one array, rewritten by each call. */
43
+ /** The grip and the blade direction (x, y, z each) of cut `cut` at `p` of the swing: one array, rewritten by each call. */
47
44
  export declare const stroke: (cut: number, p: number) => number[];
48
45
  /**
49
46
  * How far through its cut a player is, 0 to 1, or -1 when it is not cutting. `swing` counts down
@@ -106,7 +106,7 @@ export interface Renderer {
106
106
  lights: Light[], body?: Body,
107
107
  /** The bases, the flags, the racks and the health packs: drawn lit, casting shadows, with the other players. */
108
108
  ctf?: CtfScene,
109
- /** The laser beams: glowing ribbons that cast no shadow. */
109
+ /** The plasma balls, the flashes and the sparks: they glow and cast no shadow. */
110
110
  tracer?: Tracer): void;
111
111
  /** A world point on screen as of the last frame, in [0, 1] from the top left. */
112
112
  project(x: number, y: number, z: number): [number, number] | undefined;
@@ -171,8 +171,17 @@ export declare const HP_MAX = 5;
171
171
  export declare const AMMO_MAX = 60;
172
172
  /** Ticks between two shots while the trigger is held: 8.6 shots a second. */
173
173
  export declare const GUN_COOLDOWN = 7;
174
- /** Metres a laser reaches. */
174
+ /** Metres a shot reaches: a plasma ball that has flown this far is gone. */
175
175
  export declare const GUN_RANGE = 80;
176
+ /**
177
+ * A shot is a plasma ball (the user, 2026-11-06, Doom-like): it leaves the eye along the look at
178
+ * PLASMA_SPEED m/s, is a sphere of PLASMA_R metres, and bursts on the first brush or enemy body it
179
+ * touches (teammates and the shooter let it through). It lives GUN_RANGE / PLASMA_SPEED s.
180
+ */
181
+ export declare const PLASMA_SPEED = 40;
182
+ export declare const PLASMA_R = 0.12;
183
+ /** Plasma balls in flight in a room at most: past it the oldest bursts. They go on the wire. */
184
+ export declare const PLASMA_MAX = 64;
176
185
  /** Radians the view kicks up per shot (client side: the kick is in the pitch the inputs carry). */
177
186
  export declare const RECOIL = 0.012;
178
187
  /** Ticks a player lies down after the health ran out, then he is back at a spawn of his team. */
@@ -3,7 +3,7 @@ import type { World } from './world';
3
3
  type Vec3 = [number, number, number];
4
4
  /** Whether the feet of `p` are within `r` of the point `at` on the floor plane and within PICK_H of its height. */
5
5
  export declare const within: (p: PlayerState, at: Vec3, r: number) => boolean;
6
- /** What a step struck, for the host to resolve: nothing, a laser shot, or the katana's cut. */
6
+ /** What a step struck, for the host to resolve: nothing, a shot (a plasma ball), or the katana's cut. */
7
7
  export declare const STRIKE: {
8
8
  readonly NONE: 0;
9
9
  readonly SHOT: 1;
@@ -26,10 +26,4 @@ export type Strike = (typeof STRIKE)[keyof typeof STRIKE];
26
26
  * `armed` is false while the match is over: no weapon, no rack.
27
27
  */
28
28
  export declare const step: (p: PlayerState, i: Input, w: World, team: number, armed?: boolean) => Strike;
29
- /**
30
- * The first of `foes` (the players he may hit, as he saw them) that the laser of `p` meets: from his
31
- * eye along his look, at most GUN_RANGE and not through a brush. `p` is the state after the input
32
- * that fired.
33
- */
34
- export declare const shoot: (w: World, p: PlayerState, foes: PlayerState[]) => PlayerState | undefined;
35
29
  export {};
@@ -0,0 +1,29 @@
1
+ import type { Ball, PlayerState } from './types';
2
+ import type { World } from './world';
3
+ type Vec3 = [number, number, number];
4
+ /** Metres a ball flies in a tick. */
5
+ export declare const PLASMA_STEP: number;
6
+ /** Ticks of the shooter's lag a new ball is flown at most on the host before its first tick. */
7
+ export declare const PLASMA_LAG = 12;
8
+ /** A ball the host flies: whose team fired it, and the metres it has left. */
9
+ export interface Flying extends Ball {
10
+ team: number;
11
+ left: number;
12
+ }
13
+ /**
14
+ * The ball of the shot `p` has just fired (`p` is the state after the step that fired): from the
15
+ * eye of the mode along the look, GUN_RANGE metres to go, named by his `shots` count.
16
+ */
17
+ export declare const launch: (p: PlayerState, team?: number) => Flying;
18
+ /**
19
+ * Distance at which the ray from `o` along the unit `d` enters the upright cylinder of radius `r`
20
+ * on `c`'s feet, `h` tall; Infinity on a miss.
21
+ */
22
+ export declare const cylinder: (o: Vec3, d: Vec3, c: PlayerState, r: number, h: number) => number;
23
+ /**
24
+ * Flies `b` on by `m` metres (at most what it has left) as a sphere of PLASMA_R: it stops and
25
+ * bursts on the first brush, or on the first of `foes` whose body (a cylinder PLASMA_R wider) it
26
+ * enters. Returns the foe it burst on.
27
+ */
28
+ export declare const fly: (w: World, b: Flying, m: number, foes: PlayerState[]) => PlayerState | undefined;
29
+ export {};
@@ -31,6 +31,8 @@ export declare const SNAP_HEAD = 4;
31
31
  export declare const SNAP_PLAYER = 47;
32
32
  /** The match block after the players: the captures, the clock, the packs; the flags follow (2 to 16 bytes). */
33
33
  export declare const SNAP_MATCH = 8;
34
+ /** Bytes of a plasma ball. */
35
+ export declare const SNAP_BALL = 10;
34
36
  /**
35
37
  * The input as the host will read it after encodeInput and decodeInput: yaw, pitch and view
36
38
  * rounded to the wire (an absent view stays absent here, and reads 0 on the host). The client
@@ -31,6 +31,8 @@ export declare class Room {
31
31
  private rr;
32
32
  /** Ticks before each health pack of the map is back: 0 when it is there to take. */
33
33
  private gone;
34
+ /** The plasma balls in flight, and the ones that burst since the last snapshot, which sends them once more. */
35
+ private balls;
34
36
  /** Missing rules fall back to RULES. */
35
37
  constructor(rules?: Partial<Rules>, map?: WorldDef);
36
38
  /** Number of joined players. */
@@ -83,10 +85,13 @@ export declare class Room {
83
85
  */
84
86
  private harm;
85
87
  /**
86
- * A shot of `p` went off at the view tick `view`: it hits the first enemy on its way as `p` drew
87
- * him, and takes 1 hp.
88
+ * A shot of `p` went off at the view tick `view`: its ball starts where `p` saw it start, flown
89
+ * on by his lag (the view tick to now, at most PLASMA_LAG ticks) against the others as they are
90
+ * now. Past PLASMA_MAX balls in flight, the oldest bursts.
88
91
  */
89
92
  private shoot;
93
+ /** Flies the ball `b` on by `m` metres: one that bursts on an enemy who is up takes 1 hp from him, and counts a hit to its shooter. */
94
+ private fly;
90
95
  /**
91
96
  * A cut of `p` struck at the view tick `view`: every enemy it reaches as `p` drew him is hit
92
97
  * (`strike`), and the `hits` count goes up once. Each takes the cut's hp; one it does not put
@@ -172,7 +172,7 @@ export interface PlayerState {
172
172
  rack?: boolean;
173
173
  /** Ticks left lying down after the health ran out; at 0 the player is back at a spawn. 0 when up. */
174
174
  down: number;
175
- /** Shots fired and hits landed (a laser or a cut), u8 counters that wrap: the clients draw a beam and play the hit sound on each change. */
175
+ /** Shots fired and hits landed (a plasma ball or a cut), u8 counters that wrap: the clients flash the muzzle and play the hit sound on each change. */
176
176
  shots: number;
177
177
  hits: number;
178
178
  /** Has the katana (taken at the team's katana rack, lost on going down). Absent reads false. */
@@ -221,6 +221,22 @@ export interface SnapPlayer extends PlayerState {
221
221
  /** While `stun` runs: the id of the player who tackled this one (4 bits), else 0. Not part of the movement. */
222
222
  by: number;
223
223
  }
224
+ /** A plasma ball as a snapshot carries it (plasma.ts). */
225
+ export interface Ball {
226
+ /** The shooter's `shots` count after the shot that fired it, u8: with `by`, it names the ball. */
227
+ id: number;
228
+ /** The shooter's player id. */
229
+ by: number;
230
+ /** Its centre, metres (the wire keeps 1/32 m), and its unit direction of flight. */
231
+ x: number;
232
+ y: number;
233
+ z: number;
234
+ dx: number;
235
+ dy: number;
236
+ dz: number;
237
+ /** It burst where it is: the last snapshot that carries it. */
238
+ burst: boolean;
239
+ }
224
240
  /** The flag of a team as a snapshot carries it: only the fields of its state are meaningful, the rest read 0. */
225
241
  export interface FlagState {
226
242
  /** FLAG. */
@@ -250,6 +266,8 @@ export interface Snapshot {
250
266
  * packs of WorldDef.ammo (bit packs.length + n). Absent: none.
251
267
  */
252
268
  packs?: number;
269
+ /** The plasma balls in flight, and those that burst since the last snapshot. Absent: none. */
270
+ balls?: Ball[];
253
271
  }
254
272
  /** Room rules, set by the host. Defaults in constants.ts (RULES). */
255
273
  export interface Rules {
@@ -65,12 +65,14 @@ export declare const near: (w: World, x: number, z: number, r: number) => number
65
65
  /**
66
66
  * Distance along the ray from o in the unit direction d to the first brush face, at most max. A ray
67
67
  * that starts inside a brush hits at 0; one that starts on a face and moves away from it does not hit it.
68
+ * With `grow`, every brush is that much bigger on each side: the path of a sphere of that radius
69
+ * (its corners square, and a brush is only found in the cells the ray crosses).
68
70
  *
69
71
  * Walks the grid cells the ray crosses (Amanatides and Woo), testing the brushes of each against
70
72
  * the exact slab test, and stops once the next cell starts beyond the best hit or max. A brush
71
73
  * spanning several cells is tested in each: the hit is the same, and lists are short.
72
74
  */
73
- export declare const ray: (w: World, o: Vec3, d: Vec3, max: number) => number;
75
+ export declare const ray: (w: World, o: Vec3, d: Vec3, max: number, grow?: number) => number;
74
76
  /** Whether a brush hides b from a. */
75
77
  export declare const hidden: (w: World, a: Vec3, b: Vec3) => boolean;
76
78
  export {};
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.33.0",
5
+ "version": "0.34.1",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"