WIP showing clues

This commit is contained in:
Simon Cambier 2022-07-07 23:06:28 +02:00
parent 14fc9693bb
commit d75277a29d
7 changed files with 126 additions and 38 deletions

31
0hh1.p8
View File

@ -13,6 +13,7 @@ poke4(0x5700,unpack(split"0x0000.0000,0x0000.0000,0x0202.0202,0x0000.0200,0x0000
#include coroutines.lua #include coroutines.lua
#include ui.lua #include ui.lua
#include utils.lua #include utils.lua
#include bg.lua
#include states/menu.lua #include states/menu.lua
#include states/loading.lua #include states/loading.lua
#include states/game.lua #include states/game.lua
@ -20,21 +21,21 @@ poke4(0x5700,unpack(split"0x0000.0000,0x0000.0000,0x0202.0202,0x0000.0200,0x0000
__gfx__ __gfx__
00000000110000000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000110000000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000171000000001711000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000131000000001711000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700177100001111771100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00700700133100001111771100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000177710001777777100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00077000133310001777777100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000177771001777777100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00077000133331001777777100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700177710001111771100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00700700133310001111771100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000171771000001711000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000131331000001711000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000010171000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000010131000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 55505550505050505050505055555555000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 50555055050505050500050055555555000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 55505550505050500050505050555055000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 50555055050505050505000555555555000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 55505550505050505050505055555555000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 50555055050505050500050055000555000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 55505550505050500050505050555055000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 50555055050505050505000555555555000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

43
bg.lua Normal file
View File

@ -0,0 +1,43 @@
function draw_animated_bg(startx)
if (amplitude <= 0) return
startx = startx or 0
fillp(0b0101101001011010)
local color = 4
-- vertical lines
local t = t()+10
for i=startx-1,127,11 do
local a=sin(i*t/512)*amplitude+64
local b=cos(i*t/256)*amplitude+64
line(
i,
a,
i,
b ,
color)
end
-- horizontal lines
for i=startx-1,127,11 do
local a=sin(i*t/512)*amplitude+64
local b=cos(i*t/256)*amplitude+64
line(
a,
i,
b ,
i,
color)
end
end
local players = {
{name="alice", hp=5},
{name="anemone", hp=10},
}
local current_player = players[2]
for player in all(players) do
printh("Hello, my name is "..player.name.."and my hp is"..player.hp)
end
printh("The active player is "..current_player.name)

View File

@ -402,14 +402,19 @@ function Board.new()
end, end,
draw_bg = function(self) draw_bg = function(self)
local w = tile_width fillp()
fillp()
for k,v in ipairs(tiles) do for k,v in ipairs(tiles) do
local x,y = self:draw_coords(k) self:draw_bg_tile(k)
rectfill2(x, y, w, w, 1)
end end
end, end,
draw_bg_tile = function(self, k)
local w = tile_width
local x,y = self:draw_coords(k)
rectfill2(x+1, y, w-2, w, 1)
rectfill2(x, y+1, w, w-2, 1)
end,
draw = function(self) draw = function(self)
self:draw_bg() self:draw_bg()
local w = tile_width local w = tile_width
@ -423,15 +428,18 @@ function Board.new()
local v = tiles[idx] local v = tiles[idx]
if v > 0 then if v > 0 then
local x,y = self:draw_coords(idx) local x,y = self:draw_coords(idx)
local color = v == BLUE and 12 or 8 local color = v == BLUE and 8 or 14
if color == 1 then fillp() else fillp() end if color == 1 then fillp() else fillp() end
if self:is_locked(idx) then if self:is_locked(idx) then
rectfill2(x, y, w, w, color) rectfill2(x, y, w, w, color)
line(x, y+w-1, x+w-1, y+w-1, v == BLUE and 13 or 2) line(x, y+w-1, x+w-1, y+w-1, color-1)
line(x+w-1, y, x+w-1, y+w-1, v == BLUE and 13 or 2) line(x+w-1, y, x+w-1, y+w-1, color-1)
else else
roundedrect(x, y, w, w, color) roundedrect(x, y, w, w, color)
end end
else
fillp()
self:draw_bg_tile(idx)
end end
end, end,
} }

1
globals.lua Normal file
View File

@ -0,0 +1 @@
local amplitude = 128

View File

@ -104,6 +104,9 @@ end
local create = true local create = true
function _init() function _init()
pal({[0]=0,128,132,7,136,8,14,137,9,10,131,3,11,1,140,12},1)
poke(0x5f2e,1) --to keep colors
printh(" ") printh(" ")
printh("*************") printh("*************")
printh(" ") printh(" ")

View File

@ -4,23 +4,26 @@ function state_game()
local selected_id = 1 local selected_id = 1
local timer_clue = 0 local timer_clue = 0
local clues = {}
local function show_clues() local function show_clues()
local issues = board:get_issues(true) local issues = board:get_issues(true)
clues = {}
for issue in all(issues) do for issue in all(issues) do
local type, err, row, pos, other = unpack(issue) local type, err, row, pos, other = unpack(issue)
if err == "identical" and count(row,0)>0 then
goto continue
end
printh(type .. " " .. err .. " " .. pos) 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
end end
local function draw_selected_tile() local function draw_selected_tile()
local x, y = board:draw_coords(selected_id) local x, y = board:draw_coords(selected_id)
local w = board:get_tile_width() local w = board:get_tile_width()
fillp() -- fillp(▒)
rect2(x-1, y-1, w+2, w+2, 6) rect2(x-1, y-1, w+1, w+1, 6)
line()
fillp() fillp()
end end
@ -36,15 +39,33 @@ function state_game()
local function _draw() local function _draw()
cls() cls()
local x,y = board:draw_coords(1)
draw_animated_bg(x)
board:draw() board:draw()
draw_selected_tile() 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 end
local function _update() local function _update()
timer_clue += 1
if timer_clue % 120 == 0 then
show_clues()
end
local size = board:get_size() local size = board:get_size()
local x, y = board:idx_xy(selected_id) local x, y = board:idx_xy(selected_id)
if btnp(UP) then if btnp(UP) then
@ -59,6 +80,7 @@ function state_game()
if btnp(BTN_O) then if btnp(BTN_O) then
board:try_flip_tile(selected_id) board:try_flip_tile(selected_id)
show_clues()
end end
if (x<1) x=size if (x<1) x=size

View File

@ -58,12 +58,22 @@ function state_loading()
yield() yield()
repeat repeat
solved = board:solve_step() solved = board:solve_step()
if solved == "valid" then
amplitude -= .125
end
until board:is_complete() or solved == "invalid" until board:is_complete() or solved == "invalid"
if solved == "invalid" then if solved == "invalid" then
deli(previous) deli(previous)
end end
end -- end while end -- end while
printh("board generated in "..time()-start.." seconds") printh("board generated in "..time()-start.." seconds")
startcoroutine(cocreate(function()
repeat
amplitude -= .5
yield()
until amplitude <= 0
end))
board:set_tiles(previous[#previous]) board:set_tiles(previous[#previous])
printh(board:tostring()) printh(board:tostring())
@ -73,7 +83,6 @@ function state_loading()
end) end)
local function draw_tiles(board) local function draw_tiles(board)
local w = board:get_size() local w = board:get_size()
local tiles = board:get_tiles_copy() local tiles = board:get_tiles_copy()
for k,v in ipairs(tiles) do for k,v in ipairs(tiles) do
@ -84,6 +93,7 @@ function state_loading()
end end
local function _enter() local function _enter()
amplitude = 64
loaded = false loaded = false
local copy_messages = copy(loading_messages) local copy_messages = copy(loading_messages)
@ -109,19 +119,19 @@ function state_loading()
end end
end end
local function _draw() local function _draw()
cls() cls()
board:draw_bg() local x,y = board:draw_coords(1)
draw_animated_bg(x)
-- board:draw_bg()
draw_tiles(board) draw_tiles(board)
local s = board:get_size()*board:get_size() local s = board:get_size()*board:get_size()
local l = print(message, 0, -100) local l = print(message, 0, -100)
local y = 118+(removing_tile/s)*100/8 local y = 118+(removing_tile/s)*100/8
local colors = {7,6,5,5}
local ci = removing_tile\20+1 local ci = removing_tile\20+1
local c = colors[ci]
if not loaded then if not loaded then
rectfill2(0,y-2,127,10,0) 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) -- print(spinner[t()\.25%4+1], 120, 120)
end end
end end