forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCatch_the_star.js
327 lines (308 loc) · 6.63 KB
/
Catch_the_star.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
/*
@title: Catch the star
@author: Saumya
@tags: []
@addedOn: 2023-12-20
*/
const reindeer = "p";
const grass = "g";
const star = "h";
const bg = "b";
const gift ="r"; //the og gift
const red ="k"; //the red gift
const blue ="l"; //the blue gift
const purple ="u"; //the purple gift
setLegend(
[ reindeer, bitmap`
................
.......0........
.......00.......
........0CC.....
........CCCC....
.......CCC0CC3..
........C8CCC...
........CCCC....
........333.....
.....CCCCCC6....
....CCCCCCC.....
...CCCCCCCC.....
....CC...CC.....
....CC...CC.....
....00...00.....
................`],
[ grass, bitmap`
DDDDDDDDDD44444D
DD4444DDD4DDDDD4
D4DDDD4D4DDDDDDD
D4DDDDD4444DDDDD
D4DDDDD4DDD44DDD
4DDDDDD4DDDDD4DD
DDDDDDD4DDDDD4D4
DDD44D4DDDDDDD4D
DDD444DDDDD44DDD
DD4DDD4DDD4DD4DD
D4DDDDD4DD4DDD44
D4DDDDDD44DDDDDD
4DDDDDDDD4DD444D
DDDDDD44DDD4DDD4
44DDD4DD444DDDDD
DD4D4DDDDDDDDDDD`],
[ star, bitmap`
................
................
................
.......99.......
......9669......
......9669......
...9996666999...
..966666666669..
..966606606669..
...9660660669...
....96666669....
....96666669....
....96699669....
.....99..99.....
................
................`],
[ gift, bitmap`
................
................
................
................
.....333.333....
.....333.333....
...66663336666..
...66663336666..
...66663336666..
...66663336666..
...66663336666..
...66663336666..
...66663336666..
...66663336666..
...66663336666..
................`],
[ bg, bitmap`
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222`],
[ red, bitmap`
................
................
....666..666....
....666..666....
..333336633333..
..333336633333..
..333336633333..
..333336633333..
..333336633333..
..333336633333..
..333336633333..
..333336633333..
..333336633333..
..333336633333..
................
................`],
[ blue, bitmap`
................
................
....555..555....
....555..555....
..777775577777..
..777775577777..
..777775577777..
..777775577777..
..777775577777..
..777775577777..
..777775577777..
..777775577777..
..777775577777..
..777775577777..
................
................`],
[ purple, bitmap`
................
................
....HHH..HHH....
....HHH..HHH....
..99999HH99999..
..99999HH99999..
..99999HH99999..
..99999HH99999..
..99999HH99999..
..99999HH99999..
..99999HH99999..
..99999HH99999..
..99999HH99999..
..99999HH99999..
................
................`],
);
setSolids([reindeer, grass])
setBackground(bg);
let level = 0;
const levelDimensions = [8, 8, 8, 8, 8];
const levels = [
map`
gggggggg
gggggggg
gggggggg
gggggggg
gggggghg
ggggggbg
pbbbbbbg
gggggggg`,
map`
pbbbbbbr
gggggggb
ggbbbbgb
ggbbbbgb
ggbbbbgb
gggggggb
gghbbbbr
gggggggg`,
map`
pbbbbbbb
gggggggb
rbbbbrgb
bbbbgbgb
bbgbgbgb
bghbbbgb
bggggggb
bbbbbbbr`,
map`
pbbbbbbb
bbgggggb
bbrbbbgb
bbbbbbbb
bgbbbbbr
bbgbbbbg
gbbbbbbh
bggbbrbb`,
map`
pbbbbbbb
gbbbbbbb
rbbbbrgb
bbgbbbbb
bbbhgbbb
bgrbbrbb
bbbbbgbb
bbbbbbbb`,
];
const tunes = {
start: tune`
113.20754716981132,
113.20754716981132: c4^113.20754716981132,
113.20754716981132: e4^113.20754716981132,
113.20754716981132: g4^113.20754716981132,
113.20754716981132: c5^113.20754716981132,
3056.603773584906`,
reset: tune`
113.20754716981132,
113.20754716981132: c5^113.20754716981132,
113.20754716981132: c5^113.20754716981132,
113.20754716981132,
113.20754716981132: c4^113.20754716981132,
113.20754716981132: c4^113.20754716981132,
2943.396226415094`,
win: tune`
113.20754716981132,
113.20754716981132: g4^113.20754716981132 + b4^113.20754716981132 + d5^113.20754716981132 + g5^113.20754716981132,
113.20754716981132: g4^113.20754716981132 + b4^113.20754716981132 + d5^113.20754716981132 + g5^113.20754716981132,
339.62264150943395,
113.20754716981132: c4^113.20754716981132 + e4^113.20754716981132 + g4^113.20754716981132 + c5^113.20754716981132,
113.20754716981132: c4^113.20754716981132 + e4^113.20754716981132 + g4^113.20754716981132 + c5^113.20754716981132,
113.20754716981132: c4^113.20754716981132 + e4^113.20754716981132 + g4^113.20754716981132 + c5^113.20754716981132,
113.20754716981132: c4^113.20754716981132 + e4^113.20754716981132 + g4^113.20754716981132 + c5^113.20754716981132,
2490.566037735849`,
gift: tune`
113.20754716981132,
113.20754716981132: c5-113.20754716981132,
113.20754716981132: g4-113.20754716981132,
3283.0188679245284`,
};
function goTo(x, y) {
const cur = getTile(x, y);
if (cur.length && cur[0].type == grass) return false;
if (cur.length && cur[0].type == gift) {
cur[0].remove();
playTune(tunes.gift);
}
getFirst(reindeer).x = x;
getFirst(reindeer).y = y;
return true;
}
onInput("s", () => {
while (getFirst(reindeer).y + 1 < levelDimensions[level]) {
if (!goTo(getFirst(reindeer).x, getFirst(reindeer).y + 1)) break;
}
});
onInput("w", () => {
while (getFirst(reindeer).y - 1 >= 0) {
if (!goTo(getFirst(reindeer).x, getFirst(reindeer).y - 1)) break;
}
});
onInput("a", () => {
while (getFirst(reindeer).x - 1 >= 0) {
if (!goTo(getFirst(reindeer).x - 1, getFirst(reindeer).y)) break;
}
});
onInput("d", () => {
while (getFirst(reindeer).x + 1 < levelDimensions[level]) {
if (!goTo(getFirst(reindeer).x + 1, getFirst(reindeer).y)) break;
}
});
onInput("j", () => {
clearText();
setMap(levels[level]);
playTune(tunes.reset);
});
setMap(levels[level]);
addText("MOVE REINDEER!", { y: 1, color: color`0` });
addText("a=left b=right", { y: 3, color: color`0` });
addText("w=up s=down", { y: 5, color: color`0` });
playTune(tunes.start);
afterInput(() => {
clearText();
const numberCovered = tilesWith(reindeer, star).length;
if (numberCovered === 1) {
const giftsLeft = tilesWith(gift).length;
if (giftsLeft !== 0) {
addText("There are", { y: 6, color: color`0` });
addText("still gifts!", { y: 7, color: color`0` });
return;
}
level = level + 1;
const currentLevel = levels[level];
if (currentLevel !== undefined) {
setMap(currentLevel);
playTune(tunes.start);
} else {
addText("YOU WIN!", { y: 4, color: color`0` });
addText("TO RESET", { y: 6, color: color`0` });
addText("PRESS J", { y: 7, color: color`0` });
playTune(tunes.win);
}
}
if (level == 0) {
addText("REINDEER WALKS", { y: 5, color: color`0` });
addText("UNTILL IT", { y: 6, color: color`0` });
addText("REACHES GRASS!", { y: 7, color: color`0` });
}
if (level == 1) {
addText("TO RESET", { y: 6, color: color`0` });
addText("PRESS J", { y: 7, color: color`0` });
}
});