Navigating the board

This commit is contained in:
2022-06-01 23:14:22 +02:00
parent 17c7de2240
commit 65871f1789
4 changed files with 62 additions and 25 deletions
+36 -8
View File
@@ -1,7 +1,15 @@
function stateGame()
local board = Board.new()
function _enter()
local selectedId = 1
function drawSelectedTile()
local x, y = board:draw_coords(selectedId)
local w = board:getTileWidth()
rect2(x-1, y-1, w+2, w+2, 6)
end
local function _enter()
-- Create a board
repeat
board:reset()
@@ -41,14 +49,34 @@ function stateGame()
printh(board:tostring())
end
local function _draw()
board:draw()
drawSelectedTile()
end
local function _update()
local size = board:getSize()
local x, y = board:idx_xy(selectedId)
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
printh(x.." "..y)
if (x<1) x=size
if (x>size) x=1
if (y<1) y=size
if (y>size) y=1
selectedId = board:xy_idx(x, y)
end
return {
_enter = _enter,
_update = function()
end,
_draw = function()
board:draw()
end,
_update = _update,
_draw = _draw,
}
end
+2 -2
View File
@@ -1,7 +1,7 @@
function stateMenu()
local selected = 1
function onBtnDraw(btn)
local function onBtnDraw(btn)
if selected == btn.data.i then
btn.color = 7
end
@@ -18,7 +18,7 @@ function stateMenu()
onDraw=onBtnDraw})
}
function _enter()
local function _enter()
end
+2 -2
View File
@@ -3,11 +3,11 @@ function stateRules()
local fade = split"0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,4,9,10,9,4,2,1"
local color = 1
function blink(x,y,w,h)
local function blink(x,y,w,h)
rect2(x,y,w,h,fade[color])
end
function goBack()
local function goBack()
setState(states.menu)
end