forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flightless_bird.js
239 lines (219 loc) · 4.37 KB
/
flightless_bird.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
/*
@title: flightless_bird
@author: ced
*/
setLegend({
d: bitmap`
.00000.0000.000.
................
................
...0000000000...
..0.0..0...0.0..
..0.00000000.0..
..000......000..
..0.0......0.0..
..0.0......0.0..
..0.0......0.0..
..000......0.0..
..0.0......0.0..
..000...00.000..
..0.0......0.0..
..0.0......000..
..0.0......0.0..`,
'8': bitmap`
.0000.000000.000
0....0......0...
0....0......0...
0....0......0...
.0000.000000.000
................
00.0000.00000.00
..0....0.....0..
..0....0.....0..
..0....0.....0..
00.0000.00000.00
................
0000.0000.00000.
....0....0.....0
....0....0.....0
....0....0.....0`,
'7': bitmap`
.5555.555555.555
5....5......5...
5....5......5...
5....5......5...
.5555.555555.555
................
55.5555.55555.55
..5....5.....5..
..5....5.....5..
..5....5.....5..
55.5555.55555.55
................
5555.5555.55555.
....5....5.....5
....5....5.....5
....5....5.....5`,
c: bitmap`
.00000.0000.000.
................
................
................
................
................
................
................
................
................
................
................
................
................
................
................`,
l: bitmap`
.00000.0000.000.
................
.......5........
......555.......
......555.......
.....555.5......
.....55.55......
......555.......
................
................
................
................
................
................
................
................`,
o: bitmap`
................
................
.......5........
......555.......
......555.......
.....555.5......
.....55.55......
......555.......
................
................
................
................
................
................
................
................`,
i: bitmap`
......5555......
....55....55....
..55........55..
.5............5.
5.55........55.5
5...55....55...5
5.....5555.....5
5..5....5......5
5.5.....5......5
5....5..5......5
5...5...5......5
.5......5.....5.
..55....5...55..
....55..5.55....
......5555......
................ `,
p: bitmap`
.......000......
.....00..00.....
....0......0....
....0......000..
.....00...000...
....0..000......
....0....00.....
....0.....0.....
....0......0....
...0........0...
...0...0....0...
..0....0....0...
..0....0...0....
...0000...0.....
.......000......
......0...0.....`,
'I': allOf('i', 'o'),
/* that's a dub */
'w': allOf('p', 'd')
})
setSolids(["p", "8", "7"]);
setPushables({ p: ["7"] });
// setZOrder(["p","r", "0"]);
let level = 0;
const levels = [
map`
8888888888
8ccccclc88
8.......d8
8p.....888
888888.888
888888.888`,
map`
8ccclcccc8
8........8
8p.......8
8888.....d
8888...888
8888...888`,
map`
8cclccccc8
8........8
8p.......8
8888.....d
8888...888
8888...888`,
];
setMap(levels[level]);
let move = [0, 0];
onInput( "up", _ => move = [ 0, -1])
// onInput( "down", _ => move = [ 0, 1])
// onInput( "left", _ => move = [-1, 0])
onInput("right", _ => move = [ 1, 0])
/* ice cube launching special power! */
onInput( "l", _ => {
const { x, y } = getFirst("p");
addSprite("i", x+1, y);
})
/* reset level */
onInput( "j", _ => setMap(levels[level]));
const isBrick = ({ type }) => ['7', '8'].includes(type);
let tick = 0;
setInterval(_ => {
/* turn ice cube + rain drop = blue brick */
// BUG:
// replace('I', '7');
// matches not just ['i', 'o'], but ['i', 'i'] and ['o', 'o']
for (const {x, y} of getAll('i'))
if (getTile(x, y).some(x => x.type == "o"))
clearTile(x, y), addSprite("7", x, y);
/* gravity */
for (const o of getAll("o")) o.y += 1;
for (const o of getAll("7")) o.y += 1;
/* flying ice cubes */
for (const i of getAll("i")) i.x += 1;
/* player movement! */
const { x, y } = getFirst("p");
getFirst("p").x += move[0];
getFirst("p").y += move[1] + ((getTile(x, y+1) ?? []).some(isBrick) == 0);
move = [0, 0];
tick++;
/* leaks ("l") drip drops ("o") every 4th tick */
if (tick%4 == 0) {
for (const {x, y} of getAll("l"))
addSprite("o", x, y);
}
/* ice and drops break on bricks */
for (const t of ["i", "o"].flatMap(getAll))
if (getTile(t.x, t.y).some(isBrick))
t.remove();
/* next map when player touch door */
if (match("w").length > 0 && levels[level+1])
setMap(levels[++level]);
}, 200);