forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCobble_Maze.js
527 lines (512 loc) · 10.5 KB
/
Cobble_Maze.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
/*
@title: Cobble Maze
@author: yashsethu
@tags: []
@addedOn: 2024-08-13
*/
const down = "d"
const up = "n"
const right_1 = "r"
const right_2 = "s"
const left_1 = "t"
const left_2 = "u"
const ground = "m"
const v_wall = "v"
const h_wall = "h"
const u_r = "a"
const u_l = "b"
const d_r = "c"
const d_l = "z"
const c_r = "f"
const c_l = "g"
const c_u = "i"
const c_d = "j"
const goal = "w"
const chest = "e"
const lock = "k"
setLegend(
[ down, bitmap`
LL1LL000000LL1L1
1LL102222220LLLL
LLLL020220201LLL
LLLL02022020LL1L
1L1L022222201LLL
LLLLL022220LLLLL
L1L00CLLLLC00L1L
LLL0LLCLLCLL0LLL
LL00LLLLLLLL00LL
L0220LL33LL0220L
L0220LL33LL0220L
1L000LLLLLL000L1
LL1L0CC00CC0LLLL
LLLL0CC00CC0L1LL
LLLLL00LL00LLL1L
1LL1LLLL1LL1LLLL` ],
[ up, bitmap`
.....000000.....
....02222220....
....02222220....
....02222220....
....02222220....
.....022220.....
...00CCCCCC00...
...0LLLLLLLL0...
..00LLLLLLLL00..
.0220LLLLLL0220.
.0220LLLLLL0220.
..000LLLLLL000..
....0CC00CC0....
....0CC00CC0....
.....00..00.....
................` ],
[ right_1, bitmap`
................
.....000000.....
....02222220....
....02222200....
....02222200....
....02222220....
.....022220.....
....0LLCCCL0....
....0LLLLLC0....
...00LLLLLL00...
..0220LLLL3020..
..0220LLLL3020..
...000LLLLL00...
...0C000CCCC0...
...0CC000CCC0...
....00...000....` ],
[ left_1, bitmap`
................
.....000000.....
....02222220....
....00222220....
....00222220....
....02222220....
.....022220.....
....0LCCCLL0....
....0CLLLLL0....
...00LLLLLL00...
..0203LLLL0220..
..0203LLLL0220..
...00LLLLL000...
...0CCCC000C0...
...0CCC000CC0...
....000...00....` ],
[ right_2, bitmap`
................
.....000000.....
....02222220....
....02220200....
....02220200....
....02222220....
.....022220.....
....0LLCLLL0....
....0LLLCLL0....
...00LLLLL00....
..020LLLL0220...
..020LLLL0220...
...0CCC000000...
...0CCC00CCC0...
...0CC0..0CC0...
....00....00....` ],
[ left_2, bitmap`
................
.....000000.....
....02222220....
....00202220....
....00202220....
....02222220....
.....022220.....
....0LLLCLL0....
....0LLCLLL0....
....00LLLLL00...
...0220LLLL020..
...0220LLLL020..
...000000CCC0...
...0CCC00CCC0...
...0CC0..0CC0...
....00....00....` ],
[ v_wall, bitmap`
LLLLLL0000LLL1LL
L1L1LL0000LLLLLL
1LLLL10000L1LLLL
LLL1LL0000LL1L1L
L1LLLL00001LLLLL
LLLLLL0000LLLL1L
LLLL1L0000L1LLLL
L1LLLL0000LL1L1L
LLLLLL0000LLLLLL
LLLL1L0000L1L1LL
L11LLL0000LL1LLL
LLLLLL0000LLLLL1
LL1L1L00001LLLLL
L1LLL10000LL1LLL
LL1LLL0000L1LLLL
LLLL1L0000LLLL1L` ],
[ ground, bitmap`
L1LLLLLLL1LLLL1L
LLLLLLL1LLLLLLLL
LLLL1LLLLLLLL1LL
LLLLLLLLL1LLLLLL
L1LLLLLLLLL1L1LL
LLLLLLL1LLLLLLLL
LLLLL1LLLLLLLL1L
LL1LLLLLLL1LLLLL
LLLLLLLLLLLLLL1L
1L1LLLL1LLL1LLLL
LLLLL1LLLLLLLL1L
LLLLLLLL1LLLLLLL
LL1LLLLLLLL1LLLL
LLLLLLLLLLLLLLLL
1LLL1LL1LLLLLL1L
LLLLLLLLLLL1LLLL` ],
[ h_wall, bitmap`
LLLLLL1LLLLLL1LL
LL1L1LL1LLL1LLL1
1LLLLLLLLLLLLLLL
LLLL1LLLLL1LL1LL
LLL1LL1L1LLLLLL1
L1LLLLLLLLL1LLLL
0000000000000000
0000000000000000
0000000000000000
0000000000000000
LLLLLL1LLL1LLLL1
L1LL1LLLLLLLL1LL
LLLLLLLLLLL1LLLL
LL1L1LL1LL1LLLL1
LLLLLLLLLLLLLLLL
L1LLLL1L1LL1L1LL` ],
[ u_r, bitmap`
1LLLL10000L1LLL1
LL1LLL0000LLL1LL
LLLL1L0000L1LLLL
LLLLLL00001LLL1L
L1L1LL0000LLLLLL
LLLLLL0000LL1LL1
LLLL1L0000000000
L1L1LL0000000000
LLLLLL0000000000
1L1LL10000000000
LLLLLLLLLLLLL1LL
LLLL1L1LL1LL1LLL
L1LLLLLLLLLLLLL1
LLLLLL1LL1L1L1LL
LL1L1LLL1LLLLLLL
1LLLLLL1LLL1LLL1` ],
[ u_l, bitmap`
LL1LL10000L1LLLL
LLLLLL0000LLL1LL
L1LL1L0000LLLLLL
LL1LLL0000LL1L1L
LLLLLL0000LLLLLL
1LLL1L00001LLLLL
0000000000LL1LLL
0000000000L1LL1L
0000000000LLLLLL
00000000001LLLLL
LLL1LLL1LLL1LL1L
L1LLLLLLLLLLLLLL
LLLLL1LL1LL1LLLL
LL1LLLLLLLLLL1LL
1LLL1LLLLL1LLLL1
LL1LLL1L1LLLL1LL` ],
[ d_r, bitmap`
LL1LL1LLLL1LLLLL
LLLLLLLLLLLL1LL1
1LLLL1LL1LLLLLLL
LL1LLLLLLLLLLLL1
LLLLL1LLLL1LLL1L
L1LLLLLL1LLL1LLL
LLL1LL0000000000
LLLLLL0000000000
1LLL1L0000000000
LLLLLL0000000000
LL1LLL0000L1L1LL
LLLL1L0000LLLLL1
1LLLLL00001LL1LL
LLLLLL0000LLLLLL
LLL1LL0000L1LLL1
1LLLLL0000LLL1LL` ],
[ d_l, bitmap`
1LLLLLLLLLL1LL1L
LL1L1LL1L1LLLLLL
LLLLLLLLLLL1LLLL
LL1LLLLL1LLLLL1L
LLLLLL1LLL1LLLLL
1LLL1LLL1LLLLLLL
0000000000LLL1LL
0000000000L1LLLL
0000000000LLLLL1
0000000000LL1LLL
LLLLL10000L1LL1L
1LL1LL0000LLLLLL
LLLLLL0000LLLL1L
L1LLL10000L1LLLL
LL1LLL0000LLL1L1
LLLLL10000L1LLLL` ],
[ c_r, bitmap`
1LLL1L0000LL1LL1
LLLLLL0000LLLLLL
L1LL1L00001LL1LL
LLLLLL0000LLLL1L
L1LLL10000LLLLLL
LLLLLL0000L1L1LL
1LLL1L0000000000
LLLLLL0000000000
LL1LLL0000000000
LLLLL10000000000
1LLLLL0000LL1LLL
LLL1LL0000LLLLL1
L1LLLL0000LL1LLL
LLLLLL00001LLL1L
LL1LL10000LLLLLL
1LL1LL0000L1L1LL` ],
[ c_l, bitmap`
L1LLL10000L1LLLL
LLL1LL0000LLLLLL
LLLLLL0000LL1LLL
1LL1LL0000LLLL1L
LLLLLL0000L1LLLL
LL1LL10000LLLLLL
0000000000LLL1LL
0000000000LLLLLL
00000000001LLLLL
0000000000LLLL1L
L1LLLL0000LL1LLL
LL1L1L0000LLLLLL
L1LLLL00001L1L1L
LLLLL10000LLLLLL
L1L1LL0000LL1LLL
LL1L1L0000L1LL1L` ],
[ c_d, bitmap`
1LL1LLLL1LL1LLLL
LLLLLL1LLLLLL1L1
LLLL1LLLLLLLLLLL
L1LLLLLL1LL1LLLL
LLLL1LLLLLLLL1L1
1LLLLLL1LLL1LLLL
0000000000000000
0000000000000000
0000000000000000
0000000000000000
LLLL1L00001LLL1L
L1L1LL0000LLL1LL
LLLLLL0000L1LLLL
LL1L1L0000LLLL1L
LLLLLL00001LLLLL
LL1LLL0000LL1LL1` ],
[ c_u, bitmap`
1LLLL10000L1LLLL
L1L1LL0000LLLLL1
LLLLLL0000LL1LLL
1LLLLL0000LLLLL1
LLL1LL0000L1LLLL
L1LLL10000LLL1LL
0000000000000000
0000000000000000
0000000000000000
0000000000000000
1LLLL1LLLLLLLL1L
LLLLLLLLL1LLLLLL
L1L1LLLLLLL1L1LL
LLLLLL1L1LLLLLLL
L1LLLLLLLL1LLLLL
LLL1LL1LLLL1LL1L` ],
[ goal, bitmap`
LL1LLLLL1LLLL1LL
LLLLL000000LLLLL
1LL106666660L1L1
LL006633336600LL
L06063333336060L
L06066333366060L
LL006663366600L1
L1LL06666660L1LL
1LL1L06FF601LLLL
LLLL106FF60LLLLL
LL1LL06FF60L1LL1
LLLLL06FF60LLLLL
LLLL06666660LLLL
L1L0000000000L1L
LLLLLLLLLLLLLLLL
1LL1LLL1LLL1LLL1` ],
[ chest, bitmap`
000LL1LLL1LL1000
0FF0000000000FF0
060CCCCCCCCCC060
060CCCCCCCCCC060
060CCCCCCCCCC060
060CCCCCCCCCC060
060CCC0000CCC060
0000006666000000
0666666006666660
0000660000660000
060C06600660C060
060CC066660CC060
060CCC0000CCC060
060CCCCCCCCCC060
0F0CCCCCCCCCC0F0
0000000000000000` ],
[ lock, bitmap`
1L1L00000000LLL1
LLL0666666660L1L
LL10600000060LLL
1LL060LLLL0601LL
LL000000000000L1
L06666666666660L
0F666666666666F0
0F666666666666F0
0F666666666666F0
0F666600006666F0
0F666600006666F0
0F666660066666F0
0F666666666666F0
0F666666666666F0
L0FFFFFFFFFFFF01
1L000000000000LL` ]
)
setSolids([ down, up, right_1, left_1, right_2, left_2, v_wall, h_wall, u_r, u_l, d_r, d_l, c_r, c_l, c_u, c_d ])
let level = 0
const levels = [
map`
chjdjhhhhhhz
vmvmvmmmmmmv
vmvmahhzmvmv
vmmmmmmvmvev
fhzkvmmmmfhg
vmvmfhhhhgmw
vmmmvmmmmvmv
vmvmvmvmhbkv
vmvmvmvmmmmv
vmahbmvmchmv
vmmmmmvmvemv
ahhhhhihihhb`,
map`
chhhhhjhhhhhz
vmmmmmvmmmmev
vmhhzmvmchhhg
vmmmvmvmvmmmv
ahhmvmvmvkvmv
dmmmvmvmmmvmv
chhhbmfhhmvmv
vmmmmmvmmmvmv
vmchhhbkchbmv
vmvemmmmvmmmv
vmahhhhmvmvmv
vmmmmmmmvmvmv
ahhhhhhhbwahb`,
map`
chhhhhjhhhjhhhjhhhhhh
vmmmmmvemmvmmmvmmmmmw
fhzmvmahzmvmvmahhhhkv
vevkvmmmvmkmvmmmmmmmv
vmvmahzmvmchihjhhmchg
vmvmmmvmmmvmmmvemmvev
vmahzmahhhgmchihjhbmv
vmmmvmmmmmvmvmmmvmmmv
vmchihhkchbmvmvmahhmv
vmvmmmmmvmmmvmvmmmmmv
vmvmhhjhgmhhbmvmvmchg
vmvmmmvmvmmmmmvmvmvmv
vmahhkvmahhmhhbmvmvmv
vmmmmmmmmmmmmmmmvmvmv
fhhhhmvmchzmchhhbmvmv
vmmmmmvmvmvmvmmmmmmmv
vmchhmvmvmvmvmvmchhhg
vmvmmmmmvmmmmmvmvmmmv
vmahhhhmvmhhzmahbmvmv
dmmmmmmmmmmmvmmmmmvev
hhhhhhhhhhhhihhhhhihb`
]
setMap(levels[level])
let current_sprite = down
let keys = 0
onInput("s", () => {
let player = getFirst(current_sprite)
let destTile = getTile(player.x, player.y + 1) // Check the tile below the player
// Check if the destination tile is of type 'ground' or 'goal' before moving
let destType = destTile.length > 0 ? destTile[0].type : ''
if (destType === lock && keys > 0) {
keys -= 1
destType = ground
}
if (destType === ground || destType === goal || destType === chest) {
if (destType === chest) {
keys += 1
}
clearTile(player.x, player.y)
current_sprite = down
addSprite(player.x, player.y + 1, current_sprite) // Spawn new player sprite below
addSprite(player.x, player.y, ground) // Replace ground tile where the player moved from
}
})
onInput("w", () => {
let player = getFirst(current_sprite)
let destTile = getTile(player.x, player.y - 1) // Check the tile above the player
// Check if the destination tile is of type 'ground' or 'goal' before moving
let destType = destTile.length > 0 ? destTile[0].type : ''
if (destType === lock && keys > 0) {
keys -= 1
destType = ground
}
if (destType === ground || destType === goal || destType === chest) {
if (destType === chest) {
keys += 1
}
clearTile(player.x, player.y)
current_sprite = up
addSprite(player.x, player.y - 1, current_sprite) // Spawn new player sprite above
addSprite(player.x, player.y, ground) // Replace ground tile where the player moved from
}
})
onInput("a", () => {
let player = getFirst(current_sprite)
let destTile = getTile(player.x - 1, player.y) // Check the tile to the left of the player
// Check if the destination tile is of type 'ground' or 'goal' before moving
let destType = destTile.length > 0 ? destTile[0].type : ''
if (destType === lock && keys > 0) {
keys -= 1
destType = ground
}
if (destType === ground || destType === goal || destType === chest) {
if (destType === chest) {
keys += 1
}
clearTile(player.x, player.y)
current_sprite = current_sprite === left_1 ? left_2 : left_1
addSprite(player.x - 1, player.y, current_sprite) // Spawn new player sprite to the left
addSprite(player.x, player.y, ground) // Replace ground tile where the player moved from
}
})
onInput("d", () => {
let player = getFirst(current_sprite)
let destTile = getTile(player.x + 1, player.y) // Check the tile to the right of the player
// Check if the destination tile is of type 'ground' or 'goal' before moving
let destType = destTile.length > 0 ? destTile[0].type : ''
if (destType === lock && keys > 0) {
keys -= 1
destType = ground
}
if (destType === ground || destType === goal || destType === chest) {
if (destType === chest) {
keys += 1
}
clearTile(player.x, player.y)
current_sprite = current_sprite === right_1 ? right_2 : right_1
addSprite(player.x + 1, player.y, current_sprite) // Spawn new player sprite to the right
addSprite(player.x, player.y, ground) // Replace ground tile where the player moved from
}
})
afterInput(() => {
if (tilesWith(goal, current_sprite).length === 1) {
if (level === levels.length - 1) {
// Check if the current level is the last level
addText("YOU WIN!", { y: 4, color: color`3` })
} else {
level += 1;
setMap(levels[level]); // Change the map to the next level
current_sprite = down
}
}
})