forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbolt_battle.js
229 lines (207 loc) · 3.87 KB
/
bolt_battle.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
/*
@title: Bolt Battle
@author: Arnav Ambre
INSTRUCTIONS:
Use WASD to move the character to push the lighting bolts onto the batteries.
In this update, blue bolts must be moved onto blue batteries, and yellow bolts must be moved to yellow batteries.
This is a remix of Candy Rush by Tasbia (https://github.com/Tasbia).
*/
const player = "p";
const bolt = "b";
const battery = "g";
const batteryBlue = "x";
const boltBlue = "y";
const wall = "w";
setLegend(
[ player, bitmap`
......CCCC......
.....CCCCCCCC...
......0000......
.....002200.....
.....022220.....
.....022220.....
.....022220.....
......0000......
.....044440.....
....0.4444.0....
......4444......
.....444444.....
.....444444.....
......0..0......
......0..0......
.....55..55.....`],
[ bolt, bitmap`
................
.....00000000...
.....06666660...
....06666660....
....0666660.....
...0666660......
...066660000....
..0666666660....
..000066660.....
.....06660......
....06660.......
....0660........
...0660.........
...060..........
..060...........
..00............`],
[ boltBlue, bitmap`
................
.....00000000...
.....07777770...
....07777770....
....0777770.....
...0777770......
...077770000....
..0777777770....
..000077770.....
.....07770......
....07770.......
....0770........
...0770.........
...070..........
..070...........
..00............`],
[ battery, bitmap`
................
................
................
................
....00000000....
...0666666660...
...06633336600..
...06693336600..
...06699336600..
...06699936600..
...0666666660...
....00000000....
................
................
................
................`],
[ batteryBlue, bitmap`
................
................
................
................
....00000000....
...0777777770...
...07733337700..
...07793337700..
...07799337700..
...07799937700..
...0777777770...
....00000000....
................
................
................
................`],
[ wall, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`]
);
let level = 0;
const levels = [
map`
.g...
...b.
py...
....x`,
map`
g.b.w.
wwx...
p.w...
.w..y.
......`,
map`
.....g
..w...
w.....
x..wb.
wwy...
p..w.w`,
map`
...w...
.b.....
.w.pw.g
x.bw..w
....y.w
..gw.ww`,
map`
...w...
.b.....
.w.pw.g
g.yw..w
....b.w
..xw.ww`,
map`
w.....w
.b....g
....y.w
wx.....
wwww.ww
p....yx`,
];
const currentLevel = levels[level];
setMap(currentLevel);
setSolids([ player, bolt, boltBlue, wall ]);
setPushables({
[player]: [boltBlue,bolt],
/*no pushing bolt with bolt to make it harder*/
});
// START - PLAYER MOVEMENT CONTROLS
onInput("s", () => {
getFirst(player).y += 1;
});
onInput("d", () => {
getFirst(player).x += 1;
});
onInput("w", () => {
getFirst(player).y -= 1;
});
onInput("a", () => {
getFirst(player).x -= 1;
});
// END - PLAYER MOVEMENT CONTROLS
onInput("j", () => {
const currentLevel = levels[level];
if (currentLevel !== undefined) {
clearText("");
setMap(currentLevel);
}
});
afterInput(() => {
// count the number of tiles with goals
const targetNumber = tilesWith(battery).length;
const targetNumberBlue = tilesWith(batteryBlue).length;
// count the number of tiles with goals and boxes
const numberCovered = tilesWith(battery, bolt).length;
const numberCoveredBlue = tilesWith(batteryBlue, boltBlue).length;
if (numberCovered === targetNumber && numberCoveredBlue === targetNumberBlue) {
// 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("Congrats, you win!", { y: 4, color: color`3` });
}
}
});