-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmario.sed
executable file
·384 lines (369 loc) · 8.31 KB
/
mario.sed
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#!/usr/bin/env -S sed -Enf
# Sed Mario Bros
# 10th of December, 2015
# (C) Ivan Chebykin <[email protected]>
#map keys, down actually is not used
/^a/b left
/^d/b right
/^ /b up
/^s/b down
/^\[D/b left
/^\[C/b right
/^\[A/b up
/^\[B/b down
/q/q
# If screen is empty - print initial map, 2 first rows for header bar
:print
g
/^$/ { s/.*/\
+--------------------------------+\
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII\
IIIIIIIIIIIIx00IIIIIIIIIIIIIIIIIII\
|FFFFFFFFFFFFFFFFFFFFFFXFFFFFFFFFFFFFFFFFFFFFFFFF1\
|FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2\
|FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3\
|FFFFFFFFFFFFFFFFXFFFSXSXSFFFFFFFFFFFFFFFFFFFTFFF4\
|FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFTFFFFFFTFFF5\
|FFFFPFFFFFFFFFFFFFFFFFFFFFMFTFFFFFFFFTFFFMFFTFFF6\
|SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS7\
|SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS8\
+--------------------------------+\
/
}
# If no key is pressed
:none
b end
:left
g
s/FP/PF/
b end
:right
g
# Prevent screen scrolling at the end of level
/end/b end
s/PF/FP/
#Check if played is close to border of scroll buffer
/P(([FSTCBAHXMGKODE#]){16,32})[0-9]/ {
s/\|(([FSTCBAHXMGKODE]){1})/|/g
s/([FSTCBAHXMGKODE#])([0-9])/\1#\2/g
#Detect zone and load next to the scroll buffer
/P([FSTCBAHXMGKODE]){1,17}#*[0-9]/ {
/z/ !{
s/#*(1\n)/FFFFFFFFFFFFFFFF\1/
s/#*(2\n)/FFFFFFFFFFFFFFFF\1/
s/#*(3\n)/FFFFFFFFFFFFFFFF\1/
s/#*(4\n)/FFFFFFFTFFFFFFFF\1/
s/#*(5\n)/FFFFFFFTFFFFFFFF\1/
s/#*(6\n)/FMFFMFFTFFFFFFFF\1/
s/#*(7\n)/SSSSSSSSSSSSSSSS\1/
s/#*(8\n)/SSSSSSSSSSSSSSSS\1/
s/$/z1 /
b cls
}
/z1 / {
s/#*(1\n)/FFFFFF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\n)/SSSSSSSSSSSSSSSS\1/
s/z8 /z9 /
b cls
}
/z9 / {
s/#*(1\n)/FFFFFFFFFFFFFFFF\1/
s/#*(2\n)/FFFFFFFFFFFFFFFF\1/
s/#*(3\n)/FFFFFFFFFFFFFFFF\1/
s/#*(4\n)/FFFBBBFFFFFFFFFF\1/
s/#*(5\n)/FFBBBBBFFFFFFFFF\1/
s/#*(6\n)/FFBBHBBFFFFFFFFF\1/
s/#*(7\n)/SSSSSSSSSSSSSSSS\1/
s/#*(8\n)/SSSSSSSSSSSSSSSS\1/
s/z9 /z10 /
b cls
}
/z/ {
s/#*(1\n)/FFFFFFFSSSSSSSSS\1/
s/#*(2\n)/FFFFFFFSSSSSSSSS\1/
s/#*(3\n)/FFFFFFFSSSSSSSSS\1/
s/#*(4\n)/FFFFFFFSSSSSSSSS\1/
s/#*(5\n)/FFFFFFFSSSSSSSSS\1/
s/#*(6\n)/FFFFFFFSSSSSSSSS\1/
s/#*(7\n)/SSSSSSSSSSSSSSSS\1/
s/#*(8\n)/SSSSSSSSSSSSSSSS\1/
b cls
}
}
}
b end
:up
g
# Special tags check, that prevents us from jumping in the air
/(1|2|3)u/ !{
/P(.{50})F/ !{
s/F(.{50})P/P\1F/
s/$/1u/
}
}
b cls
:down
g
b end
:end
:score
# If player hit the orange box, we increment score
/X(.{50})P/{
s/X(.{50})P/D\1P/
:incr
s/9(d*)I/d\1I/;t incr
s/x(d*)I/x0\1I/
s/8(d*)I/9\1I/
s/7(d*)I/8\1I/
s/6(d*)I/7\1I/
s/5(d*)I/6\1I/
s/4(d*)I/5\1I/
s/3(d*)I/4\1I/
s/2(d*)I/3\1I/
s/1(d*)I/2\1I/
s/0(d*)I/1\1I/
s/d/0/g
}
# When enemy hits the wall it *should* change direction
:enemies
#If player hits enemies he will be removed
s/P(M|K)/\1F/
s/(G|O)P/F\1/
s/F(M|K)/\1F/g
s/(G|O)F/F\1/g
/(P(M|K))|((G|O)P)/!{
/FM/!s/M/G/
/GF/!s/G/M/
/FK/!s/K/O/
/OF/!s/O/K/
}
# Prevents enemies from moving into wall
/FMM/s/FMM/MFM/
/MMF/s/MMF/GFG/
/GGF/s/GGF/GFG/
/FGG/s/FGG/MFM/
/KKF/s/KKF/KFK/
/FKK/s/FKK/OFO/
/OOF/s/OOF/OFO/
/FOO/s/FOO/KFK/
# If player crossed flagpole, we start ending
:endlevel
/FPEF/{
s/$/end/
s/FPEF/FFPF/
s/(E|A)/F/g
}
# Move player into castle
/end/{
/FPBB/!{
s/PF/FP/;t check
}
/FPBB/{
s/FPBB/FFPB/;t check
}
/PB/{
s/PB/BP/;t check
}
/PH/{
s/P/B/;t check
}
s/x[0-9]{2}/x99/
s/$/endmsg/
}
:check
/(1|2)u/ !{
# Check if player is in the sky
/P(.{50})F/ {
s/P(.{50})F/F\1P/
s/3u//
b cls
}
/P(.{50})B/ {
s/P(.{50})B/B\1P/
b cls
}
# If player is above Gooba kill him and increment score
/P(.{50})M/ {
s/P(.{50})M/F\1P/;t incr
b cls
}
/P(.{50})G/ {
s/P(.{50})G/F\1P/;t incr
b cls
}
# Same with Koopa
/P(.{50})K/ {
s/P(.{50})K/F\1P/;t incr
b cls
}
/P(.{50})O/ {
s/P(.{50})O/F\1P/;t incr
b cls
}
# If someone fell into hole - delete him
s/[PMGKO](.{50})-/F\1-/g
#If mobs are above ground - move them down
s/([MGKO])(.{50})F/F\2\1/g
}
# Check the stage of jumping, and move player higher
/(1|2|3)u/ {
s/F(.{50})P/P\1F/
s/2u/3u/
s/1u/2u/
b cls
}
/P/ !{
/end/ !{
s/$/died/
}
}
:cls
# Saving to the hold buffer, after that all is left are post-effects.
h
# Hide offscreen buffer
s/([FSTCBAHXMGKODE#]){16}([0-9])/|/g
# Hide zone
s/z[0-9]* //
# Hide jump stage
s/[1-3]u//
# Add colors to blocks
# Sky
s/F/\[48;5;27m \[0m/g
# Brick
s/S/\[48;5;130m \[0m/g
# Pipe
s/T/\[48;5;34m \[0m/g
# Player
s/P/\[48;5;160m \[0m/g
# Stairs
s/C/\[48;5;52m \[0m/g
# Castle
s/B/\[48;5;124m \[0m/g
# Flag
s/A/\[48;5;40m \[0m/g
# Black block (castle door)
s/H/ /g
# Score block
s/X/\[48;5;208m \[0m/g
# Little Goomba
s/(M|G)/\[48;5;88m \[0m/g
# Koopa Troopa
s/(K|O)/\[48;5;76m \[0m/g
# Empty score block
s/D/\[48;5;137m \[0m/g
# Flagpole
s/E/\[48;5;27m|\[0m/g
# Here we prepare header by adding labels and sky blocks
# After that we should perform coloring again
s/\nI{34}\nI{12}x([0-9])([0-9])I{19}/\
|FFFMARIOFFFFFFFFFFWORLDFFTIMEFFF|\
|FFF0\200\10FFXx\1\2FFFF1-1FFFF360FFF|/
s/F/\[48;5;27m \[0m/g
s/X/\[48;5;214m \[0m/g
s/(MARIO|WORLD|TIME|[0-9]{6}|x[0-9]{2}|1-1|360)/\[48;5;27m\1\[0m/g
s/MARIO/\[48;5;27mMARIO\[0m/g
s/end//
# Clear screen
i\
[H
# Print end message
/endmsg/{
s/endmsg$/THANK YOU MARIO!\nYOUR QUEST IS OVER.\
WE PRESENT YOU A NEW QUEST.\n\nPLAY AGAIN/
p;q
}
/died/{
s/died$/SORRY MARIO!\nGAME OVER.\nTRY AGAIN./
p;q
}
p