Fluff
This commit is contained in:
parent
08f35f6d0d
commit
6d1f8bbc8b
36
board.lua
36
board.lua
|
@ -6,6 +6,8 @@ function Board.new()
|
|||
local tile_width = 10
|
||||
local margin = 4
|
||||
local padding = 1
|
||||
local tiles = {}
|
||||
local locked = {} -- list of indexes
|
||||
|
||||
local reset = function()
|
||||
local t = [[
|
||||
|
@ -21,6 +23,7 @@ function Board.new()
|
|||
0,0,0,0,0,0,0,0,0,0
|
||||
]]
|
||||
tiles = split(t)
|
||||
locked = {}
|
||||
end
|
||||
|
||||
reset()
|
||||
|
@ -384,6 +387,17 @@ function Board.new()
|
|||
end
|
||||
end,
|
||||
|
||||
lock_tiles = function(self)
|
||||
locked = {}
|
||||
for k,v in ipairs(tiles) do
|
||||
if v > 0 then add(locked, k) end
|
||||
end
|
||||
end,
|
||||
|
||||
is_locked = function(self, idx)
|
||||
return #find(locked, idx) > 0
|
||||
end,
|
||||
|
||||
draw_bg = function(self)
|
||||
local w = width
|
||||
fillp(▒)
|
||||
|
@ -397,13 +411,23 @@ function Board.new()
|
|||
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)
|
||||
self:draw_tile(k)
|
||||
end
|
||||
end,
|
||||
|
||||
draw_tile = function(self, idx)
|
||||
local w = width
|
||||
local v = tiles[idx]
|
||||
if v > 0 then
|
||||
local x,y = self:draw_coords(idx)
|
||||
local color = v == BLUE and 12 or 8
|
||||
if color == 1 then fillp(▒) else fillp(█) end
|
||||
rectfill2(x, y, w, w, color)
|
||||
if self:is_locked(idx) then
|
||||
line(x, y+w, x+w, y+w, v == BLUE and 6 or 14)
|
||||
line(x+w, y, x+w, y+w, v == BLUE and 6 or 14)
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
}
|
||||
end
|
27
main.lua
27
main.lua
|
@ -79,33 +79,6 @@ end
|
|||
-- return c
|
||||
-- end
|
||||
|
||||
--
|
||||
-- Returns the indices of found occurences of `o` within `tbl`
|
||||
--
|
||||
function find(tbl, o)
|
||||
local indices = {}
|
||||
for k,v in ipairs(tbl) do
|
||||
if v == o then add(indices, k) end
|
||||
end
|
||||
return indices
|
||||
end
|
||||
|
||||
--
|
||||
-- Makes a shallow table copy
|
||||
--
|
||||
function copy(tbl)
|
||||
return map(tbl, function (o) return o end)
|
||||
end
|
||||
|
||||
--
|
||||
-- Table equality - shallow comparison
|
||||
--
|
||||
function equal(tbl1, tbl2)
|
||||
for k, _ in ipairs(tbl1) do
|
||||
if tbl1[k] ~= tbl2[k] then return false end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- function tostring(any)
|
||||
-- if (type(any)~="table") return tostr(any)
|
||||
|
|
|
@ -13,6 +13,8 @@ function state_game()
|
|||
|
||||
local function _enter(_board)
|
||||
board = _board
|
||||
-- lock the initial tiles
|
||||
board:lock_tiles()
|
||||
end
|
||||
|
||||
local function _draw()
|
||||
|
|
|
@ -8,12 +8,14 @@ function state_loading()
|
|||
"eMULATING HARDWARE",
|
||||
"uNCLOGGING MEMORY BUS",
|
||||
"sPINNING UP ai AGENT",
|
||||
"bOOTING VIRTUAL MACHINE",
|
||||
"cOLLECTING PIXELS TO BUILD TILES",
|
||||
"lOADING RAY-TRACING ALGORITHM",
|
||||
"sIDE-STEPPING VIRTUAL MACHINE",
|
||||
"iNSTALLING BACKTRACKING WIZARD",
|
||||
"eXFOLIATING PIXELS",
|
||||
"sCAFFOLDING RAY-TRACING ALGORITHM",
|
||||
"sWEEPING PARTICLES",
|
||||
"pRESSURIZING USER INTERFACE",
|
||||
"rECOMPUTING BOARD MATRIX"
|
||||
"sERIALIZING BOARD MATRIX",
|
||||
"bACKPORTING e2e ENCRYPTION",
|
||||
}
|
||||
|
||||
local message = ""
|
||||
|
@ -32,14 +34,16 @@ function state_loading()
|
|||
until board:is_valid()
|
||||
|
||||
printh("b: " .. time())
|
||||
-- Remove tiles until randomness is unavoidable
|
||||
|
||||
-- Remove tiles that can be removed
|
||||
local previous = {board:get_tiles_copy()} -- initial state
|
||||
while true do
|
||||
|
||||
board:set_tiles(previous[#previous])
|
||||
-- remove a random tile
|
||||
repeat
|
||||
removing_tile += 1
|
||||
until removing_tile == 100 or board:get_tiles_copy()[iremoving_tile] ~= 0
|
||||
until removing_tile == 100 or board:get_tiles_copy()[removing_tile] ~= 0
|
||||
if removing_tile == 100 then
|
||||
break
|
||||
end
|
||||
|
@ -67,14 +71,12 @@ function state_loading()
|
|||
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)
|
||||
if k < removing_tile then
|
||||
board:draw_tile(k)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -97,7 +99,9 @@ function state_loading()
|
|||
end
|
||||
|
||||
local function _update()
|
||||
messages_x -= 2
|
||||
board:lock_tiles()
|
||||
|
||||
messages_x -= 5
|
||||
if loaded then
|
||||
set_state(states.game, board)
|
||||
end
|
||||
|
@ -105,13 +109,17 @@ function state_loading()
|
|||
|
||||
local function _draw()
|
||||
cls()
|
||||
|
||||
board:draw_bg()
|
||||
draw_tiles(board)
|
||||
|
||||
local l = print(message, 0, -100)
|
||||
local y = 118+removing_tile/8
|
||||
local colors = {7,6,5,5}
|
||||
local ci = removing_tile\20+1
|
||||
local c = colors[ci]
|
||||
if not loaded then
|
||||
print(messages_str, messages_x, 50, 7, 0)
|
||||
rectfill2(0,y-2,127,10,0)
|
||||
print(messages_str, messages_x, y, c, 0)
|
||||
-- print(spinner[t()\.25%4+1], 120, 120)
|
||||
end
|
||||
end
|
||||
|
|
29
utils.lua
29
utils.lua
|
@ -25,4 +25,33 @@ function set_state(state, ...)
|
|||
if gs and gs._leave then gs._leave() end
|
||||
gs = state
|
||||
if gs and gs._enter then gs._enter(unpack(args)) end
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Returns the indices of found occurences of `o` within `tbl`
|
||||
--
|
||||
function find(tbl, o)
|
||||
local indices = {}
|
||||
for k,v in ipairs(tbl) do
|
||||
if v == o then add(indices, k) end
|
||||
end
|
||||
return indices
|
||||
end
|
||||
|
||||
--
|
||||
-- Makes a shallow table copy
|
||||
--
|
||||
function copy(tbl)
|
||||
return map(tbl, function (o) return o end)
|
||||
end
|
||||
|
||||
--
|
||||
-- Table equality - shallow comparison
|
||||
--
|
||||
function equal(tbl1, tbl2)
|
||||
for k, _ in ipairs(tbl1) do
|
||||
if tbl1[k] ~= tbl2[k] then return false end
|
||||
end
|
||||
return true
|
||||
end
|
Loading…
Reference in New Issue
Block a user