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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
export enum Wall {
EMPTY,
WALL_HZ,
WALL_VT,
TURN_Q1,
TURN_Q2,
TURN_Q3,
TURN_Q4,
TEE_NORTH,
TEE_EAST,
TEE_SOUTH,
TEE_WEST,
CROSS,
DOT,
WALL_END_NORTH,
WALL_END_SOUTH,
WALL_END_EAST,
WALL_END_WEST
}
export enum ItemType {
DOT
}
export enum Key {
NOTHING,
UP,
DOWN,
LEFT,
RIGHT
}
export type KeyMap = {
[key: string]: Key
}
export const GameKeyMap = {
"KeyW": Key.UP,
"KeyA": Key.LEFT,
"KeyS": Key.DOWN,
"KeyD": Key.RIGHT,
}
export enum Rotation {
NOTHING,
NORTH,
EAST,
SOUTH,
WEST
}
export type Vec2 = {
x: number,
y: number
}
export type InputMap = {
[key: number]: Key
}
export type Player = {
pos: Vec2,
moveRotation: Rotation,
inputRotation: Rotation,
name?: string,
moving: boolean
}
export type PlayerInput = {
start: boolean,
key: Key,
name?: string
}
export type Input = {
players: {[key: number]: PlayerInput},
added?: number[],
removed?: number[],
}
export type Message = {
type?: string;
connections?: number[],
added?: number,
removed?: number,
id?: number,
frame?: number,
data?: any,
connection?: number,
state?: GameState,
error?: string
}
export type Players = {
[key: number]: Player
}
export type Item = {
type: ItemType,
pos: Vec2
}
export type Items = {
[key: number]: Item
}
export type Map = {
data: number[],
walls: number[],
width: number,
height: number,
id: number
}
export type Maps = {
[key: number]: Map
}
export type GameState = {
started: boolean,
input: InputMap,
players: Players,
items: Items,
mapId: number | undefined
}
export type Frame = {
data: GameState,
input: Input
}
|