forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiplayer_soccer.js
335 lines (297 loc) · 6.89 KB
/
multiplayer_soccer.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
/*
@title: multiplayer_soccer
@author: shannon yeow
*/
const player = "p";
const player1 = "1";
const box = "b";
const wall = "w";
const wallthrough = "2";
const goal = "g";
setLegend(
[ player, bitmap`
................
....11111111....
...1111111111...
....88888888....
....88888888....
....80888808....
....88800888....
....88888888....
......8888......
...8333333338...
.....333333.....
.....333333.....
.....555555.....
.....555555.....
.....8....8.....
................`],
[ player1, bitmap`
................
....LLLLLLLL....
...LLLLLLLLLL...
....44444444....
....44444444....
....40444404....
....44400444....
....44444444....
......4444......
...4777777774...
.....777777.....
.....777777.....
.....666666.....
.....666666.....
.....4....4.....
................`],
[ box, bitmap`
................
................
................
................
................
.....000000.....
.....000000.....
.....000000.....
.....000000.....
.....000000.....
.....000000.....
................
................
................
................
................`],
[ wall, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
[ wallthrough, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
[ goal, bitmap`
3333333333333333
3333333333333333
33............33
33............33
33............33
33............33
33............33
33............33
33............33
33............33
33............33
33............33
33............33
33............33
3333333333333333
3333333333333333`],
);
setSolids([player, player1, box, wall]);
let level = 0;
const levels = [
map`
222wwww
21....g
2.....w
w..b..w
2.....2
2....p2
222w222`,
map`
222wwgw222
2........2
2........2
w........w
w1...b...w
w...b...pw
w........w
2........2
2........2
222wgww222`,
map`
222wwwww222
2....b....2
2.........2
w.........w
w.........w
g1.......pg
w.........w
w.........w
2.........2
2....b....2
222wwwww222`,
map`
222wwwwwwwwgw
21..........g
2...........w
w...........w
w...........w
w....b.b....w
w...........w
w....b.b....w
w...........w
w...........w
w...........2
g..........p2
wgwwwwwwww222`,
map`
222222222wwwwww
2...2...w...1.w
2.2.2.2.w.ww.pw
2.2.2.2.w..wwww
2.2.2.2.w.....2
2..g2.2.w.www.2
2.222.2.w.2...2
2.....2.w.2.2.2
2.22222.w.2.2.2
2.....2gw.2.2.2
2.222.222.2.2.2
2.....2...2.2.2
2.22222.2.2.2.2
2.......2.2b.b2
222222222222222`
];
const currentLevel = levels[level];
setMap(currentLevel);
setMap(levels[level]);
setPushables({
[ player ]: [box, player1],
[ player1 ]: [box, player],
[ box ]: [wallthrough]
});
onInput("s", () => {
const playerTile = getFirst(player);
const x = playerTile.x;
const y = playerTile.y;
const oneBelow = getTile(x, y + 1)
const twoBelow = getTile(x, y + 2)
const oneBelowHasBall = oneBelow.some(sprite => sprite.type === box);
const twoBelowHasWall = twoBelow.some(sprite => sprite.type === wallthrough);
if (oneBelowHasBall && twoBelowHasWall) return;
playerTile.y += 1;
});
onInput("d", () => {
const playerTile1 = getFirst(player);
const x = playerTile1.x;
const y = playerTile1.y;
const oneOver = getTile(x + 1, y)
const twoOver = getTile(x + 2, y)
const oneOverHasBall = oneOver.some(sprite => sprite.type === box);
const twoOverHasWall = twoOver.some(sprite => sprite.type === wallthrough);
if (oneOverHasBall && twoOverHasWall) return;
playerTile1.x += 1;
});
onInput("w", () => {
const playerTile2 = getFirst(player);
const x = playerTile2.x;
const y = playerTile2.y;
const oneAbove = getTile(x, y - 1)
const twoAbove = getTile(x, y - 2)
const oneAboveHasBall = oneAbove.some(sprite => sprite.type === box);
const twoAboveHasWall = twoAbove.some(sprite => sprite.type === wallthrough);
if (oneAboveHasBall && twoAboveHasWall) return;
playerTile2.y -= 1;
});
onInput("a", () => {
const playerTile3 = getFirst(player);
const x = playerTile3.x;
const y = playerTile3.y;
const oneLeft = getTile(x - 1, y)
const twoLeft = getTile(x - 2, y)
const oneLeftHasBall = oneLeft.some(sprite => sprite.type === box);
const twoLeftHasWall = twoLeft.some(sprite => sprite.type === wallthrough);
if (oneLeftHasBall && twoLeftHasWall) return;
playerTile3.x -= 1;
});
onInput("k", () => {
const playerTile4 = getFirst(player1);
const x = playerTile4.x;
const y = playerTile4.y;
const oneBelow1 = getTile(x, y + 1)
const twoBelow1 = getTile(x, y + 2)
const oneBelowHasBall1 = oneBelow1.some(sprite => sprite.type === box);
const twoBelowHasWall1 = twoBelow1.some(sprite => sprite.type === wallthrough);
if (oneBelowHasBall1 && twoBelowHasWall1) return;
playerTile4.y += 1;
});
onInput("l", () => {
const playerTile5 = getFirst(player1);
const x = playerTile5.x;
const y = playerTile5.y;
const oneOver1 = getTile(x + 1, y)
const twoOver1 = getTile(x + 2, y)
const oneOverHasBall1 = oneOver1.some(sprite => sprite.type === box);
const twoOverHasWall1 = twoOver1.some(sprite => sprite.type === wallthrough);
if (oneOverHasBall1 && twoOverHasWall1) return;
playerTile5.x += 1;
});
onInput("i", () => {
const playerTile6 = getFirst(player1);
const x = playerTile6.x;
const y = playerTile6.y;
const oneAbove1 = getTile(x, y - 1)
const twoAbove1 = getTile(x, y - 2)
const oneAboveHasBall1 = oneAbove1.some(sprite => sprite.type === box);
const twoAboveHasWall1 = twoAbove1.some(sprite => sprite.type === wallthrough);
if (oneAboveHasBall1 && twoAboveHasWall1) return;
playerTile6.y -= 1;
});
onInput("j", () => {
const playerTile7 = getFirst(player1);
const x = playerTile7.x;
const y = playerTile7.y;
const oneLeft1 = getTile(x - 1, y)
const twoLeft1 = getTile(x - 2, y)
const oneLeftHasBall1 = oneLeft1.some(sprite => sprite.type === box);
const twoLeftHasWall1 = twoLeft1.some(sprite => sprite.type === wallthrough);
if (oneLeftHasBall1 && twoLeftHasWall1) return;
playerTile7.x -= 1;
});
//onInput("e", () => {
//const currentLevel = levels[level];
//if (currentLevel !== undefined) {
//clearText("");
//setMap(currentLevel);}});
afterInput(() => {
// count the number of tiles with goals
const targetNumber = tilesWith(goal).length;
// count the number of tiles with goals and boxes
const numberCovered = tilesWith(goal, box).length;
if (numberCovered === targetNumber) {
// 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 });
}
}
});