forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMirror_Mirror.js
231 lines (213 loc) · 4 KB
/
Mirror_Mirror.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
/*
@title: Mirror_Mirror
@author: Benjamin Grelk
@tags: ['puzzle']
@addedOn: 2022-12-19
*/
const player = "p";
const mirror = "m";
const wall = "w";
const exit = "e";
const bg = "b"
const walkEffect = tune`
65.78947368421052: b4~65.78947368421052,
2039.4736842105262`;
const failEffect = tune`
122.44897959183673: f5~122.44897959183673,
122.44897959183673: c5~122.44897959183673,
3673.469387755102`;
const passEffect = tune`
128.2051282051282: d5~128.2051282051282,
128.2051282051282: g5~128.2051282051282,
3846.153846153846`;
setLegend(
[player, bitmap`
................
................
.....000000.....
....00990000....
....09999990....
....09099090....
....09099090....
....09999990....
.....099990.....
.....500005.....
....0.0770.0....
....0.0770.0....
......0000......
......0..0......
......3..3......
......0..0......`],
[mirror, bitmap`
................
................
.....000000.....
....00440000....
....04444440....
....04044040....
....04044040....
....04444440....
.....044440.....
.....H0000H.....
....0.0550.0....
....0.0550.0....
......0000......
......0..0......
......D..D......
......0..0......`],
[wall, bitmap`
0000000000000000
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0LLLLLLLLLLLLLL0
0000000000000000`],
[exit, bitmap`
LLLLLLLLLLLLLLLL
L44444444444444L
L44444444444444L
L44444444444444L
L44444444444444L
L44444444444444L
L44444444444444L
L44444444444444L
L44444444444444L
L44444444444444L
L44444444444444L
L44444444444444L
L44444444444444L
L44444444444444L
L44444444444444L
LLLLLLLLLLLLLLLL`],
[bg, bitmap`
77777777L7777777
77777777L7777777
77777777L7777777
77777777L7777777
77777777L7777777
77777777L7777777
77777777L7777777
77777777LLLLLLLL
LLLLLLLL77777777
7777777L77777777
7777777L77777777
7777777L77777777
7777777L77777777
7777777L77777777
7777777L77777777
7777777L77777777`]
);
setSolids([player, mirror, wall]);
let level = 0;
const levels = [
map`
p......wm..w...
.......w...w...
.......w...w...
.......w...w...
.......w...w...
.......w...w...
wwww...w.......
.......w.......
......ew......e`,
map`
p.w....wm......
..ww...w...ww..
w..wwwww.......
.....w.w...w...
.www...wwwww.ww
...wwwww...w...
ww.....w...w...
w..ww.www......
......eww.....e`,
map`
pw.....wm.w....
...w...w..w....
ew.....w...wwww
.......w.......
.......w..wwwww
.......w....w..
.......wwww.w..
.......w....w..
.......w......e`,
map`
pbbbbbbwmbbbbwb
bbbwbbbwbbbbwbb
bbwbbwwwbbbwwbb
bwbbbbbwbbwwbbb
wwbwwwwwbwwbbwb
bbbbbbbwbwbbwwb
wwbwwbbwbbbwbbb
bbbwbbbwbbwbbww
bbbwbbewbwwbbbe`,
map`
pbbbwwbbbbbwwwm
wwwbwbbwbwbwwwb
bbwbwbwwbwbbwwb
bbwbwbwebwwbwwb
bbbbwbwebwwwwbb
bwbwwbwwwwwwbbw
bwwwbbbbbbbwbww
bbwwbwwbwwbbbww
wbbbbwwbwwbbwww`,
];
setMap(levels[level]);
setBackground(bg);
onInput("s", () => {
getFirst(player).y += 1;
getFirst(mirror).y += 1;
});
onInput("w", () => {
getFirst(player).y -= 1;
getFirst(mirror).y -= 1;
});
onInput("a", () => {
getFirst(player).x -= 1;
getFirst(mirror).x -= 1;
});
onInput("d", () => {
getFirst(player).x += 1;
getFirst(mirror).x += 1;
});
onInput("j", () => {
playTune(failEffect);
const currentLevel = levels[level];
if (currentLevel !== undefined) {
clearText("");
setMap(currentLevel);
}
});
afterInput(() => {
let sum = tilesWith(exit, mirror).length + tilesWith(exit, player).length ;
if (sum == 2) {
// Both entities are on an exit pad
playTune(passEffect);
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` });
}
} else if (sum == 1) {
// Only one entity is on an exit
playTune(failEffect);
const currentLevel = levels[level];
if (currentLevel !== undefined) {
clearText("");
setMap(currentLevel);
}
} else {
playTune(walkEffect);
}});