-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLittleSpringGame.js
444 lines (422 loc) · 7.89 KB
/
LittleSpringGame.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
/*
First time? Check out the tutorial game:
https://sprig.hackclub.com/gallery/getting_started
@title: Little Spring Game
@author: Jonas Heilig
@tags: []
@addedOn: 2024-00-00
*/
const player = "p"
const box = "k"
const catbox = "t"
const background = "b"
const hous = "h"
const cat = "c"
const cathous = "z"
const wall = "w"
const destroyablething = "d"
const transparent = "u"
const backgroundTune = tune`
172.41379310344828: D4~172.41379310344828,
172.41379310344828: D4~172.41379310344828,
172.41379310344828: D4~172.41379310344828,
172.41379310344828: D4~172.41379310344828,
172.41379310344828: E4~172.41379310344828,
172.41379310344828: E4~172.41379310344828,
172.41379310344828: E4~172.41379310344828,
172.41379310344828: E4~172.41379310344828,
172.41379310344828: F4~172.41379310344828,
172.41379310344828: F4~172.41379310344828,
172.41379310344828: F4~172.41379310344828,
172.41379310344828: F4~172.41379310344828,
172.41379310344828: G4~172.41379310344828,
172.41379310344828: G4~172.41379310344828,
172.41379310344828: G4~172.41379310344828,
172.41379310344828: G4~172.41379310344828,
172.41379310344828: D4~172.41379310344828,
172.41379310344828: D4~172.41379310344828,
172.41379310344828: D4~172.41379310344828,
172.41379310344828: D4~172.41379310344828,
172.41379310344828: E4~172.41379310344828,
172.41379310344828: E4~172.41379310344828,
172.41379310344828: E4~172.41379310344828,
172.41379310344828: E4~172.41379310344828,
172.41379310344828: F4~172.41379310344828,
172.41379310344828: F4~172.41379310344828,
172.41379310344828: F4~172.41379310344828,
172.41379310344828: F4~172.41379310344828,
172.41379310344828: G4~172.41379310344828,
172.41379310344828: G4~172.41379310344828,
172.41379310344828: G4~172.41379310344828,
172.41379310344828: G4~172.41379310344828`
playTune(backgroundTune, Infinity)
setLegend(
[player, bitmap`
................
................
................
................
................
................
......44444.....
......45454.....
......44444.....
......45554.....
......44444.....
................
................
................
................
................`],
[box, bitmap`
................
................
..CCCCCCCCCCCC..
..CCCFCCCCFCCC..
..CCCFCCCCFCCC..
..CFFFFFFFFFFC..
..CCCFCCCCFCCC..
..CCCFCCCCFCCC..
..CCCFCCCCFCCC..
..CCCFCCCCFCCC..
..CFFFFFFFFFFC..
..CCCFCCCCFCCC..
..CCCFCCCCFCCC..
..CCCCCCCCCCCC..
................
................`],
[catbox, bitmap`
................
................
..333333333333..
..333733337333..
..333733337333..
..377777777773..
..333733337333..
..333733337333..
..333733337333..
..333733337333..
..377777777773..
..333733337333..
..333733337333..
..333333333333..
................
................`],
[background, bitmap`
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD`],
[hous, bitmap`
7777777777777777
7777CCCCCCCC7777
777CCCCCCCCCC777
77CCCCCCCCCCCC77
7CCCCC2222CCCCC7
CCCCCCCCCCCCCCCC
C77CC66CC66CC77C
777CC66CC66CC777
777CCCCCCCCCC777
777CCC6666CCC777
777CCC6666CCC777
777CCCCCCCCCC777
777CCCCCCCCCC777
777C6C99C666C777
777CCC99C666C777
444CCC99CCCCC444`],
[cat, bitmap`
................
................
................
................
................
................
..........00000.
.........0002200
........00000200
.....0000000000.
...00000000000..
...0000000000...
..00000000000...
..000000000000..
..0000....0000..
..000.....000...`],
[cathous, bitmap`
1111111111111111
1111CCCCCCCC1111
111CCCCCCCCCC111
11CCCCCCCCCCCC11
1CCCCC2222CCCCC1
CCCCCCCCCCCCCCCC
C11CC66CC66CC11C
111CC66CC66CC111
111CCCCCCCCCC111
111CCC6666CCC111
111CCC6666CCC111
111CCCCCCCCCC111
111CCCCCCCCCC111
111C6C99C666C111
111CCC99C666C111
000CCC99CCCCC000`],
[wall, bitmap`
1111111111111111
1111111111111111
11LLLLLLLLLLLL11
11LLLLLLLLLLLL11
11LLLLLLLLLLLL11
11LLLLLLLLLLLL11
11LLLLLLLLLLLL11
11LLLLLLLLLLLL11
11LLLLLLLLLLLL11
11LLLLLLLLLLLL11
11LLLLLLLLLLLL11
11LLLLLLLLLLLL11
11LLLLLLLLLLLL11
11LLLLLLLLLLLL11
1111111111111111
1111111111111111`],
[transparent, bitmap`
................
................
................
................
................
................
................
................
................
................
................
................
................
................
................
1...............`],
[destroyablething, bitmap`
L1LL1111111L1LL1
L1111LL1LLLL11L1
LLL1L11LL11LLLLL
1LLLLLL1LL1LLL1L
1L11LLLLL1LLLL11
1LLLL1LLL1L1LL11
LLLLLLLL11L1LL11
L1L11111LLLLL11L
L1LL11LLLLL11L1L
L1L11L1L1LL11L11
L1L1LL1LLLL1LL1L
L11LL1LLLLL1LL11
L11LL11L1LL11LLL
L1LL1L1LL1LLLLLL
1LL11LL111L1L1LL
11LLL1LLLLLL11L1`],
)
setSolids([player, wall, box, catbox, cat, transparent])
setBackground(background)
let level = 0
let text_level = 1
let playable_levels = 14
let destroyabelthinksperlevel = 5
let thinksdestoy = 0
const levels = [
map`
p.w.......
..w.......
d.wwwwwww.
.d.d.k..ww
wwwwww..dw
.ww..www.w
.w........
.wh....d..`,
map`
p.w.......
..ww......
d.w.wwww..
..w..k..w.
..wkww.www
..d.wwd.dw
wwwwww.dhw
.....wwwww`,
map`
wwwwwwwww.
....kd..w.
w.wwwwwdw.
w.w.w.w.w.
wdw.w.dk.w
w.w.wkwww.
whw.w..d.k
.w...wwwwp`,
map`
...d......
w.w.wwwww.
w.w.......
w.wkwwwwww
wdw.w...d.
w.wdw.www.
w.w.w.w.w.
whw..dw.wp`,
map`
wwwwwwww.w
w.d.k.d..w
ww.wwwwwkw
.wkwpd...w
.w.wwwwwww
.wd..k..d.
.w.wwwww.w
.www...whw`,
map`
wwwwwww.ww
wwhw.d....
w..kkwwkw.
wwww.w..wk
.w.ww..wd.
dw..wk.w..
kwwww.ww..
pk...d.w.d`,
map`
wwwww.wdw.
w..d..w...
wd..w.w.w.
ww.wwkw.wk
wwkww.wdw.
ww.ww.w.w.
wh.ww.w.w.
ww.wwd..wp`,
map`
wwwwwwwww
wd.....dw
w....k..w
w..dkpk.w
w....k..w
w.......w
wh.d..d.w
wwwwwwwww`,
map`
....w.wwww
....wdkd.w
wwwww.w.ww
p.d.wkw..w
www.w.wwdw
..w.kd.w.w
..wwwwwwhw
.......www`,
map`
wwwwwww.w.
w.k.d...w.
ww.wwwwkw.
.wkwwwwdww
.w.d.w.kpw
.w.w.wwwww
..ww.d.d.h
..wwwwwwww`,
map`
wwwwwwwwww
w........w
w........w
w......c.w
ww.......w
.wtwww...w
.w..hw..pw
.w.wwwwwww`,
map`
p.k.....w.
wwwwww.ww.
.....w.ww.
.....wc.w.
.wwwww..w.
.w.t....w.
.ww.wwwww.
.ww..hw...`,
map`
wwwwwwwwww
w........w
w.wwwwww.w
w.wh...w.w
w.wwww.w.w
w.wwww.w.w
w......wpw
wwwwwwwwww`,
map`
wwwwwwwwww
w.......w.
w..www.ww.
w.w..tc...
w..www.ww.
w.....u.w.
wwwwwww.wk
........wp`,
map`
..........
...wwwww..
...w...w..
...w.p.w..
...w...w..
...wwwww..
..........
..........`,
]
setMap(levels[level])
setPushables({
[player]: [box, cat],
[cat]: [catbox]
})
onInput("s", () => {
getFirst(player).y += 1
})
onInput("w", () => {
getFirst(player).y -= 1
})
onInput("a", () => {
getFirst(player).x -= 1
})
onInput("d", () => {
getFirst(player).x += 1
})
onInput("j", () => {
setMap(levels[level])
thinksdestoy = 0
})
onInput("k", () => {
const playerPosition = getFirst(player);
const playerX = playerPosition.x;
const playerY = playerPosition.y;
const destroyableThingsAtPlayerPosition = getTile(playerX, playerY).filter(tile => tile.type === destroyablething);
if (destroyableThingsAtPlayerPosition.length > 0) {
console.log("Destroyable object found and will be removed.");
const destroyableObject = destroyableThingsAtPlayerPosition[0];
destroyableObject.remove();
console.log("Destroyable object was successfully removed.");
thinksdestoy += 1;
} else {
console.log("No destroyable object found.");
}
});
addText("Press J to rest", { x: 2, y: 7, color: color`9` })
addText("if you are stuck", { x: 2, y: 9, color: color`9` })
afterInput(() => {
clearText();
if (thinksdestoy == destroyabelthinksperlevel){
if (tilesWith(player, hous).length >= 1) {
addText("Level " + text_level + ", compleated", { x: 1, y: 7, color: color`9` })
level = level + 1
text_level = text_level + 1
thinksdestoy = 0
setMap(levels[level])
}
}
if (level >= playable_levels) {
addText("You won!", { x: 7, y: 7, color: color`9` })
addText("Game is Finish!", { x: 2, y: 9, color: color`9` })
}
})