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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
export const ATLAS_TILE_WIDTH = 32
export const GAME_MAP_COUNT = 4
export enum Tile {
EMPTY = 0,
WALL = 1,
GHOST_WALL = 2,
FOOD = 3,
PLAYER_SPAWN_1 = 4,
PLAYER_SPAWN_2 = 5,
PLAYER_SPAWN_3 = 6,
PLAYER_SPAWN_4 = 7,
GHOST_SPAWN = 8,
THICC_DOT = 9,
INITIAL_DOT = 10
}
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,
THICC_DOT,
FOOD
}
export enum Key {
NOTHING,
UP,
DOWN,
LEFT,
RIGHT
}
export enum GhostType {
BLINKY = 0,
PINKY = 1,
INKY = 2,
CLYDE = 3
}
export enum GhostState {
CHASE,
SCATTER,
EATEN,
SCARED
}
export type Ghost = {
pos: Vec2,
type: GhostType,
target: Vec2,
state: GhostState,
currentDirection: Rotation,
}
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,
moving: boolean,
name?: string
}
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 enum SpawnIndex {
PAC_SPAWN_1 = 1,
PAC_SPAWN_2 = 2,
PAC_SPAWN_3 = 3,
PAC_SPAWN_4 = 4,
GHOST_SPAWN = 0
}
export type Map = {
data: number[],
walls: number[],
width: number,
height: number,
id: number,
spawns?: Vec2[]
}
export type Maps = {
[key: number]: Map
}
export type Ghosts = [Ghost, Ghost, Ghost, Ghost]
export type GameState = {
started: boolean,
input: InputMap,
players: Players,
ghosts: Ghosts,
items: Items,
frame: number,
rng: number,
mapId: number | undefined
}
export type Frame = {
data: GameState,
input: Input
}
|