50 lines
843 B
Lua
50 lines
843 B
Lua
function state_game()
|
|
|
|
local board
|
|
local selected_id = 1
|
|
|
|
local function drawSelectedTile()
|
|
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()
|
|
drawSelectedTile()
|
|
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 (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 |