/
com_control_player.ts
48 lines (45 loc) 路 1.35 KB
/
com_control_player.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* # ControlPlayer
*
* Make the entity controllable by the player. Suitable for first-person and
* third-person 3D games, as well as some camera control schemes.
*/
import {Entity} from "../../lib/world.js";
import {Game} from "../game.js";
import {Has} from "../world.js";
export interface ControlPlayer {
Move: boolean;
Yaw: number;
Pitch: number;
MinPitch: number;
MaxPitch: number;
}
/**
* Add `ControlPlayer` to an entity.
*
* @param move - Whether to control the entity's movement.
* @param yaw - Sensitivity of the yaw control. 1 means that 1 pixel traveled
* by the mouse is equal to 1掳 of rotation; that's too sensitive usually.
* @param pitch - Sensitivity of the pitch control. 1 means that 1 pixel traveled
* by the mouse is equal to 1掳 of rotation; that's too sensitive usually.
* @param min_pitch - Min pitch allowed, in arc degrees.
* @param max_pitch - Max pitch allowed, in arc degrees.
*/
export function control_player(
move: boolean,
yaw: number,
pitch: number,
min_pitch = 0,
max_pitch = 0,
) {
return (game: Game, entity: Entity) => {
game.World.Signature[entity] |= Has.ControlPlayer;
game.World.ControlPlayer[entity] = {
Move: move,
Yaw: yaw,
Pitch: pitch,
MinPitch: min_pitch,
MaxPitch: max_pitch,
};
};
}