forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMazeMission.js
352 lines (330 loc) · 7.23 KB
/
MazeMission.js
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*
@title: MazeMission
@author: CaitlinOchuwa
@tags: ['puzzle']
@addedOn: 2024-08-06
HOW TO PLAY
'WASD' to control your player
'I' to reset the game
The goal is to get to the door to escape the mazes. However, in order to maximize your score
and successfully complete the run, you must collect all of the coins. But, the red coins
are known as AntiCoins and actually hurt your score. Collect coins, avoid the AntiCoins, and navigate
through the mazes to become the ultimate maze master!
*/
//CONSTANTS
const player = "p"
const antiCoin = "o"
const spike = "s"
const spikeRight = "r"
const spikeLeft = "l"
const spikeDown = "a"
const coin = "c"
const door = "d"
const background = "b"
const collectedCoin = tune `
461.53846153846155: B5~461.53846153846155,
14307.692307692309`
const collectedAntiCoin = tune `
461.53846153846155: C4^461.53846153846155,
14307.692307692309`
setLegend(
[ player, bitmap`
................
................
................
................
................
................
......9999......
.....999999.....
.....909909.....
.....999999.....
.....990099.....
......9999......
......0..0......
.....00..00.....
................
................` ],
[ spike, bitmap `
.......00.......
......0000......
.....000000.....
....00000000....
...0000000000...
..000000000000..
.00000000000000.
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
[ coin, bitmap `
................
................
................
................
.....66666......
....6666666.....
....6600066.....
....6606666.....
....6600066.....
....6666666.....
.....66666......
................
................
................
................
................`],
[door, bitmap `
................
................
................
.....CCCCCC.....
.....CCCCCC.....
.....CCCCCC.....
.....CCCCCC.....
.....CCCCCC.....
.....CCCC6C.....
.....CCCCCC.....
.....CCCCCC.....
.....CCCCCC.....
.....CCCCCC.....
.....CCCCCC.....
................
................`],
[ background, bitmap `
................
................
................
................
................
................
................
................
................
................
................
................
................
................
................
................` ],
[spikeRight, bitmap `
000000000.......
0000000000......
00000000000.....
000000000000....
0000000000000...
00000000000000..
000000000000000.
0000000000000000
0000000000000000
000000000000000.
00000000000000..
0000000000000...
000000000000....
00000000000.....
0000000000......
000000000.......`],
[spikeLeft, bitmap `
.......000000000
......0000000000
.....00000000000
....000000000000
...0000000000000
..00000000000000
.000000000000000
0000000000000000
0000000000000000
.000000000000000
..00000000000000
...0000000000000
....000000000000
.....00000000000
......0000000000
.......000000000`],
[spikeDown, bitmap `
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
.00000000000000.
..000000000000..
...0000000000...
....00000000....
.....000000.....
......0000......
.......00.......`], [antiCoin, bitmap`
................
................
................
................
.....33333......
....3333333.....
....3300033.....
....3303333.....
....3300033.....
....3333333.....
.....33333......
................
................
................
................
................`]
)
setBackground(background)
//GLOBAL VARIABLES
var score = 0
var isSecretChallenge = false
//SCORE AND LIVES LABELS
addText(`Score: ${score}`,{x: 0, y: 0, color: color`4`})
addText(` WASD to move\n 'i' to reset\n Collect coins and\n navigate through\n the mazes to win!`, {x: 1, y:5, color: color`D`})
setSolids([player, spike, spikeRight, spikeLeft, spikeDown])
let levelNumber = 0
const levels = [ map `
aad
rc.
p.l`, map `
d.aa
rc..
raa.
p..c`, map `
.....
.sss.
.ldr.
.l.r.
pl.c.`, map `
aaaaaaa
rcro.cl
r.r.l.l
r..cl.l
rss...l
r...s..
p.o.csd`, map `
ca.c.aaa
..da.c.c
rcoco..a
r....rc.
c.lc.roc
..l..c..
colcosss
pc..c..c`, map `
..d.aa
sss...
c.ocr.
.aa.r.
p...oc`, map `
..o.....c....l
.aaa..aa...r.l
.clc...o...r.l
..l..sssssss.l
..l.o......r.l
........co.r.l
.aaa.l.aaa.rcl
.aalcl.olo.rss
...l.l.cl.....
po.c..o....s.d`, map`
daaaa
....o
aaa.c
p...o`
]
setMap(levels[levelNumber])
setPushables({
[ player ]: []
})
//USER INPUT
onInput("d", () => {
getFirst(player).x += 1;
})
onInput("a", () => {
getFirst(player).x -= 1;
})
onInput("w", () => {
getFirst(player).y -= 1;
})
onInput("s", () => {
getFirst(player).y += 1;
})
onInput("i", () => {
resetGame()
})
onInput("j", () => {
resetGame()
isSecretChallenge = true
addText(`Collect the LEAST\namount of coins\n possible to win`, {x: 1, y: 10, color: color`9`})
})
afterInput(() => {
let antiCoins = getAll(antiCoin)
let coins = getAll(coin)
let character = getFirst(player)
let thisTile = getTile(getFirst(player).x, getFirst(player).y);
if(thisTile.length > 1){
if(thisTile[1]._type == "d"){
if(levelNumber >= levels.length - 1){
if(score == 36){
addText(`Congrats! You Win!`, {x: 1, y: 5, color: color`4`})
addText(`Press 'j' to play\na secret challenge`, {x: 1, y: 8, color: color`6`})
addText(`Press 'i' to reset\n the game`, {x: 1, y: 13, color: color`4`})
}
else if(isSecretChallenge == false && score < 36){
addText(`Try again. Collect\n All Coins`, {x: 1, y: 5, color: color `3`})
addText(`Press 'i' to reset\n the game`, {x: 1, y: 13, color: color `3`})
}
else if(score == 9 && isSecretChallenge == true){
addText(`Congrats! You are\n the ultimate\n maze master!`, {x: 1, y: 5, color: color `9`})
addText(`Press 'i' to reset\n the game`, {x: 1, y: 13, color: color `9`})
}
else{
addText(`Try again, Collect\nthe LEAST amount\n of coins`, {x: 1, y: 5, color: color `3`})
addText(`Press 'i' to reset\n the game`, {x: 1, y: 13, color: color`3`})
}
}
else{
levelNumber++
setMap(levels[levelNumber])
}
}
}
for(let i = 0; i < coins.length; i++){
if(character.x === coins[i].x && character.y === coins[i].y){
coins[i].remove()
playTune(collectedCoin)
score += 1;
clearText()
addText(`Score: ${score}`,{x: 0, y: 0, color: color`4`})
}
}
for(let i = 0; i < antiCoins.length; i++){
if(character.x === antiCoins[i].x && character.y === antiCoins[i].y){
antiCoins[i].remove()
playTune(collectedAntiCoin)
score -= 2;
clearText()
addText(`Score: ${score}`,{x: 0, y: 0, color: color`3`})
}
}
if(score < 0){
addText(`Try again. Collect\n All GOLD Coins`, {x: 1, y: 5, color: color `3`})
addText(`Press 'i' to reset\n the game`, {x: 1, y: 11, color: color `3`})
}
})
//RESETS THE GAME
function resetGame(){
score = 0
isSecretChallenge = false
clearText()
addText(`Score: ${score}`,{x: 0, y: 0, color: color`4`})
addText(` WASD to move\n 'i' to reset\n Collect coins and\n navigate through\n the mazes to win!`, {x: 1, y:5, color: color`D`})
levelNumber = 0
setMap(levels[levelNumber])
}