-
Notifications
You must be signed in to change notification settings - Fork 0
/
platformer.lua
320 lines (296 loc) · 21.7 KB
/
platformer.lua
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
-- title: My platformer
-- author: draxaris1010
-- desc: This is a simple platformer game.
-- script: lua
-- +-------------------------------------------------------------------------+
-- | Sprites/tiles that look like random stuff are comments in ASCII format, |
-- | to read them, copy the sprite and paste it in an HEX to ASCII converter |
-- | like https://coding.tools/hex-to-ascii |
-- | or |
-- | with the following command in linux : |
-- | echo "{{the sprite from the clipboard}}" | xxd -p -r |
-- +-------------------------------------------------------------------------+
-- +-----------------------CONTROLS----------------------+
-- | button | key | action |
-- +--------|-----|--------------------------------------+
-- | [A] | Z | jump |
-- | [B] | A | exit the game |
-- |[<] [>] | < > | left/right |
-- |-----------------------DEBUGGING---------------------|
-- | [X] | A | hold to switch level with arrow keys |
-- +-----------------------------------------------------+
trace("["..time().."]: Begin!")
function solid(x, y)
return solids[mget((x) // 8 + maps[mapn][1], (y) // 8 + maps[mapn][2])]
end
function portal(x, y)
return portals[mget((x) // 8 + maps[mapn][1], (y) // 8 + maps[mapn][2])]
end
function spike(x, y)
return spikes[mget((x) // 8 + maps[mapn][1], (y) // 8 + maps[mapn][2])]
end
function chmap(n,b)
-- if last map then quit
if (mapn == #maps) and b then
trace("["..time().."]: Finished")
return
exit()
end
mapn=mapn+n
-- teleport to spawn point identified by the sprite on the map
sync()
spawn=false
for fx=0,29 do
for fy=0,16 do
if (mget(fx+maps[mapn][1],fy+maps[mapn][2])==32) then
p.x=fx*8
p.y=fy*8
spawn=true
mset(fx+maps[mapn][1],fy+maps[mapn][2],0)
trace("["..time().."]: spawn X="..tostring(fx).." Y="..tostring(fy))
trace("["..time().."]: spawn screen X="..tostring(p.x).." Y="..tostring(p.y))
end
if not(spawn) then trace("["..time().."]: find spawn X="..tostring(fx).." Y="..tostring(fy)) end
end
end
-- if no spawn point then default spawn point
if (not(spawn)) then
p.x=0
p.y=112
end
--~ mapn=mapn+n
trace("["..time().."]: Teleported to map "..mapn)
end
function init()
solids = {[1] = true, [2] = true, [3] = true, [4] = true, [5] = true, [6] = true, [7] = true, [8] = true, [9] = true, [10] = true, [11] = true, [12] = true, [13] = true, [14] = true, [17] = true, [18] = true, [19] = true, [20] = true, [21] = true, [22] = true, [23] = true, [24] = true, [25] = true, [26] = true, [27] = true, [28] = true, [29] = true, [33] = true, [34] = true, [35] = true, [36] = true, [37] = true, [38] = true}
portals = {[16] = true}
spikes = {[39] = true, [40] = true, [41] = true, [42] = true}
p = {
x = 0,
y = 112,
vx = 0, --Velocity X
vy = 0, --Velocity Y
jl = 2 --Jumps left
}
maps={{0,0},{30,0},{60,0},{90,0},{120,0}}
trace("["..time().."]: #maps = "..#maps)
mapn=0
poke(0x3ff8,0) -- set border color
chmap(1)
end
init()
function TIC()
-- input events
if btn(2) and p.x~=0 then
p.vx = -1
elseif btn(3) and p.x~=232 then
p.vx = 1
else
p.vx = 0
end
if (btnp(4) and p.jl ~= 0) then
p.vy = -3.5
p.jl = p.jl - 1
sfx(0)
--~ else p.vy=0
end
-- debug level
if btn(6) then
p.vx=0
if btnp(2) then
if mapn~=1 then
chmap(-1,false)
end
elseif btnp(3) then
if mapn~=#maps then
chmap(1,false)
end
end
end
-- colision detection
if solid(p.x + p.vx, p.y + p.vy) or solid(p.x + 7 + p.vx, p.y + p.vy) or solid(p.x + p.vx, p.y + 7 + p.vy) or
solid(p.x + 7 + p.vx, p.y + 7 + p.vy) then
p.vx = 0
end
if solid(p.x, p.y + 8 + p.vy) or solid(p.x + 7, p.y + 8 + p.vy) then
p.vy = 0
p.jl = 2
else
p.vy = p.vy + 0.2
end
if p.vy < 0 and (solid(p.x + p.vx, p.y + p.vy) or solid(p.x + 7 + p.vx, p.y + p.vy)) then
p.vy = 0
end
p.x = p.x + p.vx
p.y = p.y + p.vy
cls()
map(maps[mapn][1],maps[mapn][2],30,17)
if (mapn == 1) then
print("[<] [>] = left right\nZ/[A] = jump\nX/[B] = exit",70,64)
end
--rect(p.x, p.y, 8, 8, 12)
spr(32, p.x, p.y,0)
print("Level "..mapn,0,0,12)
if (p.vx ~= 0 or p.vy ~=0) then
trace("["..time().."]: X="..tostring(p.x).." Y="..tostring(p.y))
--~ poke(0x3ff8,14)
--~ else
--~ poke(0x3ff8,0)
end
-- respawn when not in borders
if (p.y > 121) then
sfx(1)
reset()
trace("["..time().."]: died")
end
-- change to next level when player enters portal
if portal(p.x, p.y) or portal(p.x+8, p.y) or portal(p.x, p.y+8) or portal(p.x+8, p.y+8) then
chmap(1,true)
end
-- respawn when touching spikes
if spike(p.x, p.y) or spike(p.x+6, p.y) or spike(p.x, p.y+5) or spike(p.x+5, p.y+5) then
sfx(1)
reset()
trace("["..time().."]: died")
end
if btn(5) then
exit()
end
--~ poke(0x3ffb,0) -- disables cursor
end
-- <TILES>
-- 001:6666666665555555655555556555555565555555655555556555555565555555
-- 002:6666666655555555555555555555555555555555555555555555555555555555
-- 003:6666666655555556555555565555555655555556555555565555555655555556
-- 004:5555555555555555555555555555555555555555555555555555555555555556
-- 005:6666666665555556655555566555555665555556655555566555555665555556
-- 006:5555555555555555555555555555555555555555555555555555555565555555
-- 007:6666666655555555555555555555555555555555555555555555555566666666
-- 008:6666666665555555655555556555555565555555655555556555555565555556
-- 009:6666666655555556555555565555555655555556555555565555555665555556
-- 010:6666666655555555555555555555555555555555555555555555555555555556
-- 011:6666666655555555555555555555555555555555555555555555555565555555
-- 012:6555555565555555655555556555555565555555655555556555555565555556
-- 013:5555555655555556555555565555555655555556555555565555555665555556
-- 014:6000000600000000000000000000000000000000000000000000000060000006
-- 016:cc00cc00cc00cc0000cc00cc00cc00cccc00cc00cc00cc0000cc00cc00cc00cc
-- 017:6555555565555555655555556555555565555555655555556555555565555555
-- 018:5555555555555555555555555555555555555555555555555555555555555555
-- 019:5555555655555556555555565555555655555556555555565555555655555556
-- 020:6666666665555555655555556555555565555555655555556555555566666666
-- 021:6666666665555556655555566555555665555556655555566555555666666666
-- 022:6666666655555556555555565555555655555556555555565555555666666666
-- 023:6555555665555556655555566555555665555556655555566555555665555556
-- 024:6555555665555555655555556555555565555555655555556555555566666666
-- 025:6555555655555556555555565555555655555556555555565555555666666666
-- 026:5555555655555555555555555555555555555555555555555555555566666666
-- 027:6555555555555555555555555555555555555555555555555555555566666666
-- 028:6555555665555555655555556555555565555555655555556555555565555555
-- 029:6555555655555556555555565555555655555556555555565555555655555556
-- 032:4444444444044044440440444444444444444444404444044400004444444444
-- 033:6555555565555555655555556555555565555555655555556555555566666666
-- 034:5555555555555555555555555555555555555555555555555555555566666666
-- 035:5555555655555556555555565555555655555556555555565555555666666666
-- 036:5555555655555555555555555555555555555555555555555555555555555555
-- 037:6555555665555556655555566555555665555556655555566555555666666666
-- 038:6555555555555555555555555555555555555555555555555555555555555555
-- 039:0000000000000000000000000d000d00d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0
-- 040:dddd00000000d000dddd000000000000dddd00000000d000dddd000000000000
-- 041:0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00d000d0000000000000000000000000
-- 042:000000000000dddd000d00000000dddd000000000000dddd000d00000000dddd
-- 048:6e6f20636c69702074696c65730a000000000000000000000000000020000002
-- 049:2666666265555555655555556555555565555555655555556555555525555552
-- 050:2666666255555555555555555555555555555555555555555555555525555552
-- 051:2666666255555556555555565555555655555556555555565555555625555552
-- 052:2555555255555555555555555555555555555555555555555555555525555552
-- 053:2666666265555556655555566555555665555556655555566555555625555552
-- 054:2555555255555555555555555555555555555555555555555555555525555552
-- 055:2666666255555555555555555555555555555555555555555555555526666662
-- 056:2666666265555555655555556555555565555555655555556555555525555552
-- 057:2666666255555556555555565555555655555556555555565555555625555552
-- 058:2666666255555555555555555555555555555555555555555555555525555552
-- 059:2666666255555555555555555555555555555555555555555555555525555552
-- 060:2555555265555555655555556555555565555555655555556555555525555552
-- 061:2555555255555556555555565555555655555556555555565555555625555552
-- 065:2555555265555555655555556555555565555555655555556555555525555552
-- 066:2555555255555555555555555555555555555555555555555555555525555552
-- 067:2555555255555556555555565555555655555556555555565555555625555552
-- 068:2666666265555555655555556555555565555555655555556555555526666662
-- 069:2666666265555556655555566555555665555556655555566555555626666662
-- 070:2666666255555556555555565555555655555556555555565555555626666662
-- 071:2555555265555556655555566555555665555556655555566555555625555552
-- 072:2555555265555555655555556555555565555555655555556555555526666662
-- 073:2555555255555556555555565555555655555556555555565555555626666662
-- 074:2555555255555555555555555555555555555555555555555555555526666662
-- 075:2555555255555555555555555555555555555555555555555555555526666662
-- 076:2555555265555555655555556555555565555555655555556555555525555552
-- 077:2555555255555556555555565555555655555556555555565555555625555552
-- 081:2555555265555555655555556555555565555555655555556555555526666662
-- 082:2555555255555555555555555555555555555555555555555555555526666662
-- 083:2555555255555556555555565555555655555556555555565555555626666662
-- 084:2555555255555555555555555555555555555555555555555555555525555552
-- 085:2555555265555556655555566555555665555556655555566555555626666662
-- 086:2555555255555555555555555555555555555555555555555555555525555552
-- 087:2000000200000000000000000d000d00d0d0d0d0d0d0d0d0d0d0d0d020d0d0d2
-- 088:2ddd00020000d000dddd000000000000dddd00000000d000dddd000020000002
-- 089:2d0d0d020d0d0d0d0d0d0d0d0d0d0d0d00d000d0000000000000000020000002
-- 090:200000020000dddd000d00000000dddd000000000000dddd000d00002000ddd2
-- </TILES>
-- <SPRITES>
-- 000:637265612070756c7175657320796f7565206265207370720a00000000000000
-- 001:746520616c207265742069662068617674746572697465730000000000000000
-- 016:0000000000000000000000000000000000000000000000000000000020000000
-- 017:0000000000000000000000000000000000000000000000000000000000000002
-- 120:6f6c6420737072697465730a0000000000000000000000000000000020000002
-- 137:6666666655555555555555555555555555555555555555555555555555555555
-- 138:6666666655555556555555565555555655555556555555565555555655555556
-- 139:6666666665555555655555556555555565555555655555556555555565555555
-- 140:0000000000000000000000000d000d00d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0
-- 152:0000000e0000000e0000000e0000000e0000000e0000000e0000000e0000000e
-- 153:5555555555555555555555555555555555555555555555555555555555555555
-- 154:5555555555555555555555555555555555555555555555555555555555555556
-- 155:5555555555555555555555555555555555555555555555555555555565555555
-- 168:4444444444044044440440444444444444444444404444044400004444444444
-- 170:5555555655555555555555555555555555555555555555555555555555555555
-- 171:6555555555555555555555555555555555555555555555555555555555555555
-- </SPRITES>
-- <MAP>
-- 001:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 002:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041706100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 003:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000417061e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 005:000000000000000000000000000000000000000010202020203000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004161000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 006:000000000000000000000000000000000000000014242424243400000000000000008070707070707070707070610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000092000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 007:000000000000000000000000000000000000000014242424243400000000000000419100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000004161000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 008:000000000000000000000000000000000000000014242424243400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000417070707061000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 009:004170707070706100000000000000000041707070707070707070610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000417061000041706100005172725100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 010:000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000080707070706100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 011:000000000000000000000000000000000000000000000000000000000000005100000000000000e0e0e0e0e0e0000071000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001020a07070707070707070707070707061959595959595959595000000000000000000000000000000000000004170610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 012:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007100000000000000000000000000000000000000000000004170707070610000000000000000000000000000000041b125350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 013:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000052000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 014:020000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000001020000000000000000000000000000000000000000000000000000000000000000000000004170706172417061000000004170737373737070707070000000000000000000000000000000000000000000000000417061000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 015:000000001020202020300000000072720000009292000010202020202020202020202020203000000000000000000000000000000010202020202020202030000000001020202020202020202020202020202020202020202020300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 016:202020206221212121422020202020202020202020202062212121212121212121212121213172727272727272727272727272727211212121212121212131727272721121212121212121212121212121212121212121212121422020202020202020307272721020202020307272727210013072727272307272727272727272727272727272727272727272727272727272102020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- </MAP>
-- <WAVES>
-- 000:00000000ffffffff00000000ffffffff
-- 001:0123456789abcdeffedcba9876543210
-- 002:0123456789abcdef0123456789abcdef
-- </WAVES>
-- <SFX>
-- 000:0000101020203030404050506060707080809090a0a0b0b0c0c0d0d0e0e0e0f0f000f000f000f000f000f000f000f000f000f000f000f000f000f000300000000000
-- 001:02000211022202030204020532063207420042005200520062006200720072008200820092009200a200a200b200b200c200c200d200d200e200f200b00000000308
-- 002:0000100020003000400050006000700080009000a000b000c000d000e000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000300000000000
-- </SFX>
-- <TRACKS>
-- 000:0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e0000
-- </TRACKS>
-- <FLAGS>
-- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- 001:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- </FLAGS>
-- <PALETTE>
-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
-- </PALETTE>
-- <COVER>
-- 000:102000007494648393160f0088002c70004f4f4fa1c1c2837b467a0f0733c37565c668ffdc57ffffffc2000000000f0088000030ef81abcdef03ac94badb83bedcbbff0682e84696e986aaeac6beeb07c2fc47d6fd87eafec7feff0c0a0784c2a1f88c4a279cc6a3f90d8a47a4daa5fa8dca67bcdea7fb0e0b87c4e2b9fc8e4ba7dce6bbfd0f8bc7e4fabdfe8fcbe7fcfebfff08182838485868788898a8b8c8d8e8f809192939495969798999a9b9c9d9e9f90a1a2a3a4a5a6a7a8a9aaabacadaeafa0b1b2b3b4b5b6b7b8b9babbbcbdbebfb0c1cb5204c5c6c7c8c9cacbccc2005dc0d1d2d3d4d9c0220309dadbdcdddedfd0e0eecf48d1e6e7e8e9eae1e3ee15ebe0f1f30ded4fe2f7f8f9f3f7dafdfed4fc4ce9fb18407b10cd020b02eb38a421a2c78b09f14cc7c03983c98813d554c07fc133e9bd874a3a7c19dd04a58a6823521b76a2b5abc7962589cc9943b6adcb98337aecd9c3b7afcf90438a0d1a44b8a1d3a8439a2d5ac4b9a3d7a053aa4d9a45baa5dba853ba6ddac5bba75b0602ca8d0b7d06eb483663de132bc6d084429ff0d2c587d63009df022746c423977e27b1b36fdaf5d6b77c4fd1c9d00b851c88b0b893c88dd6067b8711b149b69dcdd550b9b304e98e83cc76fba8b33781df0343814d075d22bcc9dc5bce9d9216bdebd8b37beeddcbb7bfefd0c38b0f1e4cb8b1f3e8c39b2f5eccb9b3f7e0d3a7fb40000b3
-- </COVER>