Click to switch tiles
This commit is contained in:
+27
-3
@@ -22,11 +22,26 @@ function state_game()
|
||||
local x, y = board:draw_coords(selected_id)
|
||||
local w = board:get_tile_width()
|
||||
-- fillp(▒)
|
||||
rect2(x-1, y-1, w+1, w+1, 6)
|
||||
rect2(x-1, y-1, w, w, 6)
|
||||
line()
|
||||
fillp(█)
|
||||
end
|
||||
|
||||
local mx,mx = 0,0
|
||||
local function update_mouse()
|
||||
-- update mouse position
|
||||
if mx == mouse_x and my == mouse_y then return end
|
||||
mx,my = mouse_x, mouse_y
|
||||
local board_x, board_y = board:draw_coords(1)
|
||||
local tw = board:get_tile_width()
|
||||
local bw = board:get_size()
|
||||
-- pixels coords to grid coords
|
||||
local x = mid(1, (mouse_x - board_x) \ tw + 1, bw)
|
||||
local y = mid(1, (mouse_y - board_y) \ tw + 1, bw)
|
||||
selected_id = board:xy_idx(x,y)
|
||||
printh("x: " .. x .. " y: " .. y .. " id: " .. selected_id)
|
||||
end
|
||||
|
||||
local function _enter(_board)
|
||||
board = _board
|
||||
-- lock the initial tiles
|
||||
@@ -68,26 +83,35 @@ function state_game()
|
||||
local function _update()
|
||||
local size = board:get_size()
|
||||
local x, y = board:idx_xy(selected_id)
|
||||
local moved = false
|
||||
if btnp(UP) then
|
||||
moved = true
|
||||
y -= 1
|
||||
elseif btnp(DOWN) then
|
||||
moved = true
|
||||
y += 1
|
||||
elseif btnp(LEFT) then
|
||||
moved = true
|
||||
x -= 1
|
||||
elseif btnp(RIGHT) then
|
||||
moved = true
|
||||
x += 1
|
||||
end
|
||||
if moved then
|
||||
selected_id = board:xy_idx(x, y)
|
||||
end
|
||||
|
||||
if btnp(BTN_O) then
|
||||
if btnp(BTN_X) then
|
||||
board:try_flip_tile(selected_id)
|
||||
show_clues()
|
||||
end
|
||||
|
||||
update_mouse()
|
||||
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user