@korial29/tiny-fps 0.142.0 → 0.144.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/server.js CHANGED
@@ -48,8 +48,45 @@ var PUNCH = {
48
48
  reach: 1.4,
49
49
  arc: .6,
50
50
  hp: 0,
51
- hold: -1
51
+ hold: -1,
52
+ knock: 0
52
53
  };
54
+ /**
55
+ * The blows of the fists (the user, 2026-11-13), the `cut` of a swing with no weapon: the JAB is the
56
+ * punch above, the left fist. A fresh FIRE press after a blow's strike, while its swing runs, throws
57
+ * the next of the chain at once: the CROSS (the right fist), then the HOOK (the left, swung round),
58
+ * which ends the chain. A blow started at a sprint on the ground, in a slide or in a dash's burst is
59
+ * the LUNGE, a long straight right. `hp` 0 is half a point (PUNCH_HITS), 1 a whole one; a blow with
60
+ * a `knock` throws whoever it hits as a tackle does, `knock` times as hard, and drops his flag.
61
+ */
62
+ var BLOW = {
63
+ JAB: 0,
64
+ CROSS: 1,
65
+ HOOK: 2,
66
+ LUNGE: 3
67
+ };
68
+ var PUNCHES = [
69
+ PUNCH,
70
+ PUNCH,
71
+ {
72
+ ticks: 28,
73
+ strike: 9,
74
+ reach: 1.5,
75
+ arc: .9,
76
+ hp: 1,
77
+ hold: -1,
78
+ knock: 1.4
79
+ },
80
+ {
81
+ ticks: 26,
82
+ strike: 7,
83
+ reach: 2.2,
84
+ arc: .5,
85
+ hp: 1,
86
+ hold: -1,
87
+ knock: 1.2
88
+ }
89
+ ];
53
90
  var [PUNCH_HITS, PUNCH_STUN, PUNCH_MEMORY] = [
54
91
  2,
55
92
  3,
@@ -5950,6 +5987,14 @@ var swing = (w, feet, rovers = []) => w.doors?.forEach((s, i) => {
5950
5987
  var shut = (w) => w.doors?.forEach((s) => {
5951
5988
  s.open = s.wait = 0;
5952
5989
  });
5990
+ // src/shared/tackle.ts
5991
+ /** Whether the player's body is a weapon: in a slide, or in the burst of a dash. */
5992
+ var tackling = (p) => p.mode === MODE.SLIDE || p.dash > 50;
5993
+ /**
5994
+ * Whether the cylinders of `a` and `b` overlap, with TACKLE_REACH of reach on top: closer than
5995
+ * two radii and the reach on the floor plane, and their heights (low in a slide) overlap.
5996
+ */
5997
+ var reaches = (a, b) => Math.hypot(a.x - b.x, a.z - b.z) < 1.1 && a.y < b.y + heightOf(b) && b.y < a.y + heightOf(a);
5953
5998
  // src/shared/gun.ts
5954
5999
  /** Whether the feet of `p` are within `r` of the point `at` on the floor plane and within PICK_H of its height. */
5955
6000
  var within = (p, at, r) => {
@@ -6030,6 +6075,8 @@ var step = (p, i, w, team, armed = true, bodies = [], kit = KITS[0]) => {
6030
6075
  return STRIKE.NONE;
6031
6076
  }
6032
6077
  if (locked) return duel(p, i);
6078
+ const fresh = !!(i.keys & KEY.FIRE) && !p.pressed;
6079
+ p.pressed = !!(i.keys & KEY.FIRE);
6033
6080
  const { rack, blade, rail, rifle } = w.def.teams[team];
6034
6081
  const inside = !!rack && within(p, rack, 1.2);
6035
6082
  if (armed && inside && !p.rack) [p.ammo, p.mag] = [kit.ammo, kit.mag];
@@ -6066,7 +6113,8 @@ var step = (p, i, w, team, armed = true, bodies = [], kit = KITS[0]) => {
6066
6113
  p.charge = top ? 0 : p.charge;
6067
6114
  const s = p.swing ?? 0;
6068
6115
  const c = swingOf(p);
6069
- const stop = (v) => v == s - 1 && (v == c.ticks - c.strike || v == PUNCH.ticks - PUNCH.strike || !p.heavy && v == ticks - hold);
6116
+ const blow = PUNCHES[p.cut ?? 0] ?? PUNCHES[0];
6117
+ const stop = (v) => v == s - 1 && (v == c.ticks - c.strike || v == blow.ticks - blow.strike || !p.heavy && v == ticks - hold);
6070
6118
  p.swing = Math.max(0, kit.haste > 1 && stop(s - 1) ? s - 1 : s - kit.haste);
6071
6119
  p.heavy = !!p.swing && !!p.heavy;
6072
6120
  }
@@ -6111,7 +6159,7 @@ var step = (p, i, w, team, armed = true, bodies = [], kit = KITS[0]) => {
6111
6159
  if (!--p.reload) p[key] = full;
6112
6160
  } else if (hand != 1 && carried >= 0 && !busy && load < full && (!load || i.keys & KEY.RELOAD)) [p.reload, p.charge] = [ticks2, 0];
6113
6161
  const bare = hand < 0;
6114
- const c = bare ? PUNCH : swingOf(p);
6162
+ const c = bare ? PUNCHES[p.cut ?? 0] ?? PUNCHES[0] : swingOf(p);
6115
6163
  if (p.swing && c.ticks - p.swing === c.strike) return STRIKE.CUT;
6116
6164
  if (p.wield && !top || p.railed || p.rifled || busy || p.reload || !p.wield && !p.mag) p.charge = 0;
6117
6165
  if (p.rifled && i.keys & KEY.SPECIAL && !busy && p.nades && !p.lob) {
@@ -6124,11 +6172,13 @@ var step = (p, i, w, team, armed = true, bodies = [], kit = KITS[0]) => {
6124
6172
  const late = CUTS[p.cut ?? 0].ticks - (p.swing ?? 0);
6125
6173
  const special = !!(i.keys & KEY.SPECIAL) && (!p.swing || !p.heavy && (p.cut ?? 0) < 4 && late <= 18);
6126
6174
  if (bare) {
6127
- if (!p.swing) [p.cut, p.heavy, p.swing] = [
6128
- 0,
6129
- false,
6130
- PUNCH.ticks
6131
- ];
6175
+ if (!p.swing) {
6176
+ p.cut = tackling(p) || p.mode === MODE.GROUND && !!(i.keys & KEY.SPRINT) && p.vx * p.vx + p.vz * p.vz > kit.run * kit.run ? BLOW.LUNGE : BLOW.JAB;
6177
+ [p.heavy, p.swing] = [false, PUNCHES[p.cut].ticks];
6178
+ } else if (fresh && p.cut < BLOW.HOOK && c.ticks - p.swing > c.strike) {
6179
+ p.cut++;
6180
+ p.swing = PUNCHES[p.cut].ticks;
6181
+ }
6132
6182
  } else if (p.wield && (!p.swing || special)) {
6133
6183
  p.cut = cutOf(i.keys) + (special ? 4 : 0);
6134
6184
  [p.swing, p.charge] = [CUTS[p.cut].ticks, 0];
@@ -7583,14 +7633,6 @@ var missile = (r, by, team, yaw, pitch, id, k, sight) => {
7583
7633
  v: Math.min(63, SHIP.MISSILE_SPEED + Math.max(0, own))
7584
7634
  };
7585
7635
  };
7586
- // src/shared/tackle.ts
7587
- /** Whether the player's body is a weapon: in a slide, or in the burst of a dash. */
7588
- var tackling = (p) => p.mode === MODE.SLIDE || p.dash > 50;
7589
- /**
7590
- * Whether the cylinders of `a` and `b` overlap, with TACKLE_REACH of reach on top: closer than
7591
- * two radii and the reach on the floor plane, and their heights (low in a slide) overlap.
7592
- */
7593
- var reaches = (a, b) => Math.hypot(a.x - b.x, a.z - b.z) < 1.1 && a.y < b.y + heightOf(b) && b.y < a.y + heightOf(a);
7594
7636
  // src/shared/room.ts
7595
7637
  /** Ticks run at most this many times per timer callback, so a stalled host does not spiral. */
7596
7638
  var MAX_CATCH_UP = 20;
@@ -8278,27 +8320,30 @@ var Room = class {
8278
8320
  }
8279
8321
  }
8280
8322
  /**
8281
- * A punch of `p` struck at the view tick `view`: every enemy it reaches as `p` drew him (the
8282
- * strike test, with PUNCH's reach and arc) takes half a point, 1 hp every PUNCH_HITS punches; the
8283
- * `hits` count goes up once. The PUNCH_STUN-th he takes with no more than PUNCH_MEMORY ticks
8284
- * between two stuns him as a tackle does: a stumble thrown the way `p` faces, the flag dropped,
8285
- * `by` the puncher.
8323
+ * A punch of `p` struck at the view tick `view`: every enemy its blow (PUNCHES by `cut`) reaches
8324
+ * as `p` drew him (the strike test, with the blow's reach and arc) is hit; the `hits` count goes
8325
+ * up once. A jab or a cross takes half a point, 1 hp every PUNCH_HITS of them; a hook or a lunge a
8326
+ * whole one. The PUNCH_STUN-th blow he takes with no more than PUNCH_MEMORY ticks between two, or
8327
+ * a blow with a `knock`, stuns him as a tackle does: a stumble thrown the way `p` faces (`knock`
8328
+ * times as hard), the flag dropped, `by` the puncher.
8286
8329
  */
8287
8330
  punch(p, view) {
8288
- const seen = strike(this.world, p.state, this.enemies(p, view), PUNCH);
8331
+ const blow = PUNCHES[p.state.cut ?? 0] ?? PUNCHES[0];
8332
+ const seen = strike(this.world, p.state, this.enemies(p, view), blow);
8289
8333
  const foes = this.players().filter((q) => seen.some((s) => s.id === q.info.id));
8290
8334
  if (!foes.length) return;
8291
8335
  p.state.hits = p.state.hits + 1 & 255;
8292
8336
  for (const foe of foes) {
8293
8337
  foe.blows = (this.ticks - (foe.punched ?? -Infinity) <= PUNCH_MEMORY ? foe.blows ?? 0 : 0) + 1;
8294
8338
  foe.punched = this.ticks;
8295
- foe.bruise = ((foe.bruise ?? 0) + 1) % PUNCH_HITS;
8296
- if (!foe.bruise && this.harm(foe, 1, p, FRAG.FIST, felled(FALL$1.STRUCK, ...forward(p.state.yaw)))) continue;
8297
- if (foe.blows >= PUNCH_STUN) {
8339
+ if (!blow.hp) foe.bruise = ((foe.bruise ?? 0) + 1) % PUNCH_HITS;
8340
+ const fell = felled(FALL$1.STRUCK, ...forward(p.state.yaw));
8341
+ if ((blow.hp || !foe.bruise) && this.harm(foe, 1, p, FRAG.FIST, fell)) continue;
8342
+ if (blow.knock || foe.blows >= PUNCH_STUN) {
8298
8343
  foe.blows = 0;
8299
8344
  this.drop(foe.info.id);
8300
8345
  const [dx, dz] = forward(p.state.yaw);
8301
- stumble(foe.state, dx, dz);
8346
+ stumble(foe.state, dx, dz, 48, 6 * (blow.knock || 1));
8302
8347
  foe.state.zap = false;
8303
8348
  foe.by = p.info.id;
8304
8349
  }
@@ -37,7 +37,7 @@ export interface Audio {
37
37
  * then MP3 where the browser cannot decode the first (older Safari).
38
38
  */
39
39
  export declare const SPRITES: (() => Promise<string>)[];
40
- export declare const createAudio: (layers?: Voice[][], sprites?: (() => Promise<string>)[]) => Audio;
40
+ export declare const createAudio: (layers?: Voice[][], sprites?: (() => Promise<string>)[], song?: () => Float32Array) => Audio;
41
41
  /** The mute choice of the last visit. Storage throws when blocked: no memory then. */
42
42
  export declare const savedMute: () => boolean;
43
43
  /** Flips mute, remembers it, and returns the new state. */
@@ -36,7 +36,7 @@ export interface Combat {
36
36
  /** Shots between two states of a player, a u8 counter that wraps. */
37
37
  export declare const fired: (a?: PlayerState, b?: PlayerState) => number;
38
38
  /** What the katana's sounds read of a player: the swing, the cut and whether it is in hand. */
39
- type Blade = Pick<PlayerState, 'swing' | 'cut' | 'wield' | 'blade' | 'heavy' | 'down' | 'railed' | 'ammo' | 'reload' | 'rifled' | 'hot'>;
39
+ type Blade = Pick<PlayerState, 'swing' | 'cut' | 'wield' | 'blade' | 'heavy' | 'down' | 'railed' | 'ammo' | 'reload' | 'rifled' | 'hot' | 'hits'>;
40
40
  /**
41
41
  * The CUT of a swing that started between two states of a player, or -1: `swing` jumped up (it
42
42
  * only counts down), or the cut changed under a running one.
@@ -46,7 +46,7 @@ export declare const swung: (a?: Blade, b?: Blade) => number;
46
46
  export declare const struck: (a?: Blade, b?: Blade) => boolean;
47
47
  /** The pitch of a player's voice: the woman's higher, and each a little off the next by his id. */
48
48
  export declare const voiceOf: (id: number, body?: number) => number;
49
- export declare const createCombat: (world: World, audio: Pick<Audio, "play"> & Partial<Pick<Audio, "loop">>, hud: Pick<Hud, "vitals" | "hit" | "down">, fx: Pick<Effects, "fire" | "cut" | "wound" | "lie" | "quake">, tracer: Pick<Tracer, "flash" | "burst" | "blast" | "orbs" | "update" | "mount" | "crackle" | "charging" | "lightning">, ctl: {
49
+ export declare const createCombat: (world: World, audio: Pick<Audio, "play"> & Partial<Pick<Audio, "loop">>, hud: Pick<Hud, "vitals" | "hit" | "down">, fx: Pick<Effects, "fire" | "cut" | "wound" | "lie" | "quake" | "blow" | "punch">, tracer: Pick<Tracer, "flash" | "burst" | "blast" | "orbs" | "update" | "mount" | "crackle" | "charging" | "lightning">, ctl: {
50
50
  pitch: number;
51
51
  }, balls: Pick<Balls, "fire" | "frame">,
52
52
  /** The muzzle of a runner's long gun as last drawn, from his feet (Renderer.muzzle()). */
@@ -35,6 +35,12 @@ export interface Effects {
35
35
  punch(): void;
36
36
  /** The own katana's cut struck: a thrust punches the field of view, a slash dips the look, a cut across rolls toward the side it ends on. */
37
37
  cut(c: number): void;
38
+ /**
39
+ * A blow of the fists (BLOW) struck: the own (the look kicked toward the fist's side, rolled hard
40
+ * by a hook, a lunge punching the field of view), or, `taken`, one the own player took: the eye
41
+ * dipped and the look knocked up.
42
+ */
43
+ blow(b: number, taken?: boolean): void;
38
44
  /**
39
45
  * Advances dt seconds: the own player (eased, undefined before the first snapshot), the held keys,
40
46
  * the events, and the stride phase of its drawn legs (Gait.phase): with it the bob dips as a foot
@@ -93,9 +93,28 @@ export declare const JAB: {
93
93
  back: number[];
94
94
  twist: number;
95
95
  };
96
+ /**
97
+ * The other blows (BLOW, the user 2026-11-13), as JAB's arms: the HOOK's left arm swung round at
98
+ * the shoulder's height, the elbow bent square and out, the chest turned behind it; the LUNGE's right
99
+ * arm driven straight out, further than a jab, the chest turned the other way.
100
+ */
101
+ export declare const HOOK: {
102
+ out: number[];
103
+ twist: number;
104
+ };
105
+ export declare const LUNGE: {
106
+ out: number[];
107
+ twist: number;
108
+ };
109
+ /** The striking arm of each blow (BLOW): -1 the left, 1 the right. */
110
+ export declare const SIDE: number[];
111
+ /** Whether the player has no weapon at all: FIRE punches. */
112
+ export declare const bare: (p: PlayerState) => boolean;
113
+ /** The blow (BLOW) of a bare-handed swing. */
114
+ export declare const blowOf: (p: Pick<PlayerState, "cut">) => number;
96
115
  /**
97
116
  * How far out the fist of a punch is, 0 to 1, by the swing of a player with no weapon at all: out
98
- * at the strike, back by the swing's end.
117
+ * at the strike of its blow, back by the swing's end.
99
118
  */
100
119
  export declare const thrown: (p: PlayerState) => number;
101
120
  /** `bow` is the guard's lean forward: none for the eye's own body, whose arms hold to the view and which stands in no sword guard. */
@@ -137,3 +137,12 @@ export declare const MUSIC_RATE: number;
137
137
  * under the sounds.
138
138
  */
139
139
  export declare const music: () => Float32Array;
140
+ /**
141
+ * The moon's music, 8-bit: thirty-two bars in D minor at 126 bpm, a pulse lead, a fast arpeggio
142
+ * in a thin pulse, an octave bass on the triangle and noise drums. The second sixteen bars play
143
+ * the lead thinner with an echo and the arpeggio an octave up. Like music(): mono at MUSIC_RATE,
144
+ * deterministic, its end joining its start.
145
+ */
146
+ export declare const moon: () => Float32Array;
147
+ /** The music of each map by its key; the others play music(). */
148
+ export declare const SONGS: Record<string, () => Float32Array>;
@@ -28,10 +28,13 @@ export interface Runner {
28
28
  /** Seconds left of the grimace a hit puts on his face, and of the grin of a capture or of a foe put down. */
29
29
  hurt: number;
30
30
  grin: number;
31
- /** How far out the fist of a punch is, 0 to 1, eased. */
31
+ /** How far out the fist of a punch is, 0 to 1, eased, and its blow (BLOW). */
32
32
  jab: number;
33
33
  /** How closed his hands are, left then right, eased toward grasp(). */
34
34
  curls: number[];
35
+ blow: number;
36
+ /** How far his head is still thrown back by a blow he took, 1 to 0. */
37
+ flinch: number;
35
38
  /** His face (expression.ts), and the seconds it has yet to live through: soldier() moves it once drawn, where the head's turn is known. */
36
39
  face: Face;
37
40
  dt: number;
@@ -190,7 +190,31 @@ export declare const PUNCH: {
190
190
  arc: number;
191
191
  hp: number;
192
192
  hold: number;
193
+ knock: number;
193
194
  };
195
+ /**
196
+ * The blows of the fists (the user, 2026-11-13), the `cut` of a swing with no weapon: the JAB is the
197
+ * punch above, the left fist. A fresh FIRE press after a blow's strike, while its swing runs, throws
198
+ * the next of the chain at once: the CROSS (the right fist), then the HOOK (the left, swung round),
199
+ * which ends the chain. A blow started at a sprint on the ground, in a slide or in a dash's burst is
200
+ * the LUNGE, a long straight right. `hp` 0 is half a point (PUNCH_HITS), 1 a whole one; a blow with
201
+ * a `knock` throws whoever it hits as a tackle does, `knock` times as hard, and drops his flag.
202
+ */
203
+ export declare const BLOW: {
204
+ readonly JAB: 0;
205
+ readonly CROSS: 1;
206
+ readonly HOOK: 2;
207
+ readonly LUNGE: 3;
208
+ };
209
+ export declare const PUNCHES: {
210
+ ticks: number;
211
+ strike: number;
212
+ reach: number;
213
+ arc: number;
214
+ hp: number;
215
+ hold: number;
216
+ knock: number;
217
+ }[];
194
218
  export declare const PUNCH_HITS: number, PUNCH_STUN: number, PUNCH_MEMORY: number;
195
219
  /** Shots the rack loads. */
196
220
  export declare const AMMO_MAX = 60;
@@ -139,11 +139,12 @@ export declare class Room {
139
139
  */
140
140
  private cut;
141
141
  /**
142
- * A punch of `p` struck at the view tick `view`: every enemy it reaches as `p` drew him (the
143
- * strike test, with PUNCH's reach and arc) takes half a point, 1 hp every PUNCH_HITS punches; the
144
- * `hits` count goes up once. The PUNCH_STUN-th he takes with no more than PUNCH_MEMORY ticks
145
- * between two stuns him as a tackle does: a stumble thrown the way `p` faces, the flag dropped,
146
- * `by` the puncher.
142
+ * A punch of `p` struck at the view tick `view`: every enemy its blow (PUNCHES by `cut`) reaches
143
+ * as `p` drew him (the strike test, with the blow's reach and arc) is hit; the `hits` count goes
144
+ * up once. A jab or a cross takes half a point, 1 hp every PUNCH_HITS of them; a hook or a lunge a
145
+ * whole one. The PUNCH_STUN-th blow he takes with no more than PUNCH_MEMORY ticks between two, or
146
+ * a blow with a `knock`, stuns him as a tackle does: a stumble thrown the way `p` faces (`knock`
147
+ * times as hard), the flag dropped, `by` the puncher.
147
148
  */
148
149
  private punch;
149
150
  /**
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.142.0",
5
+ "version": "0.144.0",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"