@korial29/tiny-fps 0.30.0 → 0.31.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 +1 -1
- package/dist/index.js +14 -14
- package/dist/local.js +1 -1
- package/dist/server.js +578 -381
- package/dist/types/client/beams.d.ts +4 -0
- package/dist/types/client/beats.d.ts +12 -3
- package/dist/types/client/combat.d.ts +12 -2
- package/dist/types/client/effects.d.ts +2 -0
- package/dist/types/client/flag.d.ts +2 -0
- package/dist/types/client/hud.d.ts +6 -2
- package/dist/types/client/input.d.ts +20 -4
- package/dist/types/client/katana.d.ts +52 -0
- package/dist/types/client/props.d.ts +4 -2
- package/dist/types/client/sfx.d.ts +4 -0
- package/dist/types/client/soldier.d.ts +5 -0
- package/dist/types/client/trail.d.ts +14 -0
- package/dist/types/shared/blade.d.ts +20 -0
- package/dist/types/shared/constants.d.ts +19 -0
- package/dist/types/shared/gun.d.ts +19 -6
- package/dist/types/shared/physics.d.ts +10 -4
- package/dist/types/shared/protocol.d.ts +1 -1
- package/dist/types/shared/room.d.ts +18 -2
- package/dist/types/shared/types.d.ts +28 -2
- package/dist/types/shared/world.d.ts +2 -0
- package/package.json +1 -1
|
@@ -5,6 +5,10 @@ export declare const LIFE = 0.08;
|
|
|
5
5
|
export interface Tracer {
|
|
6
6
|
/** A shot from `a` to `b`; `hit` when it ended on a wall, which sparks; `own` for the player's, which stays on its muzzle. */
|
|
7
7
|
shoot(a: Vec3, b: Vec3, hit: boolean, own?: boolean): void;
|
|
8
|
+
/** The katana's shock at `at`: a burst of sparks and bolts. */
|
|
9
|
+
shock(at: Vec3): void;
|
|
10
|
+
/** One frame of the crackle around a shocked runner whose middle is `at`: a few bolts, flickering. */
|
|
11
|
+
crackle(at: Vec3): void;
|
|
8
12
|
/** Where the own muzzle is now: the own beams start there, so that a kick of the view does not swing them. */
|
|
9
13
|
mount(a: Vec3): void;
|
|
10
14
|
/** Ages everything by dt seconds and drops what is over. */
|
|
@@ -23,6 +23,13 @@ export type Beat = {
|
|
|
23
23
|
who: number;
|
|
24
24
|
by: number;
|
|
25
25
|
at: Vec3;
|
|
26
|
+
}
|
|
27
|
+
/** Player `who` was shocked by the katana of player `by`: a stumble with `zap` set. */
|
|
28
|
+
| {
|
|
29
|
+
kind: 'shock';
|
|
30
|
+
who: number;
|
|
31
|
+
by: number;
|
|
32
|
+
at: Vec3;
|
|
26
33
|
};
|
|
27
34
|
/**
|
|
28
35
|
* The beats from snapshot `a` to `b`. Nothing at the first snapshot, nothing while a match is
|
|
@@ -30,12 +37,13 @@ export type Beat = {
|
|
|
30
37
|
* its flags and score reset from. A capture is one beat: the carried flag going home with it is
|
|
31
38
|
* not a return. A carried flag that is home in the next snapshot without a capture was dropped and
|
|
32
39
|
* sent home by its tackler within the same two ticks: one return. A tackle is a player whose
|
|
33
|
-
* stumble timer is higher than it was (a new stumble), one beat each, after the flag beats
|
|
40
|
+
* stumble timer is higher than it was (a new stumble), one beat each, after the flag beats; a
|
|
41
|
+
* stumble with `zap` is a shock of the katana, not a tackle.
|
|
34
42
|
*/
|
|
35
43
|
export declare const beats: (a: Snapshot | undefined, b: Snapshot) => Beat[];
|
|
36
44
|
/**
|
|
37
45
|
* A line for the banner, and the team whose colour it is in, or none: a tackle is told to the
|
|
38
|
-
* tackler only. `me` is the own player.
|
|
46
|
+
* tackler only, a shock to nobody. `me` is the own player.
|
|
39
47
|
*/
|
|
40
48
|
export declare const say: (beat: Beat, me: {
|
|
41
49
|
id: number;
|
|
@@ -55,7 +63,8 @@ export interface Cue {
|
|
|
55
63
|
* The sounds of a beat: a lower pitch for bad news for the own team (its flag taken, the enemy
|
|
56
64
|
* flag dropped or returned, a point for the other side), the plain one for good news. A tackle
|
|
57
65
|
* is an impact at the spot for the others, a close one for the tackler, and for the one tackled
|
|
58
|
-
* an impact and a grunt, centred.
|
|
66
|
+
* an impact and a grunt, centred. A shock is a zap, centred for the one shocked and at the spot
|
|
67
|
+
* for the others; the attacker hears his own with the hit (combat.ts). None for a new match.
|
|
59
68
|
*/
|
|
60
69
|
export declare const cues: (beat: Beat, me: {
|
|
61
70
|
id: number;
|
|
@@ -30,13 +30,23 @@ export declare const sight: (world: World, eye: Vec3, cam: Vec3, yaw: number, pi
|
|
|
30
30
|
local: Vec3;
|
|
31
31
|
};
|
|
32
32
|
export interface Combat {
|
|
33
|
-
/** One live step of the own player, its state before and after: the recoil and the kick of each shot it fired. */
|
|
33
|
+
/** One live step of the own player, its state before and after: the recoil and the kick of each shot it fired, the swish and the punch of a cut. */
|
|
34
34
|
step(a?: PlayerState, b?: PlayerState): void;
|
|
35
35
|
/** One frame: the beams and the sounds of what changed since the last one, and the HUD. */
|
|
36
36
|
frame(v: View | undefined, me: PlayerState | undefined, others: PlayerState[], keys: number, dt: number): void;
|
|
37
37
|
}
|
|
38
38
|
/** Shots between two states of a player, a u8 counter that wraps. */
|
|
39
39
|
export declare const fired: (a?: PlayerState, b?: PlayerState) => number;
|
|
40
|
-
|
|
40
|
+
/** What the katana's sounds read of a player: the swing, the cut and whether it is in hand. */
|
|
41
|
+
type Blade = Pick<PlayerState, 'swing' | 'cut' | 'wield' | 'blade'>;
|
|
42
|
+
/**
|
|
43
|
+
* The CUT of a swing that started between two states of a player, or -1: `swing` jumped up (it
|
|
44
|
+
* only counts down), or the cut changed under a running one.
|
|
45
|
+
*/
|
|
46
|
+
export declare const swung: (a?: Blade, b?: Blade) => number;
|
|
47
|
+
/** Whether the step from a to b is the strike of its cut: `swing` went down through the strike tick (CUTS). */
|
|
48
|
+
export declare const struck: (a?: Blade, b?: Blade) => boolean;
|
|
49
|
+
export declare const createCombat: (world: World, audio: Pick<Audio, "play">, hud: Pick<Hud, "vitals" | "hit" | "down">, fx: Pick<Effects, "fire" | "cut" | "wound" | "lie">, tracer: Pick<Tracer, "shoot" | "update" | "mount" | "crackle">, ctl: {
|
|
41
50
|
pitch: number;
|
|
42
51
|
}) => Combat;
|
|
52
|
+
export {};
|
|
@@ -31,6 +31,8 @@ export interface Effects {
|
|
|
31
31
|
jolt(): void;
|
|
32
32
|
/** The own player tackled someone: a small punch of the look and the field of view. */
|
|
33
33
|
punch(): void;
|
|
34
|
+
/** 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. */
|
|
35
|
+
cut(c: number): void;
|
|
34
36
|
/** Advances dt seconds: the own player (eased, undefined before the first snapshot), the held keys, the events. */
|
|
35
37
|
update(me: PlayerState | undefined, keys: number, dt: number, hit?: Hit): void;
|
|
36
38
|
}
|
|
@@ -27,6 +27,8 @@ export interface CtfScene {
|
|
|
27
27
|
flags: readonly FlagDraw[];
|
|
28
28
|
/** Each team's gun rack, where it has one, and the health packs that are there to take. */
|
|
29
29
|
racks?: readonly (Vec3 | undefined)[];
|
|
30
|
+
/** Each team's katana rack, where it has one. */
|
|
31
|
+
blades?: readonly (Vec3 | undefined)[];
|
|
30
32
|
packs?: readonly Vec3[];
|
|
31
33
|
/** The ammo packs that are there to take. */
|
|
32
34
|
ammo?: readonly Vec3[];
|
|
@@ -21,8 +21,12 @@ export interface Hud {
|
|
|
21
21
|
marks(list: Mark[]): void;
|
|
22
22
|
/** The red vignette of a tackle, 0 (none) to 1 (full). */
|
|
23
23
|
hurt(level: number): void;
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The health as pips out of HP_MAX, and the weapon in hand: the ammo counter with the gun glyph,
|
|
26
|
+
* or the katana glyph when `wield` (or when it is all there is). -1 ammo is no gun, `blade` is a
|
|
27
|
+
* katana carried; both carried show the slots (1 gun, 2 katana) over the glyph, none hides it.
|
|
28
|
+
*/
|
|
29
|
+
vitals(hp: number, ammo: number, blade?: boolean, wield?: boolean): void;
|
|
26
30
|
/** A hit marker on the crosshair for a moment: a laser of the own player hit. */
|
|
27
31
|
hit(): void;
|
|
28
32
|
/** The state of being down: `level` 0 (up) to 1 hides or greys the screen, `left` seconds till the respawn. */
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
import type { PlayerState } from '../shared/types';
|
|
1
2
|
/** Two presses of the same direction key this close (ms) are a dash that way. */
|
|
2
3
|
export declare const DOUBLE_TAP_MS = 250;
|
|
3
4
|
/** The keys of the step of a dash toward `dir` (a direction bit): only that direction is held with it. */
|
|
4
5
|
export declare const dashKeys: (keys: number, dir: number) => number;
|
|
5
6
|
/** The KEY bit of a KeyboardEvent.code, 0 for a key the game ignores. */
|
|
6
7
|
export declare const keyBit: (code: string) => number;
|
|
8
|
+
/** The wheel swaps the weapon at most this often (ms): a trackpad's flick is a hundred events, one swap. */
|
|
9
|
+
export declare const WHEEL_MS = 250;
|
|
10
|
+
/** Whether the katana is the choice after a key: 1 the gun, 2 the katana, any other key keeps it. */
|
|
11
|
+
export declare const picked: (blade: boolean, code: string) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The choice after a step of the own player. Picking the katana up switches to it, once; losing
|
|
14
|
+
* both weapons (going down) goes back to the gun; anything else, the gun picked up included, keeps it.
|
|
15
|
+
*/
|
|
16
|
+
export declare const chosen: (blade: boolean, was?: PlayerState, now?: PlayerState) => boolean;
|
|
17
|
+
/** The keys of a step with KEY.BLADE set while the katana is the choice. */
|
|
18
|
+
export declare const withBlade: (keys: number, blade: boolean) => number;
|
|
7
19
|
/** Live look angles and held keys; the loop reads them once per step and per frame. */
|
|
8
20
|
export interface Controls {
|
|
9
21
|
/** Radians, [0, 2π). Mouse right turns right, which lowers yaw. */
|
|
@@ -12,12 +24,16 @@ export interface Controls {
|
|
|
12
24
|
pitch: number;
|
|
13
25
|
/** KEY bits held now. */
|
|
14
26
|
keys: number;
|
|
27
|
+
/** The katana is the chosen weapon (1, 2 and the wheel), the gun otherwise. */
|
|
28
|
+
blade: boolean;
|
|
15
29
|
/**
|
|
16
|
-
* The KEY bits of the next step, read once per step. Same as `keys`,
|
|
17
|
-
* after a double tap: it carries DASH and only the tapped
|
|
18
|
-
* whatever else is held, and nothing else is on the wire.
|
|
30
|
+
* The KEY bits of the next step, read once per step. Same as `keys`, plus BLADE while the katana
|
|
31
|
+
* is chosen, except for the step right after a double tap: it carries DASH and only the tapped
|
|
32
|
+
* direction, so the dash goes that way whatever else is held, and nothing else is on the wire.
|
|
19
33
|
*/
|
|
20
34
|
take(): number;
|
|
35
|
+
/** One live step of the own player, its state before and after: a katana picked up is chosen, losing both weapons chooses the gun. */
|
|
36
|
+
track(was?: PlayerState, now?: PlayerState): void;
|
|
21
37
|
/** The canvas holds the pointer lock. */
|
|
22
38
|
locked(): boolean;
|
|
23
39
|
/** Removes every listener. */
|
|
@@ -26,6 +42,6 @@ export interface Controls {
|
|
|
26
42
|
/**
|
|
27
43
|
* Click the canvas to lock the pointer; while locked the mouse looks, the keys move (WASD, Shift
|
|
28
44
|
* sprints, Space jumps, C crouches, a direction key pressed twice within DOUBLE_TAP_MS dashes that
|
|
29
|
-
* way, the left button fires) and M calls `onMute`.
|
|
45
|
+
* way, the left button fires or cuts, 1 and 2 or the wheel pick the gun or the katana) and M calls `onMute`.
|
|
30
46
|
*/
|
|
31
47
|
export declare const createInput: (canvas: HTMLCanvasElement, onMute?: () => void) => Controls;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { PlayerState } from '../shared/types';
|
|
2
|
+
import type { Vec3 } from './mesh';
|
|
3
|
+
import type { Quat } from './rig';
|
|
4
|
+
/** Where the blade starts and ends along the model's forward axis, metres from the right hand. */
|
|
5
|
+
export declare const BASE: number, TIP: number;
|
|
6
|
+
/**
|
|
7
|
+
* The katana at a level of detail (0 far, 1 near), built once, in the vertex format of mesh.ts: the
|
|
8
|
+
* blade (bevelled edge, a ridge, a spine, a point), a thin cyan glow along its edge, a collar, a
|
|
9
|
+
* rounded-square guard, a grip wrapped in a violet check and a pommel with a glowing bead.
|
|
10
|
+
*/
|
|
11
|
+
export declare const katana: (lod: number) => number[];
|
|
12
|
+
/** Appends arcs of lightning flickering along the blade at the clock `t` (s): a few zigzags of thin crossed ribbons, each new every 70 ms. */
|
|
13
|
+
export declare const arcs: (out: number[], at: Vec3, [r, u, f]: Vec3[], t: number, lod: number, k?: number) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Appends the katana with its right-hand grip at `at`, axes `[right, up, forward]`, `k` times its
|
|
16
|
+
* size; with the clock `t` (s) it crackles.
|
|
17
|
+
*/
|
|
18
|
+
export declare const sword: (out: number[], at: Vec3, ax: Vec3[], lod: number, t?: number, k?: number) => void;
|
|
19
|
+
/** The sword's axes [right, up, forward] for a hand turned by `q` (see body.ts): the back of the hand to its right, the blade off the thumb toward the fingers. */
|
|
20
|
+
export declare const axes: (q: Quat) => Vec3[];
|
|
21
|
+
/** Where the fingers point for a sword with axes `ax`: the inverse of axes(). */
|
|
22
|
+
export declare const fingers: ([, u, f]: Vec3[]) => Vec3;
|
|
23
|
+
/** The right and the left wrist for a sword with its right-hand grip at `at`: the left hand is BEHIND the right one, mirrored. */
|
|
24
|
+
export declare const wrists: (at: Vec3, ax: Vec3[]) => Vec3[];
|
|
25
|
+
/** Appends the katana held in the right hand at `pos` turned by `q`. */
|
|
26
|
+
export declare const held: (out: number[], pos: Vec3, q: Quat, lod: number, t?: number, k?: number) => void;
|
|
27
|
+
/** The root of the blade and its point, in the world, for the hand at `pos` turned by `q`. */
|
|
28
|
+
export declare const ends: (pos: Vec3, q: Quat) => Vec3[];
|
|
29
|
+
/**
|
|
30
|
+
* The axes [right, up, forward] in the camera's space (right, up, forward: a mirror of the world's)
|
|
31
|
+
* for a blade along `d`, rolled by `roll` about it: right as near (cos, sin, 0) as it can be, up
|
|
32
|
+
* forward cross right, so that the frame is a proper turn whichever way the blade points.
|
|
33
|
+
*/
|
|
34
|
+
export declare const frameOf: (d: Vec3, roll: number) => Vec3[];
|
|
35
|
+
/**
|
|
36
|
+
* The cuts. Each is keys of [share of the swing, grip x, y, z, blade direction x, y, z, roll] in
|
|
37
|
+
* the camera's space (right, up, forward), the guard first, and the same guard last: a wind-up,
|
|
38
|
+
* the strike at its tick (every cut passes the middle of the view there, the point 81 cm from
|
|
39
|
+
* the grip) and a follow-through, with the hand taking the slope between its neighbours' keys
|
|
40
|
+
* (fastest through the strike). The right hand holds the grip, the left 9.5 cm behind it.
|
|
41
|
+
*/
|
|
42
|
+
export declare const GUARD: number[];
|
|
43
|
+
/** 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. */
|
|
44
|
+
export declare const stroke: (cut: number, p: number) => number[];
|
|
45
|
+
/**
|
|
46
|
+
* How far through its cut a player is, 0 to 1, or -1 when it is not cutting. `swing` counts down
|
|
47
|
+
* in ticks, and the snapshots of the others come every second tick: the answer runs on with the
|
|
48
|
+
* time, never more than two ticks ahead of the count, never behind it. `was` is the last answer.
|
|
49
|
+
*/
|
|
50
|
+
export declare const progress: (was: number, p: Pick<PlayerState, "swing" | "cut">, dt: number) => number;
|
|
51
|
+
/** Whether the blade is cutting at `p` of its swing: the wind-up and the recovery leave no trail. */
|
|
52
|
+
export declare const cutting: (p: number) => boolean;
|
|
@@ -4,8 +4,10 @@ import type { Vec3 } from './mesh';
|
|
|
4
4
|
* count from `from`: the ammo packs come after the health packs.
|
|
5
5
|
*/
|
|
6
6
|
export declare const packsOf: (all?: readonly Vec3[], mask?: number, from?: number) => Vec3[];
|
|
7
|
-
/** A rack at `at` (a point on a top): a post and a dish, a ring on the roof of the radius that gives the gun, the gun over it. */
|
|
8
|
-
export declare const rack: (out: number[], at: Vec3, rgb: number[], t: number) => void;
|
|
7
|
+
/** A rack at `at` (a point on a top): a post and a dish, a ring on the roof of the radius that gives the gun, the gun over it, or with `blade` the katana, crackling. */
|
|
8
|
+
export declare const rack: (out: number[], at: Vec3, rgb: number[], t: number, blade?: boolean) => void;
|
|
9
|
+
/** Each team's gun rack and katana rack, where it has them. */
|
|
10
|
+
export declare const racks: (out: number[], guns?: readonly (Vec3 | undefined)[], blades?: readonly (Vec3 | undefined)[], t?: number) => void;
|
|
9
11
|
/** A health pack at `at`: a white box with a glowing green cross on each side. */
|
|
10
12
|
export declare const kit: (out: number[], at: Vec3, t: number) => void;
|
|
11
13
|
/** An ammo pack at `at`: a violet box with a glowing cyan cartridge on each side, the gun's colours. */
|
|
@@ -48,6 +48,10 @@ export declare const SOUND: {
|
|
|
48
48
|
readonly GUN: 20;
|
|
49
49
|
readonly PACK: 21;
|
|
50
50
|
readonly DRY: 22;
|
|
51
|
+
/** The katana: the shing of drawing or sheathing it, the swish of a cut (played faster for a thrust, slower for a slash), the electric zap of a hit. */
|
|
52
|
+
readonly SHING: 23;
|
|
53
|
+
readonly SWISH: 24;
|
|
54
|
+
readonly ZAP: 25;
|
|
51
55
|
};
|
|
52
56
|
/**
|
|
53
57
|
* The sounds of the game: one entry per sound, its voices layered, in SOUND order. A low-passed
|
|
@@ -2,6 +2,7 @@ import type { PlayerState } from '../shared/types';
|
|
|
2
2
|
import type { World } from '../shared/world';
|
|
3
3
|
import type { Gait } from './gait';
|
|
4
4
|
import type { Vec3 } from './mesh';
|
|
5
|
+
import type { Trail } from './trail';
|
|
5
6
|
/** What a runner keeps between frames. */
|
|
6
7
|
export interface Runner {
|
|
7
8
|
/** The player as last seen. */
|
|
@@ -14,6 +15,10 @@ export interface Runner {
|
|
|
14
15
|
aim: number;
|
|
15
16
|
/** Where its last shot went, which its gun points at. */
|
|
16
17
|
focus: Vec3;
|
|
18
|
+
/** How far through its katana cut it is, -1 when it is not cutting, the light the blade leaves and the clock of its crackle. */
|
|
19
|
+
prog: number;
|
|
20
|
+
trail: Trail;
|
|
21
|
+
t: number;
|
|
17
22
|
}
|
|
18
23
|
/** A runner as first seen: in the pose its state asks for, no ease. */
|
|
19
24
|
export declare const createRunner: (p: PlayerState) => Runner;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Vec3 } from './mesh';
|
|
2
|
+
/** Seconds a sample of the trail lasts. */
|
|
3
|
+
export declare const LIFE = 0.15;
|
|
4
|
+
export interface Trail {
|
|
5
|
+
/** The blade as drawn: its root and its point; `on` while it cuts, which leaves a ribbon. */
|
|
6
|
+
mark(base: Vec3, tip: Vec3, on: boolean): void;
|
|
7
|
+
/** Ages the samples by dt seconds and drops the ones that are over. */
|
|
8
|
+
update(dt: number): void;
|
|
9
|
+
/** Appends the ribbon, in the vertex format of mesh.ts. */
|
|
10
|
+
draw(out: number[]): void;
|
|
11
|
+
/** The samples alive now. */
|
|
12
|
+
readonly count: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const createTrail: () => Trail;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PlayerState } from './types';
|
|
2
|
+
import type { World } from './world';
|
|
3
|
+
/**
|
|
4
|
+
* The cut the keys held when FIRE starts a swing give: LEFT or RIGHT, one of them, cuts across from
|
|
5
|
+
* that side; else FORWARD thrusts; else (back or no key) it slashes. Both sides held are neither.
|
|
6
|
+
*/
|
|
7
|
+
export declare const cutOf: (keys: number) => number;
|
|
8
|
+
/**
|
|
9
|
+
* The enemies the cut of `p` (`p.cut`, `p` the state after the step that struck) hits, of `foes`
|
|
10
|
+
* (as he saw them): each within CUTS reach of his centre less PLAYER_R on the floor plane, inside
|
|
11
|
+
* the arc round his look (the foe's own angular radius counts: his edge in the arc is a hit), with
|
|
12
|
+
* the heights of the two bodies overlapping and no brush between the chests.
|
|
13
|
+
*/
|
|
14
|
+
export declare const strike: (w: World, p: PlayerState, foes: PlayerState[]) => PlayerState[];
|
|
15
|
+
/**
|
|
16
|
+
* The way the shock of the cut of `p` throws a foe, a unit vector on the floor plane: along his
|
|
17
|
+
* look for a thrust and a slash; a cut across ends on the opposite side to the one it starts from,
|
|
18
|
+
* so LEFT throws to his right and RIGHT to his left.
|
|
19
|
+
*/
|
|
20
|
+
export declare const knock: (p: PlayerState) => [x: number, z: number];
|
|
@@ -187,6 +187,25 @@ export declare const PACK_R = 0.9;
|
|
|
187
187
|
export declare const RACK_R = 1.2;
|
|
188
188
|
/** Metres the feet may be above or below a pack or a rack to take it. */
|
|
189
189
|
export declare const PICK_H = 1;
|
|
190
|
+
/**
|
|
191
|
+
* The cuts, by CUT. A swing lasts `ticks`, during which no other starts, and strikes once, `strike`
|
|
192
|
+
* ticks after its start. It hits every enemy whose body comes within `reach` metres of the
|
|
193
|
+
* attacker's (centre to centre less PLAYER_R, on the floor plane), within `arc` radians either side
|
|
194
|
+
* of his look, at a height his body overlaps, with no brush between. A hit takes `hp`.
|
|
195
|
+
*/
|
|
196
|
+
export declare const CUTS: {
|
|
197
|
+
ticks: number;
|
|
198
|
+
strike: number;
|
|
199
|
+
reach: number;
|
|
200
|
+
arc: number;
|
|
201
|
+
hp: number;
|
|
202
|
+
}[];
|
|
203
|
+
/**
|
|
204
|
+
* A cut that does not put the enemy down shocks him: a stumble (`stumble()`, physics.ts) of
|
|
205
|
+
* SHOCK_TICKS (0.4 s), thrown SHOCK_KNOCK m/s the way the blade goes.
|
|
206
|
+
*/
|
|
207
|
+
export declare const SHOCK_TICKS = 24;
|
|
208
|
+
export declare const SHOCK_KNOCK = 4;
|
|
190
209
|
/** Seconds a carrier who is made to drop the flag cannot take it again: he would pick it up where he stands. */
|
|
191
210
|
export declare const FLAG_LOCK = 2;
|
|
192
211
|
/** Seconds the end screen of a match stays, then a new match starts. */
|
|
@@ -3,16 +3,29 @@ 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. */
|
|
7
|
+
export declare const STRIKE: {
|
|
8
|
+
readonly NONE: 0;
|
|
9
|
+
readonly SHOT: 1;
|
|
10
|
+
readonly CUT: 2;
|
|
11
|
+
};
|
|
12
|
+
export type Strike = (typeof STRIKE)[keyof typeof STRIKE];
|
|
6
13
|
/**
|
|
7
|
-
* One input: the move, then the
|
|
14
|
+
* One input: the move, then the weapons. Returns what struck on this step (STRIKE), for the host to
|
|
15
|
+
* resolve it: a shot, or a cut, which is not a shot.
|
|
8
16
|
* - Down: the keys are dropped, and when `down` runs out the player is back at a spawn.
|
|
9
17
|
* - The team's rack fills the gun when the player steps into its circle (`rack` tells he is in it),
|
|
10
|
-
* and again each time he comes back; staying gives nothing.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
18
|
+
* and again each time he comes back; staying gives nothing. The katana rack gives the katana,
|
|
19
|
+
* once and for good: it stays until he goes down.
|
|
20
|
+
* - In hand (`wield`) is the katana when he has it and wants it (KEY.BLADE) or has no gun, and
|
|
21
|
+
* it stays in hand for the length of a swing.
|
|
22
|
+
* - The trigger: `cool` and `swing` run down, and at 0 a held FIRE fires the gun, with ammo, or
|
|
23
|
+
* starts the katana's swing (`cut` from the keys), unless the hands are busy (a hang, a climb).
|
|
24
|
+
* The cut strikes `CUTS[cut].strike` ticks into its swing. The look is the input's, so both go
|
|
25
|
+
* where the player sees.
|
|
26
|
+
* `armed` is false while the match is over: no weapon, no rack.
|
|
14
27
|
*/
|
|
15
|
-
export declare const step: (p: PlayerState, i: Input, w: World, team: number, armed?: boolean) =>
|
|
28
|
+
export declare const step: (p: PlayerState, i: Input, w: World, team: number, armed?: boolean) => Strike;
|
|
16
29
|
/**
|
|
17
30
|
* The first of `foes` (the players he may hit, as he saw them) that the laser of `p` meets: from his
|
|
18
31
|
* eye along his look, at most GUN_RANGE and not through a brush. `p` is the state after the input
|
|
@@ -27,6 +27,11 @@ export declare const STILL: {
|
|
|
27
27
|
down: number;
|
|
28
28
|
shots: number;
|
|
29
29
|
hits: number;
|
|
30
|
+
blade: boolean;
|
|
31
|
+
wield: boolean;
|
|
32
|
+
swing: number;
|
|
33
|
+
cut: number;
|
|
34
|
+
zap: boolean;
|
|
30
35
|
ev: number;
|
|
31
36
|
fall: number;
|
|
32
37
|
};
|
|
@@ -46,11 +51,12 @@ export declare const speedOf: (p: Pick<PlayerState, "vx" | "vz">) => number;
|
|
|
46
51
|
/** Running faster than a walk on the ground: the sprint, for the animation to pump the arms. */
|
|
47
52
|
export declare const sprinting: (p: Pick<PlayerState, "mode" | "vx" | "vz">) => boolean;
|
|
48
53
|
/**
|
|
49
|
-
* A tackle lands on the player: he stumbles for STUMBLE_TICKS and is thrown
|
|
50
|
-
* (dx, dz), a unit vector (the tackler's way). It ends a dash, a wall-run,
|
|
51
|
-
* clears a jump press and the coyote window. For the host to call between
|
|
54
|
+
* A tackle lands on the player: he stumbles for `ticks` (STUMBLE_TICKS) and is thrown `knock`
|
|
55
|
+
* (STUMBLE_KNOCK) m/s along (dx, dz), a unit vector (the tackler's way). It ends a dash, a wall-run,
|
|
56
|
+
* a hang and a climb, and clears a jump press and the coyote window. For the host to call between
|
|
57
|
+
* two steps. The katana's shock calls it with its own ticks and knock.
|
|
52
58
|
*/
|
|
53
|
-
export declare const stumble: (p: PlayerState, dx: number, dz: number) => void;
|
|
59
|
+
export declare const stumble: (p: PlayerState, dx: number, dz: number, ticks?: number, knock?: number) => void;
|
|
54
60
|
/**
|
|
55
61
|
* Applies one input for 1 / TICK_HZ s, in place: yaw and pitch from the input (pitch clamped to
|
|
56
62
|
* MAX_PITCH), then the step of the current mode (see the top of the file). Feet under the world's
|
|
@@ -28,7 +28,7 @@ export declare const MSG_INPUT = 1;
|
|
|
28
28
|
export declare const MSG_SNAPSHOT = 2;
|
|
29
29
|
export declare const INPUT_BYTES = 12;
|
|
30
30
|
export declare const SNAP_HEAD = 4;
|
|
31
|
-
export declare const SNAP_PLAYER =
|
|
31
|
+
export declare const SNAP_PLAYER = 46;
|
|
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
34
|
/**
|
|
@@ -71,12 +71,28 @@ export declare class Room {
|
|
|
71
71
|
* tackler goes. Once per TACKLE_COOLDOWN ticks, for the first carrier hit.
|
|
72
72
|
*/
|
|
73
73
|
private tackle;
|
|
74
|
+
/**
|
|
75
|
+
* The enemies of `p` as `p` drew them at the view tick `view` (lag compensation), without one who
|
|
76
|
+
* lies down now or did then.
|
|
77
|
+
*/
|
|
78
|
+
private enemies;
|
|
79
|
+
/**
|
|
80
|
+
* `hp` of damage to `foe`; the last one puts him down: he lies where he fell, without the gun or
|
|
81
|
+
* the katana, and a flag he carries drops with the lock. True when he went down.
|
|
82
|
+
*/
|
|
83
|
+
private harm;
|
|
74
84
|
/**
|
|
75
85
|
* A shot of `p` went off at the view tick `view`: it hits the first enemy on its way as `p` drew
|
|
76
|
-
* him
|
|
77
|
-
* him down: he lies where he fell, without the gun, and a flag he carries drops with the lock.
|
|
86
|
+
* him, and takes 1 hp.
|
|
78
87
|
*/
|
|
79
88
|
private shoot;
|
|
89
|
+
/**
|
|
90
|
+
* A cut of `p` struck at the view tick `view`: every enemy it reaches as `p` drew him is hit
|
|
91
|
+
* (`strike`), and the `hits` count goes up once. Each takes the cut's hp; one it does not put
|
|
92
|
+
* down is shocked: a stumble of SHOCK_TICKS thrown SHOCK_KNOCK m/s the way the blade goes, with
|
|
93
|
+
* `zap`, and `by` the attacker. A shock drops no flag.
|
|
94
|
+
*/
|
|
95
|
+
private cut;
|
|
80
96
|
/**
|
|
81
97
|
* The packs, health ones first, then the ammo ones: one that is gone comes back after PACK_BACK
|
|
82
98
|
* s. A health pack goes to a hurt player standing at it, an ammo pack to one with the gun and
|
|
@@ -30,8 +30,24 @@ export declare const KEY: {
|
|
|
30
30
|
readonly DASH: 64;
|
|
31
31
|
/** Hold to crouch, or to slide when fast. */
|
|
32
32
|
readonly CROUCH: 128;
|
|
33
|
-
/** Hold to fire the gun: one shot every GUN_COOLDOWN ticks while there is ammo. */
|
|
33
|
+
/** Hold to fire the gun: one shot every GUN_COOLDOWN ticks while there is ammo. With the katana in hand: a cut (see CUT). */
|
|
34
34
|
readonly FIRE: 256;
|
|
35
|
+
/**
|
|
36
|
+
* Set while the player wants the katana in hand (the client's choice: 1, 2 or the wheel), clear
|
|
37
|
+
* for the gun. Ignored without the katana; without the gun the katana is in hand whatever it says.
|
|
38
|
+
*/
|
|
39
|
+
readonly BLADE: 512;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The katana's cuts (PlayerState.cut, constants CUTS), chosen by the keys held when FIRE starts
|
|
43
|
+
* one: LEFT or RIGHT (one of them) cuts across from that side, else FORWARD thrusts, else (back or
|
|
44
|
+
* no key) it slashes down from above.
|
|
45
|
+
*/
|
|
46
|
+
export declare const CUT: {
|
|
47
|
+
readonly THRUST: 0;
|
|
48
|
+
readonly LEFT: 1;
|
|
49
|
+
readonly RIGHT: 2;
|
|
50
|
+
readonly SLASH: 3;
|
|
35
51
|
};
|
|
36
52
|
/** The movement state of a player: what the body is doing, one of these. */
|
|
37
53
|
export declare const MODE: {
|
|
@@ -144,9 +160,19 @@ export interface PlayerState {
|
|
|
144
160
|
rack?: boolean;
|
|
145
161
|
/** Ticks left lying down after the health ran out; at 0 the player is back at a spawn. 0 when up. */
|
|
146
162
|
down: number;
|
|
147
|
-
/** Shots fired and hits landed, u8 counters that wrap: the clients draw a beam and play the hit sound on each change. */
|
|
163
|
+
/** 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. */
|
|
148
164
|
shots: number;
|
|
149
165
|
hits: number;
|
|
166
|
+
/** Has the katana (taken at the team's katana rack, lost on going down). Absent reads false. */
|
|
167
|
+
blade?: boolean;
|
|
168
|
+
/** The katana is in hand rather than the gun (see KEY.BLADE). Absent reads false. */
|
|
169
|
+
wield?: boolean;
|
|
170
|
+
/** Ticks left in the katana's swing, CUTS[cut].ticks at its start, 0 when ready. Absent reads 0. */
|
|
171
|
+
swing?: number;
|
|
172
|
+
/** CUT of the running or last swing. Absent reads 0. */
|
|
173
|
+
cut?: number;
|
|
174
|
+
/** The running stumble (`stun`) is a katana's shock, not a tackle. Absent reads false. */
|
|
175
|
+
zap?: boolean;
|
|
150
176
|
/** For the animation, not sent: the EV bits of the last step, and the speed of a landing. */
|
|
151
177
|
ev: number;
|
|
152
178
|
fall: number;
|
|
@@ -20,6 +20,8 @@ export interface TeamDef {
|
|
|
20
20
|
spawns: Spawn[];
|
|
21
21
|
/** The gun rack near the spawns, a point on a top: walking within RACK_R gives the gun with AMMO_MAX shots. */
|
|
22
22
|
rack?: Vec3;
|
|
23
|
+
/** The katana rack, next to the gun rack, a point on a top: walking within RACK_R gives the katana. */
|
|
24
|
+
blade?: Vec3;
|
|
23
25
|
}
|
|
24
26
|
export interface WorldDef {
|
|
25
27
|
/** Shown on the title screen. */
|
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.
|
|
5
|
+
"version": "0.31.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|