WIP showing clues

This commit is contained in:
2022-07-07 23:06:28 +02:00
parent 14fc9693bb
commit d75277a29d
7 changed files with 126 additions and 38 deletions
+32 -10
View File
@@ -4,23 +4,26 @@ function state_game()
local selected_id = 1
local timer_clue = 0
local clues = {}
local function show_clues()
local issues = board:get_issues(true)
clues = {}
for issue in all(issues) do
local type, err, row, pos, other = unpack(issue)
if err == "identical" and count(row,0)>0 then
goto continue
end
printh(type .. " " .. err .. " " .. pos)
::continue::
add(clues, {type=type, pos=pos, t=0})
if err == "identical" then
add(clues, {type=type, pos=other, t=0})
end
end
end
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(▒)
rect2(x-1, y-1, w+1, w+1, 6)
line()
fillp(█)
end
@@ -36,15 +39,33 @@ function state_game()
local function _draw()
cls()
local x,y = board:draw_coords(1)
draw_animated_bg(x)
board:draw()
draw_selected_tile()
-- draw clues
for clue in all(clues) do
palt(0,false)
palt(5,true)
local x,y
if clue.type == "row" then
x,y = board:draw_coords((clue.pos-1) * board:get_size()+1)
x=0
spr(19, x+clue.t%144, y+1+sin(t())*2)
else -- col
x,y = board:draw_coords(clue.pos)
spr(19, x+2+sin(t())*2, y+clue.t%144)
y=0
end
pset(x, y, 5)
clue.t += 1
end
palt()
end
local function _update()
timer_clue += 1
if timer_clue % 120 == 0 then
show_clues()
end
local size = board:get_size()
local x, y = board:idx_xy(selected_id)
if btnp(UP) then
@@ -59,6 +80,7 @@ function state_game()
if btnp(BTN_O) then
board:try_flip_tile(selected_id)
show_clues()
end
if (x<1) x=size
+16 -6
View File
@@ -58,12 +58,22 @@ function state_loading()
yield()
repeat
solved = board:solve_step()
if solved == "valid" then
amplitude -= .125
end
until board:is_complete() or solved == "invalid"
if solved == "invalid" then
deli(previous)
end
end -- end while
printh("board generated in "..time()-start.." seconds")
startcoroutine(cocreate(function()
repeat
amplitude -= .5
yield()
until amplitude <= 0
end))
board:set_tiles(previous[#previous])
printh(board:tostring())
@@ -73,7 +83,6 @@ function state_loading()
end)
local function draw_tiles(board)
local w = board:get_size()
local tiles = board:get_tiles_copy()
for k,v in ipairs(tiles) do
@@ -84,6 +93,7 @@ function state_loading()
end
local function _enter()
amplitude = 64
loaded = false
local copy_messages = copy(loading_messages)
@@ -109,19 +119,19 @@ function state_loading()
end
end
local function _draw()
local function _draw()
cls()
board:draw_bg()
local x,y = board:draw_coords(1)
draw_animated_bg(x)
-- board:draw_bg()
draw_tiles(board)
local s = board:get_size()*board:get_size()
local l = print(message, 0, -100)
local y = 118+(removing_tile/s)*100/8
local colors = {7,6,5,5}
local ci = removing_tile\20+1
local c = colors[ci]
if not loaded then
rectfill2(0,y-2,127,10,0)
print(messages_str, messages_x, y, c, 0)
print(messages_str, messages_x, y, 3, 0)
-- print(spinner[t()\.25%4+1], 120, 120)
end
end