pico8-0hh1/main.lua

138 lines
2.2 KiB
Lua
Raw Normal View History

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)
2022-07-02 13:52:31 +02:00
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)
2022-05-30 22:44:22 +02:00
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
--
function _init()
2022-07-08 22:47:26 +02:00
-- pal({[0]=0,128,132,7,136,8,14,137,9,10,131,3,11,1,140,12},1)
-- poke(0x5f2e,1) --to keep colors
2022-07-07 23:06:28 +02:00
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-03 19:09:15 +02:00
local date = stat(80)..stat(81)..stat(82)..stat(84)..stat(85)
srand(date)
printh("seed " .. date)
2022-07-10 16:39:11 +02:00
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
loading = state_loading(),
2022-07-12 21:47:10 +02:00
game = state_game(),
endgame = state_endgame(),
2022-05-29 18:38:07 +02:00
}
2022-05-28 23:58:00 +02:00
2022-07-12 21:47:10 +02:00
set_state(states.menu)
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-05-29 18:38:07 +02:00
2022-07-10 16:39:11 +02:00
-- update mouse coords
2022-05-29 18:38:07 +02:00
mouse_x = stat(32)
mouse_y = stat(33)
2022-07-12 21:47:10 +02:00
_coresolve()
gs._update()
2022-05-28 11:44:09 +02:00
end
function _draw()
2022-05-29 18:38:07 +02:00
gs._draw()
2022-07-12 21:47:10 +02:00
for overlay in all(overlays) do
overlay:_draw()
end
2023-02-23 08:14:29 +01:00
-- mouse cursor
spr(1, mouse_x, mouse_y)
2022-05-28 11:44:09 +02:00
end