Progressive board display while loading
This commit is contained in:
parent
c5db9f717f
commit
08f35f6d0d
1
0hh1.p8
1
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
|
||||
|
|
20
board.lua
20
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
|
||||
}
|
||||
|
|
7
main.lua
7
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
|
||||
--
|
||||
|
|
|
@ -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<removing_tile and v > 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 {
|
||||
|
|
5
ui.lua
5
ui.lua
|
@ -39,3 +39,8 @@ function make_button(options)
|
|||
end
|
||||
}
|
||||
end
|
||||
|
||||
function print_shadow(text, x, y, color)
|
||||
print(text, x+1, y+1, 0)
|
||||
print(text, x, y, color)
|
||||
end
|
28
utils.lua
Normal file
28
utils.lua
Normal file
|
@ -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
|
Loading…
Reference in New Issue
Block a user