From 08f35f6d0d92757eae61be22f2b86b2fc08d42ec Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Fri, 3 Jun 2022 21:09:45 +0200 Subject: [PATCH] Progressive board display while loading --- 0hh1.p8 | 1 + board.lua | 20 +++++++++++++---- main.lua | 7 ------ states/loading.lua | 54 ++++++++++++++++++++++++++++++---------------- ui.lua | 5 +++++ utils.lua | 28 ++++++++++++++++++++++++ 6 files changed, 85 insertions(+), 30 deletions(-) create mode 100644 utils.lua diff --git a/0hh1.p8 b/0hh1.p8 index 89ea964..f0c1904 100644 --- a/0hh1.p8 +++ b/0hh1.p8 @@ -12,6 +12,7 @@ poke4(0x5700,unpack(split"0x0000.0000,0x0000.0000,0x0202.0202,0x0000.0200,0x0000 #include board.lua #include coroutines.lua #include ui.lua +#include utils.lua #include states/menu.lua #include states/loading.lua #include states/game.lua diff --git a/board.lua b/board.lua index 8ae2e08..a4cd080 100644 --- a/board.lua +++ b/board.lua @@ -384,13 +384,25 @@ function Board.new() end end, - draw = function(self) + draw_bg = function(self) local w = width + fillp(▒) for k,v in ipairs(tiles) do local x,y = self:draw_coords(k) - local color = v == BLUE and 12 or v == YELLOW and 8 or 1 - if color == 1 then fillp(▒) else fillp(█) end - rectfill2(x, y, w, w, color) + rectfill2(x, y, w, w, 1) + end + end, + + draw = function(self) + self:draw_bg() + local w = width + for k,v in ipairs(tiles) do + if v > 0 then + local x,y = self:draw_coords(k) + local color = v == BLUE and 12 or 8 + if color == 1 then fillp(▒) else fillp(█) end + rectfill2(x, y, w, w, color) + end end end } diff --git a/main.lua b/main.lua index 559d687..00611e6 100644 --- a/main.lua +++ b/main.lua @@ -118,13 +118,6 @@ end -- end -function set_state(state, ...) - local args = {...} - if gs and gs._leave then gs._leave() end - gs = state - if gs and gs._enter then gs._enter(unpack(args)) end -end - -- -- main loop -- diff --git a/states/loading.lua b/states/loading.lua index 6291ca2..d558535 100644 --- a/states/loading.lua +++ b/states/loading.lua @@ -3,26 +3,24 @@ function state_loading() local spinner = split"-,\\,|,/" local loading_messages = { - "lOADING PATHFINDING ALGORITHM", "rETICULATING SPLINES", - "aLLOCATING MEMORY BANDWIDTH", - "iNITIALIZING HARDWARE", + "aLLOCATING RESSOURCES", + "eMULATING HARDWARE", + "uNCLOGGING MEMORY BUS", "sPINNING UP ai AGENT", - "PINGING aZURE AGENT POOL", "bOOTING VIRTUAL MACHINE", - "cOUNTING PIXELS", - "cOLORING TILES", - "tIP: THIS GAME RUNS BETTER ON iNTERNET eXPLORER 6", - "lOADING A NEW BOARD", - "iF YOU CAN'T SOLVE A BOARD, ASK HELP FROM AN ADULT", - "lOADING RAY-TRACING SETTINGS", - "aDJUSTING DIFFICULTY FOR YOUR PLAY STYLE", + "cOLLECTING PIXELS TO BUILD TILES", + "lOADING RAY-TRACING ALGORITHM", + "sWEEPING PARTICLES", + "pRESSURIZING USER INTERFACE", + "rECOMPUTING BOARD MATRIX" } local message = "" local messages_str = "" local messages_x = 128 local loaded = false + local removing_tile = 0 local create_board = cocreate(function() repeat @@ -36,18 +34,17 @@ function state_loading() printh("b: " .. time()) -- Remove tiles until randomness is unavoidable local previous = {board:get_tiles_copy()} -- initial state - local i = 0 while true do board:set_tiles(previous[#previous]) -- remove a random tile repeat - i += 1 - until i == 100 or board:get_tiles_copy()[i] ~= 0 - if i == 100 then + removing_tile += 1 + until removing_tile == 100 or board:get_tiles_copy()[iremoving_tile] ~= 0 + if removing_tile == 100 then break end - board:fill(i, 0) + board:fill(removing_tile, 0) add(previous, board:get_tiles_copy()) -- try to solve the board @@ -69,6 +66,19 @@ function state_loading() loaded = true end) + local function draw_tiles(board) + local w = board:get_size() + local tiles = board:get_tiles_copy() + for k,v in ipairs(tiles) do + if k 0 then + local x,y = board:draw_coords(k) + local color = v == BLUE and 12 or 8 + if color == 1 then fillp(▒) else fillp(█) end + rectfill2(x, y, w, w, color) + end + end + end + local function _enter() loaded = false @@ -80,7 +90,7 @@ function state_loading() messages_str ..= m .. " " del(copy_messages, m) end - messages_str ..= "[END OF MESSAGES, THANK YOU FOR YOUR PATIENCE]" + messages_str ..= "tHANK YOU FOR YOUR PATIENCE" custom_font() startcoroutine(create_board) @@ -95,9 +105,15 @@ function state_loading() local function _draw() cls() + + board:draw_bg() + draw_tiles(board) + local l = print(message, 0, -100) - print(messages_str, messages_x, 50, 7) - print(spinner[t()\.25%4+1], 120, 120) + if not loaded then + print(messages_str, messages_x, 50, 7, 0) + -- print(spinner[t()\.25%4+1], 120, 120) + end end return { diff --git a/ui.lua b/ui.lua index 4cb68b1..f80fb48 100644 --- a/ui.lua +++ b/ui.lua @@ -38,4 +38,9 @@ function make_button(options) end end } +end + +function print_shadow(text, x, y, color) + print(text, x+1, y+1, 0) + print(text, x, y, color) end \ No newline at end of file diff --git a/utils.lua b/utils.lua new file mode 100644 index 0000000..52b79e5 --- /dev/null +++ b/utils.lua @@ -0,0 +1,28 @@ +local oldprint = print +function print(t,x,y,col1,col2) + if col2 then + for i=-1,1 do + for j=-1,1 do + oldprint(t, x+i, y+j, col2) + end + end + end + oldprint(t, x, y, col1) +end + +function str_width(str) + return print(str,0,-8) +end + +function print_shade(t,x,y,col1,col2) + print(t,x,y+1,col2) + print(t,x+1,y+1,col2) + print(t,x,y,col1) +end + +function set_state(state, ...) + local args = {...} + if gs and gs._leave then gs._leave() end + gs = state + if gs and gs._enter then gs._enter(unpack(args)) end +end \ No newline at end of file