pico8-0hh1/states/game.lua

55 lines
913 B
Lua

function state_game()
local board
local selected_id = 1
local function draw_selected_tile()
local x, y = board:draw_coords(selected_id)
local w = board:get_tile_width()
fillp()
rect2(x-1, y-1, w+2, w+2, 6)
fillp()
end
local function _enter(_board)
board = _board
-- lock the initial tiles
board:lock_tiles()
end
local function _draw()
cls()
board:draw()
draw_selected_tile()
end
local function _update()
local size = board:get_size()
local x, y = board:idx_xy(selected_id)
if btnp(UP) then
y -= 1
elseif btnp(DOWN) then
y += 1
elseif btnp(LEFT) then
x -= 1
elseif btnp(RIGHT) then
x += 1
end
if btnp(BTN_O) then
board:try_flip_tile(selected_id)
end
if (x<1) x=size
if (x>size) x=1
if (y<1) y=size
if (y>size) y=1
selected_id = board:xy_idx(x, y)
end
return {
_enter = _enter,
_update = _update,
_draw = _draw,
}
end