pico8-0hh1/states/game.lua

50 lines
843 B
Lua
Raw Normal View History

2022-06-02 20:18:02 +02:00
function state_game()
2022-05-29 18:38:07 +02:00
2022-06-02 22:39:23 +02:00
local board
2022-06-02 20:18:02 +02:00
local selected_id = 1
2022-06-01 23:14:22 +02:00
2022-06-02 17:55:52 +02:00
local function drawSelectedTile()
2022-06-02 20:18:02 +02:00
local x, y = board:draw_coords(selected_id)
local w = board:get_tile_width()
2022-06-02 22:39:23 +02:00
fillp()
2022-06-01 23:14:22 +02:00
rect2(x-1, y-1, w+2, w+2, 6)
2022-06-02 22:39:23 +02:00
fillp()
2022-06-01 23:14:22 +02:00
end
2022-06-02 22:39:23 +02:00
local function _enter(_board)
board = _board
2022-06-03 23:31:26 +02:00
-- lock the initial tiles
board:lock_tiles()
2022-05-29 18:38:07 +02:00
end
2022-06-01 23:14:22 +02:00
local function _draw()
2022-06-02 17:55:52 +02:00
cls()
2022-06-01 23:14:22 +02:00
board:draw()
drawSelectedTile()
end
2022-05-29 18:38:07 +02:00
2022-06-01 23:14:22 +02:00
local function _update()
2022-06-02 20:18:02 +02:00
local size = board:get_size()
local x, y = board:idx_xy(selected_id)
2022-06-01 23:14:22 +02:00
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
2022-06-02 20:18:02 +02:00
selected_id = board:xy_idx(x, y)
2022-06-01 23:14:22 +02:00
end
2022-05-29 18:38:07 +02:00
2022-06-01 23:14:22 +02:00
return {
_enter = _enter,
_update = _update,
_draw = _draw,
2022-05-29 18:38:07 +02:00
}
end