forked from galah4d/pacman-cx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.cx
More file actions
238 lines (213 loc) · 9.57 KB
/
board.cx
File metadata and controls
238 lines (213 loc) · 9.57 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package main
import "graphical2d"
var x_cells i32 = 28
var y_cells i32 = 31
var CELL_WIDTH f32 = 0.07143
var CELL_HEIGHT f32 = 0.0645
var CELL_HALF_WIDTH f32 = CELL_WIDTH / 2.0
var CELL_HALF_HEIGHT f32 = CELL_HEIGHT / 2.0
// Item Types
var PATH_CELL i32 = 3
var WALL_CELL i32 = 1
var PATH_CELL_WITH_SIMPLE_POINT i32 = 0
var PATH_CELL_WITH_SUPER_POINT i32 = 2
var TELEPORT_CELL i32 = 4
var GATE_CELL i32 = 5
// Point constants
var SIMPLE_POINT_RADIUS f32 = 0.01
var SUPER_POINT_RADIUS f32 = 0.015
var POINT_COLOR_RED f32 = 1.0
var POINT_COLOR_GREEN f32 = 1.0
var POINT_COLOR_BLUE f32 = 1.0
// Animation timers
var POINT_ANIMATION_TIMER f64 = 0.0D
var POINT_ANIMATION_SEMI_LIMIT f64 = 0.2D
var POINT_ANIMATION_LIMIT f64 = 0.4D
// Lives Variables
var LIFE_SPAWN_LINE i32 = 30
var LIFE_SPAWN_COLUMN i32 = 26
var LIFE_COLOR_RED f32 = 1.0
var LIFE_COLOR_GREEN f32 = 0.0
var LIFE_COLOR_BLUE f32 = 0.0
var LIFE_RADIUS f32 = 0.02
/* Function : initScene
Description : Initializes all game objects including the board cells, the
points, the ghosts and the player.
*/
func initScene() {
// Initialize game board items
var line [28]i32
for i:=0; i<y_cells; i++ {
line = get_board_line(i32.add(i, 1))
for j:=0; j<x_cells; j++ {
initializeItem(i, j, line[j])
}
}
// Initialize player
player = newPlayer(PLAYER_SPAWN_LINE, PLAYER_SPAWN_COLUMN, PLAYER_RADIUS)
nextLifePos = coords2position(LIFE_SPAWN_LINE, i32.sub(LIFE_SPAWN_COLUMN, PLAYER_LIVES - 1))
// Initialize ghosts
ghosts[0] = newGhost(11, 13, 0, GHOST_MODE_CHASE) // Shadow
ghosts[1] = newGhost(14, 11, 1, GHOST_MODE_IN_HOUSE) // Speedy
ghosts[2] = newGhost(14, 13, 2, GHOST_MODE_IN_HOUSE) // Bashful
ghosts[3] = newGhost(14, 15, 3, GHOST_MODE_IN_HOUSE) // Pokey
}
func initializeItem(line i32, col i32, item_type i32) {
//x := f32.add(-1.0, f32.add(f32.mul(i32.f32(col), CELL_WIDTH), f32.div(CELL_WIDTH, 2.0)))
//y := f32.sub(1.0, f32.add(f32.mul(i32.f32(line), CELL_HEIGHT), f32.div(CELL_HEIGHT, 2.0)))
if i32.eq(item_type, WALL_CELL) {
cells[line][col] = newCell(line, col, WALL_CELL)
}
if i32.eq(item_type, PATH_CELL) {
cells[line][col] = newCell(line, col, PATH_CELL)
}
if i32.eq(item_type, PATH_CELL_WITH_SIMPLE_POINT) {
points[points_count] = newPoint(line, col, PATH_CELL_WITH_SIMPLE_POINT)
points_count = i32.add(points_count, 1)
cells[line][col] = newCell(line, col, PATH_CELL)
}
if i32.eq(item_type, PATH_CELL_WITH_SUPER_POINT) {
points[points_count] = newPoint(line, col, PATH_CELL_WITH_SUPER_POINT)
points_count = i32.add(points_count, 1)
cells[line][col] = newCell(line, col, PATH_CELL)
}
if i32.eq(item_type, TELEPORT_CELL) { // FIX ME merge multiple cases together
cells[line][col] = newCell(line, col, TELEPORT_CELL)
}
if i32.eq(item_type, GATE_CELL) {
cells[line][col] = newCell(line, col, GATE_CELL)
}
}
/* Function : isLevelCompleted
Output : true if the level is completed, false otherwise.
Description : Checks if all the points on the board were caught allowing the
player to progress to the next level if this condition is met.
*/
func isLevelCompleted() (is_completed bool) {
is_completed = true
for i:=0; i<points_count; i++ {
if points[i].active {
is_completed = false
}
}
}
// FIX ME change game settings
// Checks if all the points on the board were caught allowing the
// player to progress to the next level if this condition is met.
func levelUp() {
if i32.lteq(GAME_LEVEL, GAME_MAX_LEVEL) {
GAME_LEVEL = i32.add(GAME_LEVEL, 1)
GHOST_RELEASE_LIMIT = f64.sub(GHOST_RELEASE_LIMIT, GHOST_RELESE_MODIFIER)
GHOST_MOVEMENT_LIMIT = f64.sub(GHOST_MOVEMENT_LIMIT, GHOST_MOVEMENT_MODIFIER)
GHOST_FRIGHTENED_LIMIT = f64.sub(GHOST_FRIGHTENED_LIMIT, GHOST_FRIGHTENED_MODIFIER)
GHOST_FRIGHTENED_SEMI_LIMIT = f64.sub(GHOST_FRIGHTENED_SEMI_LIMIT, GHOST_FRIGHTENED_SEMI_MODIFIER)
GHOST_CHASE_LIMIT = f64.add(GHOST_CHASE_LIMIT, GHOST_CHASE_MODIFIER)
GHOST_SCATTER_LIMIT = f64.sub(GHOST_SCATTER_LIMIT, GHOST_SCATTER_MODIFIER)
}
}
/* Function : coords2position
Input : Vertical board position (line i32)
: Horizontal board position (column i32)
Output : A position in the game screen (position graphical2d.Position2D)
Description : Maps a (line/column) pair into an actual screen coordinates
*/
func coords2position(line i32, column i32) (position graphical2d.Position2D) {
x := f32.add(-1.0, f32.add(f32.mul(i32.f32(column), CELL_WIDTH), f32.div(CELL_WIDTH, 2.0)))
y := f32.sub(1.0, f32.add(f32.mul(i32.f32(line), CELL_HEIGHT), f32.div(CELL_HEIGHT, 2.0)))
position = graphical2d.newPosition2D(x, y)
}
func get_board_line(i i32) (line [28]i32) {
if i32.eq(i, 1) {
line = [28]i32{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
}
if i32.eq(i, 2) {
line = [28]i32{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
}
if i32.eq(i, 3) {
line = [28]i32{1, 2, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 2, 1}
}
if i32.eq(i, 4) {
line = [28]i32{1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1}
}
if i32.eq(i, 5) {
line = [28]i32{1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1}
}
if i32.eq(i, 6) {
line = [28]i32{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
}
if i32.eq(i, 7) {
line = [28]i32{1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1}
}
if i32.eq(i, 8) {
line = [28]i32{1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1}
}
if i32.eq(i, 9) {
line = [28]i32{1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1}
}
if i32.eq(i, 10) {
line = [28]i32{1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 3, 1, 1, 3, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1}
}
if i32.eq(i, 11) {
line = [28]i32{1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 3, 1, 1, 3, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1}
}
if i32.eq(i, 12) {
line = [28]i32{1, 1, 1, 1, 1, 1, 0, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 0, 1, 1, 1, 1, 1, 1}
}
if i32.eq(i, 13) {
line = [28]i32{1, 1, 1, 1, 1, 1, 0, 1, 1, 3, 1, 1, 1, 5, 5, 1, 1, 1, 3, 1, 1, 0, 1, 1, 1, 1, 1, 1}
}
if i32.eq(i, 14) {
line = [28]i32{1, 1, 1, 1, 1, 1, 0, 1, 1, 3, 1, 3, 3, 3, 3, 3, 3, 1, 3, 1, 1, 0, 1, 1, 1, 1, 1, 1}
}
if i32.eq(i, 15) {
line = [28]i32{3, 3, 3, 3, 3, 1, 0, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 0, 1, 3, 3, 3, 3, 3}
}
if i32.eq(i, 16) {
line = [28]i32{1, 1, 1, 1, 1, 1, 0, 1, 1, 3, 1, 3, 3, 3, 3, 3, 3, 1, 3, 1, 1, 0, 1, 1, 1, 1, 1, 1}
}
if i32.eq(i, 17) {
line = [28]i32{1, 1, 1, 1, 1, 1, 0, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 0, 1, 1, 1, 1, 1, 1}
}
if i32.eq(i, 18) {
line = [28]i32{1, 1, 1, 1, 1, 1, 0, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 0, 1, 1, 1, 1, 1, 1}
}
if i32.eq(i, 19) {
line = [28]i32{1, 1, 1, 1, 1, 1, 0, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 0, 1, 1, 1, 1, 1, 1}
}
if i32.eq(i, 20) {
line = [28]i32{1, 1, 1, 1, 1, 1, 0, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 0, 1, 1, 1, 1, 1, 1}
}
if i32.eq(i, 21) {
line = [28]i32{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
}
if i32.eq(i, 22) {
line = [28]i32{1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1}
}
if i32.eq(i, 23) {
line = [28]i32{1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1}
}
if i32.eq(i, 24) {
line = [28]i32{1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1}
}
if i32.eq(i, 25) {
line = [28]i32{1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1}
}
if i32.eq(i, 26) {
line = [28]i32{1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1}
}
if i32.eq(i, 27) {
line = [28]i32{1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1}
}
if i32.eq(i, 28) {
line = [28]i32{1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}
}
if i32.eq(i, 29) {
line = [28]i32{1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1}
}
if i32.eq(i, 30) {
line = [28]i32{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
}
if i32.eq(i, 31) {
line = [28]i32{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
}
}