Loading & messages

This commit is contained in:
2022-06-02 22:39:23 +02:00
parent cb1c76cd2d
commit c5db9f717f
6 changed files with 145 additions and 89 deletions
+5 -48
View File
@@ -1,61 +1,18 @@
function state_game()
local board = Board.new()
local board
local selected_id = 1
local function drawSelectedTile()
local x, y = board:draw_coords(selected_id)
local w = board:get_tile_width()
fillp(▒)
rect2(x-1, y-1, w+2, w+2, 6)
fillp(█)
end
local function create_board()
printh("a: " .. time())
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")
end
local function _enter()
cocreate(create_board)
local function _enter(_board)
board = _board
end
local function _draw()
+108
View File
@@ -0,0 +1,108 @@
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