pico8-0hh1/main.lua

141 lines
2.1 KiB
Lua
Raw Normal View History

2022-05-28 11:44:09 +02:00
--
-- constants
--
local BLUE = 1
local YELLOW = 2
2022-05-29 22:55:43 +02:00
-- 🅾️ 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
2022-05-28 11:44:09 +02:00
--
-- Utils
--
2022-06-02 20:18:02 +02:00
function custom_font()
2022-06-01 21:26:57 +02:00
poke(0x5f58,0x81)
end
2022-06-02 20:18:02 +02:00
function standard_font(font)
2022-06-01 21:26:57 +02:00
poke(0x5f58,0x80)
end
2022-05-28 11:44:09 +02:00
function idx_xy(idx, width)
2022-05-28 12:34:08 +02:00
return (idx - 1) % width + 1, (idx - 1) \ width + 1
2022-05-28 11:44:09 +02:00
end
function xy_idx(x, y, width)
2022-05-28 12:34:08 +02:00
return ((y - 1) * width) + x
2022-05-28 11:44:09 +02:00
end
function map(tbl, f)
2022-05-28 12:34:08 +02:00
local t = {}
for k, v in pairs(tbl) do
t[k] = f(v)
end
return t
2022-05-28 11:44:09 +02:00
end
function filter(tbl, f, keepindex)
2022-05-28 12:34:08 +02:00
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
2022-05-28 11:44:09 +02:00
end
function slice(tbl, first, last, step)
2022-05-28 12:34:08 +02:00
local sliced = {}
for i = (first or 1), (last or #tbl), (step or 1) do
2022-05-29 14:35:28 +02:00
sliced[#sliced + 1] = tbl[i]
2022-05-28 12:34:08 +02:00
end
return sliced
2022-05-28 11:44:09 +02:00
end
2022-05-30 22:44:22 +02:00
function rectfill2(x, y, w, h, col)
rectfill(x, y, x+w, y+h, col)
end
function rect2(x, y, w, h, col)
rect(x, y, x+w, y+h, col)
2022-05-28 11:44:09 +02:00
end
2022-05-29 14:35:28 +02:00
--
-- 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
2022-05-28 11:44:09 +02:00
2022-05-28 15:02:55 +02:00
2022-05-29 14:35:28 +02:00
-- 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
2022-05-28 23:58:00 +02:00
2022-05-28 11:44:09 +02:00
--
-- main loop
--
2022-05-28 23:58:00 +02:00
local create = true
2022-05-28 11:44:09 +02:00
function _init()
2022-05-28 23:58:00 +02:00
printh(" ")
2022-07-01 19:50:08 +02:00
printh("*************")
2022-05-28 23:58:00 +02:00
printh(" ")
2022-07-01 20:20:57 +02:00
local date = stat(80)..stat(81)..stat(82)
2022-07-01 19:50:08 +02:00
-- srand(date)
2022-07-01 20:20:57 +02:00
-- srand(20227149)
2022-07-01 19:50:08 +02:00
printh(date)
2022-05-29 18:38:07 +02:00
mouse_x = 0
mouse_y = 0
2022-05-28 23:58:00 +02:00
2022-06-02 20:18:02 +02:00
frame_count = 0
2022-05-30 22:44:22 +02:00
2022-05-29 18:38:07 +02:00
states = {
2022-06-02 20:18:02 +02:00
rules = state_rules(),
menu = state_menu(),
2022-06-02 22:39:23 +02:00
game = state_game(),
loading = state_loading(),
2022-05-29 18:38:07 +02:00
}
2022-05-28 23:58:00 +02:00
2022-06-02 22:39:23 +02:00
set_state(states.loading)
2022-05-28 23:58:00 +02:00
2022-05-28 11:44:09 +02:00
end
2022-05-28 17:32:43 +02:00
function _update60()
2022-06-02 20:18:02 +02:00
frame_count += 1
2022-06-02 17:55:52 +02:00
_coresolve()
2022-05-29 18:38:07 +02:00
gs._update()
2022-05-29 14:35:28 +02:00
-- if not create then
2022-06-02 20:18:02 +02:00
-- board:solve_step()
2022-05-29 14:35:28 +02:00
-- end
2022-05-29 18:38:07 +02:00
-- mouse
mouse_x = stat(32)
mouse_y = stat(33)
2022-05-28 11:44:09 +02:00
end
function _draw()
2022-05-29 18:38:07 +02:00
gs._draw()
2022-05-29 19:49:59 +02:00
spr(1, stat(32), stat(33))
2022-05-28 11:44:09 +02:00
end