147 lines
2.3 KiB
Lua
147 lines
2.3 KiB
Lua
--
|
|
-- constants
|
|
--
|
|
|
|
local BLUE = 1
|
|
local YELLOW = 2
|
|
|
|
-- 🅾️ Z[C]N ❎ [X]VM
|
|
-- X and C have the same position on QWERTY and AZERTY
|
|
local LEFT,RIGHT,UP,DOWN,BTN_O,BTN_X = 0,1,2,3,4,5
|
|
|
|
--
|
|
-- Utils
|
|
--
|
|
|
|
function custom_font()
|
|
poke(0x5f58,0x81)
|
|
end
|
|
|
|
function standard_font(font)
|
|
poke(0x5f58,0x80)
|
|
end
|
|
|
|
function idx_xy(idx, width)
|
|
return (idx - 1) % width + 1, (idx - 1) \ width + 1
|
|
end
|
|
|
|
function xy_idx(x, y, width)
|
|
return ((y - 1) * width) + x
|
|
end
|
|
|
|
function map(tbl, f)
|
|
local t = {}
|
|
for k, v in pairs(tbl) do
|
|
t[k] = f(v)
|
|
end
|
|
return t
|
|
end
|
|
|
|
function filter(tbl, f, keepindex)
|
|
local ret = {}
|
|
for k, v in pairs(tbl) do
|
|
if f(v) then
|
|
if keepindex
|
|
then ret[k] = v
|
|
else add(ret, v)
|
|
end
|
|
end
|
|
end
|
|
return ret
|
|
end
|
|
|
|
function slice(tbl, first, last, step)
|
|
local sliced = {}
|
|
for i = (first or 1), (last or #tbl), (step or 1) do
|
|
sliced[#sliced + 1] = tbl[i]
|
|
end
|
|
return sliced
|
|
end
|
|
|
|
function rectfill2(x, y, w, h, col)
|
|
rectfill(x, y, x+w-1, y+h-1, col)
|
|
end
|
|
|
|
function roundedrect(x, y, w, h, col)
|
|
rectfill2(x,y,w,h,0)
|
|
rectfill2(x+1, y, w-2, h, col)
|
|
rectfill2(x, y+1, w, h-2, col)
|
|
end
|
|
|
|
function rect2(x, y, w, h, col)
|
|
rect(x, y, x+w, y+h, col)
|
|
end
|
|
|
|
--
|
|
-- Overrides count() to accept a callback
|
|
--
|
|
-- local _count = count
|
|
-- function count(tbl, p)
|
|
-- if type(p) != "function" then return _count(tbl, p) end
|
|
-- local c = 0
|
|
-- for v in all(tbl) do
|
|
-- if p(v) then c+=1 end
|
|
-- end
|
|
-- return c
|
|
-- end
|
|
|
|
|
|
-- function tostring(any)
|
|
-- if (type(any)~="table") return tostr(any)
|
|
-- local str = "{"
|
|
-- for k,v in pairs(any) do
|
|
-- if (str~="{") str=str..","
|
|
-- str=str..tostring(k).."="..tostring(v)
|
|
-- end
|
|
-- return str.."}"
|
|
-- end
|
|
|
|
|
|
--
|
|
-- main loop
|
|
--
|
|
|
|
local create = true
|
|
|
|
function _init()
|
|
printh(" ")
|
|
printh("*************")
|
|
printh(" ")
|
|
local date = stat(80)..stat(81)..stat(82)
|
|
-- srand(date)
|
|
-- srand(20227149)
|
|
printh(date)
|
|
mouse_x = 0
|
|
mouse_y = 0
|
|
|
|
frame_count = 0
|
|
|
|
states = {
|
|
rules = state_rules(),
|
|
menu = state_menu(),
|
|
game = state_game(),
|
|
loading = state_loading(),
|
|
}
|
|
|
|
set_state(states.loading)
|
|
|
|
end
|
|
|
|
function _update60()
|
|
frame_count += 1
|
|
_coresolve()
|
|
gs._update()
|
|
-- if not create then
|
|
-- board:solve_step()
|
|
-- end
|
|
|
|
-- mouse
|
|
mouse_x = stat(32)
|
|
mouse_y = stat(33)
|
|
end
|
|
|
|
function _draw()
|
|
gs._draw()
|
|
spr(1, stat(32), stat(33))
|
|
end
|