Skip to content

Commit 9cf4ede

Browse files
SokobanLike (#1995)
* sokobonlike a short sokobon game with optional portals * fixed final error sokobon!!!!!!! * Add files via upload * Update metadata for sokobanlike.js * added a couple new levels added 1 or 2 new levels to further utilise portals and creative thinking * Update sokobanlike.js --------- Co-authored-by: Marios Mitsios <[email protected]>
1 parent 0c5f34a commit 9cf4ede

File tree

1 file changed

+379
-0
lines changed

1 file changed

+379
-0
lines changed

games/sokobanlike.js

+379
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,379 @@
1+
/*
2+
First time? Check out the tutorial game:
3+
https://sprig.hackclub.com/gallery/getting_started
4+
5+
@title: sokobanlike
6+
@author: Neptune1190
7+
@tags: ["puzzle"]
8+
@addedOn: 2024-07-18
9+
*/
10+
11+
const player = "p"
12+
const floor = "f"
13+
const box = "b"
14+
const goal = "g"
15+
const redbox = "r"
16+
const redgoal = "c"
17+
const numgoal = tilesWith(goal).length;
18+
const pathsfinished = tilesWith(goal, box).length;
19+
const blueportal = "l"
20+
const orangeportal = "k"
21+
let canportal = false
22+
setLegend(
23+
[ player, bitmap`
24+
0202020202020202
25+
2020202020202020
26+
0202020202020202
27+
2020202020202020
28+
0202020202020202
29+
2020202020202020
30+
0202020202020202
31+
2020202020202020
32+
0202020202020202
33+
2020202020202020
34+
0202020202020202
35+
2020202020202020
36+
0202020202020202
37+
2020202020202020
38+
0202020202020202
39+
2020202020202020` ] ,
40+
[ floor, bitmap`
41+
1111111111111111
42+
1111111111111111
43+
1111111111111111
44+
1111111111111111
45+
1111111111111111
46+
1111111111111111
47+
1111111111111111
48+
1111111111111111
49+
1111111111111111
50+
1111111111111111
51+
1111111111111111
52+
1111111111111111
53+
1111111111111111
54+
1111111111111111
55+
1111111111111111
56+
1111111111111111` ] ,
57+
[ box, bitmap`
58+
CCCCCCCCCCCCCCCC
59+
CCCCCCCCCCCCCCCC
60+
CCCCCCCCCCCCCCCC
61+
CCCCCCCCCCCCCCCC
62+
CCCCCCCCCCCCCCCC
63+
CCCCCCCCCCCCCCCC
64+
CCCCCCCCCCCCCCCC
65+
CCCCCCCCCCCCCCCC
66+
CCCCCCCCCCCCCCCC
67+
CCCCCCCCCCCCCCCC
68+
CCCCCCCCCCCCCCCC
69+
CCCCCCCCCCCCCCCC
70+
CCCCCCCCCCCCCCCC
71+
CCCCCCCCCCCCCCCC
72+
CCCCCCCCCCCCCCCC
73+
CCCCCCCCCCCCCCCC` ] ,
74+
[ goal, bitmap`
75+
9999999999999999
76+
9999999999999999
77+
9999999999999999
78+
9999999699999999
79+
9999966669999999
80+
9999666666999999
81+
9966666666699999
82+
9666666666669999
83+
9966666666666999
84+
9966666666666999
85+
9996666966666999
86+
9996669996669999
87+
9999699999969999
88+
9999999999999999
89+
9999999999999999
90+
9999999999999999` ],
91+
[ redgoal, bitmap`
92+
5555555555555555
93+
5555555555555555
94+
5555555555555555
95+
5555555355555555
96+
5555533335555555
97+
5555333333555555
98+
5533333333355555
99+
5333333333335555
100+
5533333333333555
101+
5533333333333555
102+
5553333533333555
103+
5553335553335555
104+
5555355555535555
105+
5555555555555555
106+
5555555555555555
107+
5555555555555555` ],
108+
[ redbox, bitmap`
109+
3333333333333333
110+
3333333333333333
111+
3333333333333333
112+
3333333333333333
113+
3333333333333333
114+
3333333333333333
115+
3333333333333333
116+
3333333333333333
117+
3333333333333333
118+
3333333333333333
119+
3333333333333333
120+
3333333333333333
121+
3333333333333333
122+
3333333333333333
123+
3333333333333333
124+
3333333333333333` ],
125+
[ blueportal, bitmap`
126+
................
127+
...5555555555...
128+
..555555555555..
129+
..555555555555..
130+
..555555555555..
131+
..555555555555..
132+
..555555555555..
133+
..555555555555..
134+
..555555555555..
135+
..555555555555..
136+
..555555555555..
137+
..555555555555..
138+
..555555555555..
139+
..555555555555..
140+
...5555555555...
141+
................` ],
142+
[ orangeportal, bitmap`
143+
................
144+
...9999999999...
145+
..999999999999..
146+
..999999999999..
147+
..999999999999..
148+
..999999999999..
149+
..999999999999..
150+
..999999999999..
151+
..999999999999..
152+
..999999999999..
153+
..999999999999..
154+
..999999999999..
155+
..999999999999..
156+
..999999999999..
157+
...9999999999...
158+
................` ]
159+
160+
)
161+
162+
setSolids([ player, floor, box, redbox ])
163+
164+
let level = 0
165+
const levels = [
166+
map`
167+
fffff
168+
fg..f
169+
f.b.f
170+
f..pf
171+
fffff`,
172+
map`
173+
ffffff
174+
fgb..f
175+
f....f
176+
f.p..f
177+
f..bgf
178+
ffffff`,
179+
map`
180+
ffffffff
181+
fg.....f
182+
fffff..f
183+
f...b..f
184+
f.bp...f
185+
f..fffff
186+
f.....gf
187+
ffffffff`,
188+
map`
189+
ffffffffff
190+
f........f
191+
f.b......f
192+
f......f.f
193+
f.b..p.f.f
194+
f......f.f
195+
f.b....fgf
196+
f......fgf
197+
f......fgf
198+
ffffffffff`,
199+
map`
200+
ffffffffffff
201+
f.......f..f
202+
f.b.....f..f
203+
f....ff.f..f
204+
f....gfgf..f
205+
f.....pf...f
206+
f....fgf...f
207+
f..........f
208+
f........b.f
209+
f....b.....f
210+
f..........f
211+
ffffffffffff`,
212+
map`
213+
fffffffff
214+
f.......f
215+
f.......f
216+
f.......f
217+
f..bgb..f
218+
f.fgpgfff
219+
f..bgb..f
220+
f...f...f
221+
fffffffff`,
222+
map`
223+
fffffff
224+
f..g..f
225+
f.....f
226+
f.rp.cf
227+
f..b..f
228+
f.....f
229+
fffffff`,
230+
map`
231+
ffffffffffffff
232+
ffffffffffffff
233+
ffffffffffffff
234+
fffc......gfff
235+
fff.b....r.fff
236+
fff........fff
237+
fff....p...fff
238+
fff........fff
239+
fff........fff
240+
fff.r....b.fff
241+
fffg......cfff
242+
ffffffffffffff`,
243+
map`
244+
ffffffffffffff
245+
f...f........f
246+
f...f......b.f
247+
f.p.cg..b....f
248+
f...f........f
249+
f...f........f
250+
ffgfffffff.fff
251+
ff...r.....fff
252+
ff.........fff
253+
ffffffffffffff`,
254+
map`
255+
fffffffffffffffff
256+
fffff.fffffffffff
257+
fffff..........ff
258+
fffff.f........ff
259+
fffff.f......f.ff
260+
fffff.f.....br.ff
261+
f...f.ffffff.f.ff
262+
f.p.f..fffff...ff
263+
f...g..ffffffffff
264+
f...fffffffffffff
265+
f...............f
266+
f.............c.f
267+
f...............f
268+
fffffffffffffffff`,
269+
map`
270+
fffffffffffffffff
271+
f...............f
272+
f.fffffffffff.b.f
273+
f.ff........f...f
274+
f.ff.fffff.b.f..f
275+
f.ff.f.fff...fr.f
276+
f.ff.f....f.f...f
277+
f.ff.f.f..f.f...f
278+
f.ff.f.f.ffgf...f
279+
f.ff.f.f.ffff...f
280+
f.ff.f.f.fff....f
281+
f...p.cf.......gf
282+
ffff.fff.ffffffff
283+
ffff.ffff......gf
284+
ffff.fffffb.fffff
285+
ffff........fffff
286+
ffffffffff.ffffff
287+
fffffffffffffffff`,
288+
map`
289+
fffffff
290+
fffffff
291+
fffffff
292+
fffpfff
293+
fffffff
294+
fffffff
295+
fffffff`,
296+
]
297+
setMap(levels[level])
298+
299+
setPushables({
300+
[ player ]: [ box, redbox]
301+
})
302+
303+
if (level === 0) {
304+
addText("Move using the \n w a s d keys", {
305+
x: 3,
306+
y: 1})
307+
}
308+
if (level === 7) {
309+
addText("You can now shoot \nportals,using the \nl and k keys", {
310+
x: 2,
311+
y: 1})
312+
}
313+
314+
if (level === 11) {
315+
addText("You have won!", {
316+
x: 2,
317+
y: 1})
318+
}
319+
onInput("w", () => {
320+
getFirst(player).y -= 1
321+
})
322+
onInput("a", () => {
323+
getFirst(player).x -= 1
324+
})
325+
onInput("d", () => {
326+
getFirst(player).x += 1
327+
})
328+
onInput("s", () => {
329+
getFirst(player).y += 1
330+
})
331+
332+
onInput("l", () => {
333+
const existingBluePortal = getFirst(blueportal);
334+
if (existingBluePortal) {
335+
existingBluePortal.remove();
336+
}
337+
if (canportal == true) {
338+
addSprite(getFirst(player).x, getFirst(player).y, blueportal)
339+
}})
340+
341+
onInput("k", () => {
342+
const existingOrangePortal = getFirst(orangeportal);
343+
if (existingOrangePortal) {
344+
existingOrangePortal.remove();
345+
}
346+
if (canportal == true) {
347+
addSprite(getFirst(player).x, getFirst(player).y, orangeportal)
348+
}})
349+
350+
afterInput(() => {
351+
const numgoal = tilesWith(goal).length;
352+
const pathsfinished = tilesWith(goal, box).length;
353+
const redgoals = tilesWith(redgoal).length;
354+
const redfinish = tilesWith(redgoal, redbox).length
355+
const playerblue = tilesWith(blueportal, player).length
356+
const playerorange = tilesWith(orangeportal, player).length
357+
const existingOrangePortal = getFirst(orangeportal);
358+
const existingBluePortal = getFirst(blueportal);
359+
if (level >= 7) {
360+
canportal = true
361+
}
362+
if (pathsfinished === numgoal && redfinish === redgoals && level < 11 ) {
363+
clearText()
364+
level = level + 1
365+
setMap(levels[level])
366+
}
367+
if (playerblue === 1 && existingOrangePortal) {
368+
setSolids([ floor, box, redbox ])
369+
getFirst(player).x = getFirst(orangeportal).x
370+
getFirst(player).y = getFirst(orangeportal).y
371+
setSolids([ player, floor, box, redbox ])
372+
}
373+
if (playerorange === 1 && existingBluePortal ) {
374+
setSolids([ floor, box, redbox ])
375+
getFirst(player).x = getFirst(blueportal).x
376+
getFirst(player).y = getFirst(blueportal).y
377+
setSolids([ player, floor, box, redbox ])
378+
}
379+
})

0 commit comments

Comments
 (0)