forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLava_and_Water.js
309 lines (272 loc) · 5.29 KB
/
Lava_and_Water.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
/*
@title: Lava and Water
@author: Akeell
@tags: ['puzzle','multiplayer','retro']
@addedOn: 2022-10-15
*/
/*
Instructions:
This game is a two player game but if you want, you can play it yourself.
Get both player to the teleporters and finish all the levels
before the time ends.
Be careful and don't move the blocks into the teleporters otherwise
they cannot be used again and you would have to restart the entire game.
Controls:
Red player (player 1):
W = up
S = down
A = left
D = right
Blue player (player 2)
I = up
K = down
J = left
L = right
*/
const player1 = "p";
const player2 = "q";
const redteleport = "r";
const blueteleport = "b";
const wall = "w";
const redlocker = "l";
const bluelocker = "I";
setLegend(
[ player1, bitmap`
................
................
................
....3333333.....
...3.......3....
...3.0..0..3....
...3.......3....
...3.......3....
...333333333....
.......3........
.......3..3.....
....3333333.....
....3..3........
.......3........
......3.3.......
.....3...3......`],
[ player2, bitmap`
................
................
................
....5555555.....
...5.......5....
...5.0..0..5....
...5.......5....
...5.......5....
...555555555....
.......5........
.......5..5.....
....5555555.....
....5..5........
.......5........
......5.5.......
.....5...5......`],
[ redteleport, bitmap`
3333333333333333
3933333333333933
3333339333333333
3393333333933333
3333333393333333
3333393333393339
3333333333333333
3933339333333333
3333933333333933
3333333339333333
3333333333339333
3393333333333333
3333333933333333
3933333333333339
3333393333393333
3333333933333333`],
[ blueteleport, bitmap`
5555555555755555
5575557555555555
5555555555555555
7555555555555555
5555575555555755
5555555557555555
5575555555555555
5555555555555555
5555555755557575
7555755555555555
5555555555555555
5555555555755555
5555555555555557
5555755575555755
5755555555555555
5555555555555555`],
[ wall, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
[ redlocker, bitmap`
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777`],
[ bluelocker, bitmap`
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999
9999999999999999`],
);
setSolids([wall, redlocker, bluelocker, player1, player2]);
let level = 0;
const levels = [
map`
p....r
wwwww.
......
wwwww.
b....q`,
map`
p.....q
www.www
..w.w..
..w.w..
..w.w..
b.....r`,
map`
p.....r
...I...
..wqw..
ww.w.w.
.......
...b...`,
map`
....pq.....
wIwwwwwwwlw
...........
...........
wlwwwwwwwIw
...........
....rb.....`,
map`
p.l..I......
..l..I.....w
..l..I....lr
..l.qI.....w
..l..I......
..l..I.....w
..l..I....Ib
..l..I.....w
..l..I......`,
map`
...w...........w...
.w.w.w.wwwww.w.w.w.
.w.w.w.wr.bw.w.w.w.
.w.w.w.w.w.w.w.w.w.
.w.w.wI.l.I.lw.w.w.
.w.w.w.......w.w.w.
qw...w.......w...wp`,
];
const currentLevel = levels[level];
setMap(currentLevel);
setPushables({
[ player1 ]: [bluelocker],
[ player2 ]: [redlocker],
});
//player1 - movement
onInput("w", () => {
getFirst(player1).y += -1
});
onInput("s", () => {
getFirst(player1).y += 1
});
onInput("a", () => {
getFirst(player1).x += -1
});
onInput("d", () => {
getFirst(player1).x += 1
});
// End - player1 movement
//player2 movement
onInput("i", () => {
getFirst(player2).y += -1
});
onInput("k", () => {
getFirst(player2).y += 1
});
onInput("j", () => {
getFirst(player2).x += -1
});
onInput("l", () => {
getFirst(player2).x += 1
});
//End - player2 movement
var tempototal = 100;
var tempodescendo = setInterval(function(){
tempototal--;
clearText();
addText(""+tempototal, { y: 1 , color: color`3` });
if(tempototal <= 0){
clearInterval(tempodescendo);
clearTile(getFirst(player1).x,getFirst(player1).y);
clearTile(getFirst(player2).x,getFirst(player2).y);
//clearText() here before
addText("Try Again!", { y: 1 , color: color`3` });
}
},1000);
//teleport players
afterInput(() => {
const targetNumber = tilesWith(redteleport).length;
const targetNumber2 = tilesWith(blueteleport).length;
const targetNumberboth = targetNumber + targetNumber2;
const numberCovered = tilesWith(redteleport, player1).length;
const numberCovered2 = tilesWith(blueteleport, player2).length;
const bothCovered = numberCovered + numberCovered2;
if (bothCovered === targetNumberboth) {
// increase the current level number
level = level + 1;
const currentLevel = levels[level];
// make sure the level exists and if so set the map
if (currentLevel !== undefined) {
setMap(currentLevel);
} else {
addText("you win!", { y: 4, color: color`3` });
clearInterval(tempodescendo);
}
}
});
//end teleport players