forked from stevelavietes/pico8carts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathedges.p8
440 lines (346 loc) · 10.6 KB
/
edges.p8
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
pico-8 cartridge // http://www.pico-8.com
version 18
__lua__
function _init()
g_t = 0
g_b = makeboard(8, 10)
g_cur = makecursor(g_b)
--test
g_b[3][9][1] = 3
g_b[2][9][2] = 9
g_b[2][9][1] = 8
g_b[4][9][2] = 8
g_b[4][3][2] = 8
g_b[4][3][1] = 8
g_b[5][3][1] = 3
--g_b[1][10][1] = 8
--g_b[1][10][2] = 8
--g_b[2][10][2] = 9
g_cur.x = 1
g_cur.y = 8
end
function _update60()
g_t += 1
if btnp(0, 1) then
raiseboard(g_b)
end
updatecursor(g_cur)
end
function _draw()
cls()
rect(0, 0, 127, 127, 1)
camera(-4, -10)
drawboard(g_b)
drawcursor(g_cur)
--local f =
-- curframe(flr(g_t / -3))
--f = 0
--pal(1, 0)
--spr(f, 8, 16, 3, 3)
-- pal()
camera()
end
function curframe(i)
i = i % 6
if i < 5 then
return i * 3
end
return 48
end
function makeboard(x, y)
local b = {}
for _x = 1, x do
local c = {}
b[_x] = c
for _y = 1, y do
c[_y] = {0, 0, 0, 0}
end
end
return b
end
function drawboard(b)
for x = 1, #b do
local c = b[x]
for y = 1, #c do
local e = c[y]
if x > 1
and x < #b
and y > 1
and y < #c
then
spr(15, x*8, y*8)
end
-- right
if e[1] > 0 then
pal(7, e[1])
spr(47, x*8+4, y*8)
pal()
end
-- up
if e[2] > 0 then
pal(7, e[2])
spr(31, x*8, y*8-4)
pal()
end
end
end
end
_spinpivots = {
{{3, 11}, --left
{20, 12}, --right
{12, 3}, --top
{11, 20}},--bot
{{4, 13},
{19, 10},
{9, 3},
{12, 20}},
{{4, 15},
{19, 8},
{8, 4},
{14, 19}},
{{5, 17},
{17, 6},
{6, 5},
{16, 18}},
{{7, 18},
{15, 5},
{5, 7},
{18, 16}},
{{9, 19},
{13, 4},
{4, 9},
{18, 14}}
}
function makecursor(board)
return {
x = 0,
y = 0,
direction = 0,
rotcount = 0,
pivot = 0,
pivotcount = 0,
board=board,
}
end
_dirs = {
{-1, 0},
{1, 0},
{0, -1},
{0, 1},
}
function drawcursor(c)
if c.direction == 0 then
pal(1, 0)
spr(curframe(0),
c.x * 8, c.y * 8, 3, 3)
pal()
local x = c.x * 8 + 8
local y = c.y * 8 + 8
if c.pivot > 0 then
x += _dirs[c.pivot][1] * 8
y += _dirs[c.pivot][2] * 8
end
local f = 51
if g_t % 30 > 14 then
f += 1
end
spr(f, x, y)
--print(c.x .. ' ' .. c.y,
-- 0, -10, 5)
else
spr(curframe(c.rotcount),
c.x * 8, c.y * 8, 3, 3,
c.direction > 0)
end
end
_cwoffsets = {
{0, 1, 1},
{1, 1, 2},
{1, 1, 1},
{1, 2, 2}
}
function updatecursor(c)
if c.direction == 0 then
c.pivot = 0
for i = 0, 3 do
if btn(i) then
c.pivot = i + 1
break
end
end
if c.pivot == 0 then
local bp = -1
for i = 4, 5 do
if btnp(i) then
bp = i
break
end
end
if bp > -1 then
-- gather entries
local ens = {}
local vals = {}
for i = 1, 4 do
local e = _cwoffsets[i]
add(ens, {
c.board[c.x + e[1]]
[c.y + e[2]], e[3]})
add(vals,
ens[i][1][e[3]])
end
c.direction =
(bp - 4) * 2 - 1
for i = 1, 4 do
local en = ens[i]
local ii = i
if bp == 5 then
ii -= 1
if ii < 1 then
ii = 4
end
else
ii = (ii % 4) + 1
end
en[1][en[2]] = vals[ii]
--
end
--[[
stop('\n\n\n' .. vals[1] .. ' '
.. vals[2] .. ' '
.. vals[3] .. ' '
.. vals[4])
--]]
end
end
updatecursorpos(c)
else
c.rotcount += 1
if c.rotcount >= 5 then
c.direction = 0
c.rotcount = 0
end
end
end
_curoffs = {
--ccw, cw
{{-1, -1},{-1, 1}}, --left
{{1, 1}, {1, -1}}, --right
{{1, -1}, {-1, -1}}, --up
{{-1, 1}, {1, 1}} --down
}
_curdirs = {
{-1, 0},
{1, 0},
{0, -1},
{0, 1}
}
function updatecursorpos(c)
if c.pivot == 0 then
return
end
local x = c.x
local y = c.y
if btnp(c.pivot - 1) then
x += _curdirs[c.pivot][1]
y += _curdirs[c.pivot][2]
else
return
end
--[[
local d = 0
if btnp(4) then
d = 1
elseif btnp(5) then
d = 2
end
if d == 0 then
return
end
local off =
_curoffs[c.pivot][d]
local x = c.x + off[1]
local y = c.y + off[2]
--]]
local w = #c.board
local h = #c.board[1]
if x < 1 or x > w - 2 then
return
end
if y < 1 or y > h - 2 then
return
end
c.x = x
c.y = y
end
_colors = {
0, 0, 0, 0, 0, 0, 0,
3, 8, 12}
function getcol()
return _colors[
flr(rnd(#_colors)) + 1]
end
function raiseboard(b)
--todo
for i = 1, #b do
local c = b[i]
del(c, c[1])
local e = {0,0,0,0}
if i > 1 and i < #b then
e[2] = getcol()
if c[#c][1] == 0 then
c[#c][1] = getcol()
end
end
add(c, e)
c[1][1] = 0
c[1][2] = 0
end
end
__gfx__
00000000000110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000001771000000000000000000111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000017007100000000000000001777100000000000000000011110000000000000000000000000000000000000000000000000001111000000000000000
00000000170000710000000000000017700710000000000000000177771000000000000000000111000000011100000000000000000017777100000000055000
00000000170000710000000000000017000071000000000000001700007100000000000000001777100000177710000000000000000170007100000000055000
00000000170000710000000000000017000071000000000000001700007100011111000000017000710001700071000000011111000170007100000000000000
00000000170000710000000000000017000071000000000000001770000710117777100000017000071017000071000000177777100700007100000000000000
00000000170000710000000000000001700071111111000000000170000711770007710000017000007170000071000000170000711700007100000000000000
00011111170000711111100000000001700007777777110000000017000077000000710000017000000700000710000000170000077000007100000000000000
00177777700000077777710000000111700000000000710000000017000000000007100000001700000000000710000000170000000000071000000000077000
01700000000000000000071000011777000000000000710000000017000000000077100000000170000000007100000000017000000000071000000000077000
17000000000000000000007100177000000000000000710000000117000000007711000000000017000000071000000000001770000000071100000000077000
17000000000000000000007101700000000000000077100000011770000000071100000000000017000000071000000000000117000000007710000000077000
01700000000000000000071001700000000000077711000000177000000000071000000000000170000000007100000000000017000000000071000000077000
00177777700000077777710001700000000000711100000000170000000000071000000000001700000000000710000000000017000000000007100000077000
00011111170000711111100000177777770000710000000000170000077000071000000000001700000000000071000000000177000077000000710000000000
00000000170000710000000000011111117000710000000000170007711700007100000000017000007170000071000000000170000711770000710000000000
00000000170000710000000000000000017000071000000000177771111700007710000000017000071017000071000000000170000710177777100000000000
00000000170000710000000000000000017000071000000000011111000170000710000000017000710001700071000000000170007100011111000000000000
00000000170000710000000000000000017000071000000000000000000170000710000000001777100000177710000000000170007100000000000007777770
00000000170000710000000000000000001700710000000000000000000017777100000000000111000000011100000000000177771000000000000007777770
00000000017007100000000000000000000177710000000000000000000001111000000000000000000000000000000000000011110000000000000000000000
00000000001771000000000000000000000011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000007700000077000000770000007700000077000000777000007777770000000000000000000000000000000000
00000000000011000000000000000000000aa0007700000077000000777000007770000077770000777777007777770000000000000000000000000000000000
000000000001771000000000000aa00000a00a007700000077000000077000000777000000777700000777000000000000000000000000000000000000000000
00000000001700710000000000a00a000a0000a07700000007700000077000000077700000007700000000000000000000000000000000000000000000000000
00000000017000071000000000a00a000a0000a07700000007700000077700000007770000000000000000000000000000000000000000000000000000000000
000000000170000710000000000aa00000a00a007700000007700000007700000000700000000000000000000000000000000000000000000000000000000000
00000000017000071000000000000000000aa0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00111111117000710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
01777777770000710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
01700000000000710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
01700000000000071111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00170000000000007777100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00017770000000000000710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00001117000000000000710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000001700000000000710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000001700007777777710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000001700071111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000017000071000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000017000071000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000017000071000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000001700710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000177100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000