pico8-0hh1/states/loading.lua
2022-06-02 22:39:23 +02:00

108 lines
2.3 KiB
Lua

function state_loading()
local board = Board.new()
local spinner = split"-,\\,|,/"
local loading_messages = {
"lOADING PATHFINDING ALGORITHM",
"rETICULATING SPLINES",
"aLLOCATING MEMORY BANDWIDTH",
"iNITIALIZING HARDWARE",
"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",
}
local message = ""
local messages_str = ""
local messages_x = 128
local loaded = false
local create_board = cocreate(function()
repeat
board:reset()
repeat
board:solve_step(true)
yield()
until board:is_complete()
until board:is_valid()
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
break
end
board:fill(i, 0)
add(previous, board:get_tiles_copy())
-- try to solve the board
local solved = ""
yield()
repeat
solved = board:solve_step()
until board:is_complete() or solved == "invalid"
if solved == "invalid" then
deli(previous)
end
end -- end while
printh("c: " .. time())
board:set_tiles(previous[#previous])
printh(board:tostring())
printh(count(board:get_tiles_copy(), 0).." zeroes")
loaded = true
end)
local function _enter()
loaded = false
local copy_messages = copy(loading_messages)
messages_str = ""
messages_x = 128
while #copy_messages > 0 do
local m = rnd(copy_messages)
messages_str ..= m .. " "
del(copy_messages, m)
end
messages_str ..= "[END OF MESSAGES, THANK YOU FOR YOUR PATIENCE]"
custom_font()
startcoroutine(create_board)
end
local function _update()
messages_x -= 2
if loaded then
set_state(states.game, board)
end
end
local function _draw()
cls()
local l = print(message, 0, -100)
print(messages_str, messages_x, 50, 7)
print(spinner[t()\.25%4+1], 120, 120)
end
return {
_enter = _enter,
_update = _update,
_draw = _draw,
}
end