forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWarriors_quest.js
399 lines (365 loc) · 7.63 KB
/
Warriors_quest.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
/*
@author: The-UnknownHacker
@title: The Warrior's Quest
@tags: ['puzzle', 'platformer']
@addedOn: 2024-11-25
*/
// USE W,A,S,D to move and find the right coin
// Only one coin will work and the other ones are fake
// Enjoy
// Define sprite keys using numbers
const player = "1"; // Player represented by 1
const wall = "2"; // Wall represented by 2
const coin = "3"; // Coin represented by 3
const white_block = "4"; // White block represented by 4
const goal = "5"; // Goal represented by 5
const side_wall = "6"; // Side wall represented by 6
const corner_top_right = "7"; // Corner top right
const corner_top_left = "8"; // Corner top left
const corner_bottom_right = "9"; // Corner bottom right
const corner_bottom_left = "w"; // Corner bottom left
const trick_goal = "e";
// Set the legend for the game sprites
setLegend(
[player, bitmap`
HHHH33000033HHHH
HHH0330000330HHH
HH000CCCCCC000HH
H00CCLLLLLLCC00H
000CLLLLLLLLC000
00CLLLLLLLLLLC00
00CLLLLLLLLLLC00
00CLLLL44LLLLC00
00CLLLL44LLLLC00
00CLLLLLLLLLLC00
00CLLLLLLLLLLC00
03CCLLLLLLLLC330
H33CCLLLLLLCC33H
HH333CCCCCC333HH
HH333333333333HH
HHHH33333333HHHH`], // Player sprite (simple square)
[wall, bitmap`
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....`], // Wall sprite
[coin, bitmap`
...0666666660...
...6666666666...
..666666666666..
.66666666666666.
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
0666666666666660
006666666666660.
.0066666666660..
..006666666600..
...0000000000...`], // Coin sprite
[white_block, bitmap`
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
..22222222222222`], // White block sprite
[goal, bitmap`
................
................
................
................
................
................
................
................
................
................
................
................
................
................
................
................`], // Goal sprite
[trick_goal, bitmap`
....06666660....
...6666666666...
..666666666666..
.66666666666666.
6666666666666666
6666666666666666
6666666666666666
6666666006666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
0666666666666660
.06666666666660.
..0666666666600.
...0000000000...`], // Goal sprite
[side_wall, bitmap`
................
................
................
................
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
................
................
................
................`], // Side Wall sprite
[corner_top_right, bitmap`
................
................
................
................
000000000000....
000000000000....
000000000000....
000000000000....
000000000000....
000000000000....
000000000000....
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....`], // Corner Top Right sprite
[corner_top_left, bitmap`
................
................
................
................
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....00000000....
....00000000....
....00000000....
....00000000....
....00000000....`], // Corner Top Left sprite
[corner_bottom_right, bitmap`
....00000000....
....00000000....
....00000000....
....00000000....
000000000000....
00000000000H....
000000000000....
000000000000....
000000000000....
000000000000....
000000000000....
................
................
................
................
................`], // Corner Bottom Right spritesddd
[corner_bottom_left, bitmap`
....00000000....
....00000000....
....00000000....
....00000000....
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
....000000000000
................
................
................
................
................`], // Corner Bottom Left sprawdte
);
// Set the background to the white block
setBackground(white_block);
// Define 5 levels, each with a single coin
const levels = [
map`
8686766666666667
232e2..........2
252.2.8667.....2
2525.52.e2.e...2
25w66695895586.2
25..5555w6669..2
25.5555555555..2
25..555555555512
25..5555555555.2
2566666755867..2
2555e252..2e...2
25555552..w69..2
255552e2.......2
w666666666666669`,
map`
866666666666667
2..2...2...2.32
2..2.2.2.2.2.22
2..2.2.2.252522
2..252525252522
2.5252525252522
21.252525252.22
2..252525252522
255252525252522
2..252525252522
2..252.2.252522
2..2.2.2.2.2.22
2....2...2...22
w66666666666699`,
map`
8666666666666667
21..22.........2
2.2.22....2....2
2.2.22....2....2
2.2.22....2....2
2.2.22....2....2
2.2.22....2....2
2.2.22.3..2....2
2.2.2666662....2
2.2.2...2......2
2.2.2.2.2.2....2
2.2.2.2.2.2....2
2.2...2...2....2
w666666666666669`,
map`
86666666666666667
218667...8667...2
2.2222.2.2222.2.2
2.2222.2.2869.2.2
2.2222.2.22...2.2
2.2222.2.22.862.2
2.2222.2.22.222.2
2.w669.2.22.222.2
2......2.22.222.2
26666669.22.222.2
2........22.222.2
2..86666692.w69.2
2..w6666669.2...2
2...........2.222
26666666666623222
w6666666666666669`,
map`
1..............
.86666666666666
.2.............
.w66666666.2.7.
...........2.2.
86666666666952.
2............9.
2.8666666666664
2.2............
2.2............
2.2............
2.8666666666664
2e23..........e
w6w666666666669`
];
// Initialize current level index
let level = 0;
let canMove = false; // Flag to control movement
// Set player and wall as solid objects, including side wall
setSolids([player, wall, side_wall]);
// Display the current level number at the start for 3 seconds
function displayLevel() {
clearText();
addText(`Level ${level + 1}`, { x: 5, y: 3 });
}
// Set the initial map and display the level for 3 seconds
function startLevel() {
setMap(levels[level]);
displayLevel();
canMove = false; // Prevent movement during display
// Delay for 3 seconds, then allow movement
setTimeout(() => {
clearText(); // Clear level display after 3 seconds
canMove = true; // Enable movement
}, 1000); // Delay for 3 seconds
}
// Initialize the first level
startLevel();
// Set pushables (player can push coins)
setPushables({
[player]: [coin]
});
// Function to switch levels
function goToNextLevel() {
level += 1;
if (level < levels.length) {
startLevel(); // Start the next level
} else {
clearText();
addText("You win!", { y: 4, color: color`7` });
}
}
// Handle player input for movement (only if canMove is true)
onInput("d", () => {
if (canMove) {
const playerSprite = getFirst(player);
playerSprite.x += 1; // Move right
}
});
onInput("a", () => {
if (canMove) {
const playerSprite = getFirst(player);
playerSprite.x -= 1; // Move left
}
});
onInput("w", () => {
if (canMove) {
const playerSprite = getFirst(player);
playerSprite.y -= 1; // Move up
}
});
onInput("s", () => {
if (canMove) {
const playerSprite = getFirst(player);
playerSprite.y += 1; // Move down
}
});
// Check if player has collected the coin after each input
afterInput(() => {
if (canMove) {
const playerSprite = getFirst(player);
const coinSprite = getFirst(coin);
// If player is on the same tile as the coin, switch levels
if (coinSprite && playerSprite.x === coinSprite.x && playerSprite.y === coinSprite.y) {
goToNextLevel();
}
}
});