forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrap hunt.js
528 lines (512 loc) · 10.5 KB
/
trap hunt.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: trap runner
@author: surojit roy
@tags: []
@addedOn: 2024-08-28
*/
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`
0010033333300101
1001333333330000
0000377337731000
0000333003330010
1010330330331000
0000066666600000
0103333333333010
0003333333333000
0033333333333300
0333333333333330
0333333333333330
1033333333333301
0010333333330000
0000333333330100
0000033003300010
1001000010010000` ],
[ up, bitmap`
0000033333300000
0000333333330000
0000333333330000
0000333333330000
0000333333330000
0000066666600000
0003333333333000
0003333333333000
0033333333333300
0333333333333330
0333333333333330
0033333333333300
0000333333330000
0000333333330000
0000033003300000
0000000000000000` ],
[ right_1, bitmap`
0000000000000000
0000033333300000
0000333333330000
0000333333770000
0000333333300000
0000333333030000
0000066666600000
0000333333330000
0000333333330000
0003333333333000
0033333333333300
0033333333333300
0003333333333000
0003333333333000
0003333333333000
0000330003330000` ],
[ left_1, bitmap`
................
.....333333.....
....33333333....
....77333333....
....33333333....
....33333333....
.....666666.....
....33333333....
....33333333....
...3333333333...
..333333333333..
..333333333333..
...3333333333...
...3333333333...
...3333333333...
....333...33....` ],
[ right_2, bitmap`
................
.....333333.....
....33333333....
....33333377....
....33333333....
....33333333....
.....666666.....
....33333333....
....33333333....
...333333333....
..33333333333...
..33333333333...
...3333333333...
...3333333333...
...3333..3333...
....33....33....` ],
[ left_2, bitmap`
................
.....333333.....
....33333333....
....77333333....
....33333333....
....33333333....
.....666666.....
....33333333....
....33333333....
....333333333...
...33333333333..
...33333333333..
...3333333333...
...3333333333...
...3333..3333...
....33....33....` ],
[ v_wall, bitmap`
0000002222000100
0101002222000000
1000012222010000
0001002222001010
0100002222100000
0000002222000010
0000102222010000
0100002222001010
0000002222000000
0000102222010100
0110002222001000
0000002222000001
0010102222100000
0100012222001000
0010002222010000
0000102222000010` ],
[ ground, bitmap`
0100000001000010
0000000100000000
0000100000000100
0000000001000000
0100000000010100
0000000100000000
0000010000000010
0010000000100000
0000000000000010
1010000100010000
0000010000000010
0000000010000000
0010000000010000
0000000000000000
1000100100000010
0000000000010000` ],
[ h_wall, bitmap`
0000001000000100
0010100100010001
1000000000000000
0000100000100100
0001001010000001
0100000000010000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000001000100001
0100100000000100
0000000000010000
0010100100100001
0000000000000000
0100001010010100` ],
[ u_r, bitmap`
1000010000010001
0010000000000100
0000100000010000
0000000000100010
0101000000000000
0000000000001001
0000100000000000
0101000000000000
0000000000000000
1010010000000000
0000000000000100
0000101001001000
0100000000000001
0000001001010100
0010100010000000
1000000100010001` ],
[ u_l, bitmap`
LL1LL10000L1LLLL
LLLLLL0000LLL1LL
L1LL1L0000LLLLLL
LL1LLL0000LL1L1L
LLLLLL0000LLLLLL
1LLL1L00001LLLLL
0000000000LL1LLL
0000000000L1LL1L
0000000000LLLLLL
00000000001LLLLL
LLL1LLL1LLL1LL1L
L1LLLLLLLLLLLLLL
LLLLL1LL1LL1LLLL
LL1LLLLLLLLLL1LL
1LLL1LLLLL1LLLL1
LL1LLL1L1LLLL1LL` ],
[ d_r, bitmap`
0010010000100000
0000000000001001
1000010010000000
0010000000000001
0000010000100010
0100000010001000
0001000000000000
0000000000000000
1000100000000000
0000000000000000
0010000000010100
0000100000000001
1000000000100100
0000000000000000
0001000000010001
1000000000000100` ],
[ d_l, bitmap`
1000000000010010
0010100101000000
0000000000010000
0010000010000010
0000001000100000
1000100010000000
0000000000000100
0000000000010000
0000000000000001
0000000000001000
0000010000010010
1001000000000000
0000000000000010
0100010000010000
0010000000000101
0000010000010000` ],
[ c_r, bitmap`
1000100000001001
0000000000000000
0100100000100100
0000000000000010
0100010000000000
0000000000010100
1000100000000000
0000000000000000
0010000000000000
0000010000000000
1000000000001000
0001000000000001
0100000000001000
0000000000100010
0010010000000000
1001000000010100` ],
[ c_l, bitmap`
0100010000010000
0001000000000000
0000000000001000
1001000000000010
0000000000010000
0010010000000000
0000000000000100
0000000000000000
0000000000100000
0000000000000010
0100000000001000
0010100000000000
0100000000101010
0000010000000000
0101000000001000
001L100000010010` ],
[ c_d, bitmap`
1001000010010000
0000001000000101
0000100000000000
0100000010010000
0000100000000101
1000000100010000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000100000100010
0101000000000100
0000000000010000
0010100000000010
0000000000100000
0010000000001001` ],
[ c_u, bitmap`
1000010000010000
0101000000000001
0000000000001000
1000000000000001
0001000000010000
0100010000000100
0000000000000000
0000000000000000
0000000000000000
0000000000000000
1000010000000010
0000000001000000
0101000000010100
0000001010000000
0100000000100000
0001001000010010` ],
[ goal, bitmap`
551555551HHHH1HH
55555000000HHHHH
155108888880H1H1
55008833338800HH
506083333338060H
506088333388060H
5500888338880071
5144088888807177
1441L08FF8017777
4444108FF8077777
4414408FF8071771
4444408FF8077777
4444088888807777
4140000000000717
4444444444417777
1441444144417771` ],
[ chest, bitmap`
000LL1LLL1LL1000
0FF0000000000FF0
0703333333333070
0703333333333070
0703333333333070
0703333333333070
0703330000333070
0000007777000000
0777777007777770
0000770000770000
0703077007703070
0703307777033070
0703330000333070
0703333333333070
0F033333333330F0
0000000000000000` ],
[ lock, bitmap`
101L555555550001
0005888888885010
0015855555585000
1005850000585100
0055555555555501
058888888888885L
5F888888888888F5
5F888888888888F5
5F888888888888F5
5F888877778888F5
5F888877778888F5
5F888887788888F5
5F888888888888F5
5F888888888888F5
L5FFFFFFFFFFFF51
1L555555555555LL` ]
)
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
}
}
})