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 board.lua
|
||||||
#include coroutines.lua
|
#include coroutines.lua
|
||||||
#include ui.lua
|
#include ui.lua
|
||||||
|
#include utils.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
|
||||||
|
|
16
board.lua
16
board.lua
|
@ -384,14 +384,26 @@ function Board.new()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
draw = function(self)
|
draw_bg = function(self)
|
||||||
local w = width
|
local w = width
|
||||||
|
fillp(▒)
|
||||||
for k,v in ipairs(tiles) do
|
for k,v in ipairs(tiles) do
|
||||||
local x,y = self:draw_coords(k)
|
local x,y = self:draw_coords(k)
|
||||||
local color = v == BLUE and 12 or v == YELLOW and 8 or 1
|
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
|
if color == 1 then fillp(▒) else fillp(█) end
|
||||||
rectfill2(x, y, w, w, color)
|
rectfill2(x, y, w, w, color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
7
main.lua
7
main.lua
|
@ -118,13 +118,6 @@ end
|
||||||
-- 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
|
-- main loop
|
||||||
--
|
--
|
||||||
|
|
|
@ -3,26 +3,24 @@ function state_loading()
|
||||||
|
|
||||||
local spinner = split"-,\\,|,/"
|
local spinner = split"-,\\,|,/"
|
||||||
local loading_messages = {
|
local loading_messages = {
|
||||||
"lOADING PATHFINDING ALGORITHM",
|
|
||||||
"rETICULATING SPLINES",
|
"rETICULATING SPLINES",
|
||||||
"aLLOCATING MEMORY BANDWIDTH",
|
"aLLOCATING RESSOURCES",
|
||||||
"iNITIALIZING HARDWARE",
|
"eMULATING HARDWARE",
|
||||||
|
"uNCLOGGING MEMORY BUS",
|
||||||
"sPINNING UP ai AGENT",
|
"sPINNING UP ai AGENT",
|
||||||
"PINGING aZURE AGENT POOL",
|
|
||||||
"bOOTING VIRTUAL MACHINE",
|
"bOOTING VIRTUAL MACHINE",
|
||||||
"cOUNTING PIXELS",
|
"cOLLECTING PIXELS TO BUILD TILES",
|
||||||
"cOLORING TILES",
|
"lOADING RAY-TRACING ALGORITHM",
|
||||||
"tIP: THIS GAME RUNS BETTER ON iNTERNET eXPLORER 6",
|
"sWEEPING PARTICLES",
|
||||||
"lOADING A NEW BOARD",
|
"pRESSURIZING USER INTERFACE",
|
||||||
"iF YOU CAN'T SOLVE A BOARD, ASK HELP FROM AN ADULT",
|
"rECOMPUTING BOARD MATRIX"
|
||||||
"lOADING RAY-TRACING SETTINGS",
|
|
||||||
"aDJUSTING DIFFICULTY FOR YOUR PLAY STYLE",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local message = ""
|
local message = ""
|
||||||
local messages_str = ""
|
local messages_str = ""
|
||||||
local messages_x = 128
|
local messages_x = 128
|
||||||
local loaded = false
|
local loaded = false
|
||||||
|
local removing_tile = 0
|
||||||
|
|
||||||
local create_board = cocreate(function()
|
local create_board = cocreate(function()
|
||||||
repeat
|
repeat
|
||||||
|
@ -36,18 +34,17 @@ function state_loading()
|
||||||
printh("b: " .. time())
|
printh("b: " .. time())
|
||||||
-- Remove tiles until randomness is unavoidable
|
-- Remove tiles until randomness is unavoidable
|
||||||
local previous = {board:get_tiles_copy()} -- initial state
|
local previous = {board:get_tiles_copy()} -- initial state
|
||||||
local i = 0
|
|
||||||
while true do
|
while true do
|
||||||
board:set_tiles(previous[#previous])
|
board:set_tiles(previous[#previous])
|
||||||
-- remove a random tile
|
-- remove a random tile
|
||||||
repeat
|
repeat
|
||||||
i += 1
|
removing_tile += 1
|
||||||
until i == 100 or board:get_tiles_copy()[i] ~= 0
|
until removing_tile == 100 or board:get_tiles_copy()[iremoving_tile] ~= 0
|
||||||
if i == 100 then
|
if removing_tile == 100 then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
board:fill(i, 0)
|
board:fill(removing_tile, 0)
|
||||||
add(previous, board:get_tiles_copy())
|
add(previous, board:get_tiles_copy())
|
||||||
|
|
||||||
-- try to solve the board
|
-- try to solve the board
|
||||||
|
@ -69,6 +66,19 @@ function state_loading()
|
||||||
loaded = true
|
loaded = true
|
||||||
end)
|
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()
|
local function _enter()
|
||||||
loaded = false
|
loaded = false
|
||||||
|
|
||||||
|
@ -80,7 +90,7 @@ function state_loading()
|
||||||
messages_str ..= m .. " "
|
messages_str ..= m .. " "
|
||||||
del(copy_messages, m)
|
del(copy_messages, m)
|
||||||
end
|
end
|
||||||
messages_str ..= "[END OF MESSAGES, THANK YOU FOR YOUR PATIENCE]"
|
messages_str ..= "tHANK YOU FOR YOUR PATIENCE"
|
||||||
|
|
||||||
custom_font()
|
custom_font()
|
||||||
startcoroutine(create_board)
|
startcoroutine(create_board)
|
||||||
|
@ -95,9 +105,15 @@ function state_loading()
|
||||||
|
|
||||||
local function _draw()
|
local function _draw()
|
||||||
cls()
|
cls()
|
||||||
|
|
||||||
|
board:draw_bg()
|
||||||
|
draw_tiles(board)
|
||||||
|
|
||||||
local l = print(message, 0, -100)
|
local l = print(message, 0, -100)
|
||||||
print(messages_str, messages_x, 50, 7)
|
if not loaded then
|
||||||
print(spinner[t()\.25%4+1], 120, 120)
|
print(messages_str, messages_x, 50, 7, 0)
|
||||||
|
-- print(spinner[t()\.25%4+1], 120, 120)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
5
ui.lua
5
ui.lua
|
@ -39,3 +39,8 @@ function make_button(options)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
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