Code formatting

This commit is contained in:
Simon Cambier 2023-10-07 19:12:53 +02:00
parent bc408aeeb3
commit cb74bdf740
16 changed files with 1066 additions and 1067 deletions

View File

@ -1,4 +1,4 @@
{ {
"editor.insertSpaces": false, "editor.insertSpaces": true,
"editor.detectIndentation": false "editor.detectIndentation": false,
} }

View File

@ -2,10 +2,9 @@ pico-8 cartridge // http://www.pico-8.com
version 38 version 38
__lua__ __lua__
-- Font M3X6 by daniel linssen -- Font M3X6 by daniel linssen
poke(0x5600, 4, 4, 7) poke(0x5600, 4, 4, 7)
poke4(0x5700,unpack(split"0x0000.0000,0x0000.0000,0x0202.0202,0x0000.0200,0x0000.0505,0x0000.0000,0x0505.0705,0x0000.0507,0x0407.0106,0x0000.0203,0x0204.0100,0x0000.0401,0x0102.0502,0x0000.0305,0x0000.0102,0x0000.0000,0x0101.0102,0x0000.0201,0x0202.0201,0x0000.0102,0x0205.0000,0x0000.0005,0x0702.0000,0x0000.0002,0x0000.0000,0x0000.0102,0x0700.0000,0x0000.0000,0x0000.0000,0x0000.0200,0x0202.0404,0x0000.0101,0x0505.0506,0x0000.0305,0x0202.0302,0x0000.0702,0x0204.0403,0x0000.0701,0x0403.0403,0x0000.0304,0x0406.0505,0x0000.0404,0x0403.0107,0x0000.0304,0x0503.0106,0x0000.0605,0x0204.0407,0x0000.0202,0x0502.0506,0x0000.0305,0x0605.0503,0x0000.0304,0x0002.0000,0x0000.0002,0x0002.0000,0x0000.0102,0x0102.0400,0x0000.0402,0x0007.0000,0x0000.0007,0x0402.0100,0x0000.0102,0x0204.0403,0x0000.0200,0x0505.0506,0x0000.0601,0x0604.0300,0x0000.0705,0x0505.0301,0x0000.0705,0x0101.0600,0x0000.0701,0x0505.0604,0x0000.0705,0x0705.0600,0x0000.0601,0x0702.0204,0x0000.0202,0x0705.0600,0x0000.0304,0x0505.0301,0x0000.0505,0x0202.0002,0x0000.0202,0x0202.0002,0x0000.0102,0x0305.0101,0x0000.0505,0x0202.0202,0x0000.0402,0x0707.0300,0x0000.0507,0x0505.0300,0x0000.0505,0x0505.0600,0x0000.0305,0x0305.0700,0x0000.0101,0x0705.0600,0x0000.0404,0x0101.0600,0x0000.0101,0x0701.0600,0x0000.0304,0x0207.0202,0x0000.0202,0x0505.0500,0x0000.0705,0x0505.0500,0x0000.0205,0x0705.0500,0x0000.0507,0x0205.0500,0x0000.0505,0x0605.0500,0x0000.0304,0x0204.0700,0x0000.0701,0x0101.0103,0x0000.0301,0x0202.0101,0x0000.0404,0x0202.0203,0x0000.0302,0x0000.0502,0x0000.0000,0x0000.0000,0x0000.0403,0x0000.0201,0x0000.0000,0x0507.0506,0x0000.0505,0x0507.0503,0x0000.0705,0x0101.0106,0x0000.0701,0x0505.0503,0x0000.0305,0x0103.0107,0x0000.0701,0x0301.0106,0x0000.0101,0x0501.0106,0x0000.0705,0x0507.0505,0x0000.0505,0x0202.0207,0x0000.0702,0x0404.0407,0x0000.0304,0x0503.0505,0x0000.0505,0x0101.0101,0x0000.0701,0x0507.0705,0x0000.0505,0x0505.0503,0x0000.0505,0x0505.0506,0x0000.0305,0x0103.0507,0x0000.0101,0x0505.0506,0x0000.0403,0x0503.0507,0x0000.0505,0x0407.0106,0x0000.0304,0x0202.0207,0x0000.0202,0x0505.0505,0x0000.0705,0x0505.0505,0x0000.0205,0x0705.0505,0x0000.0507,0x0202.0505,0x0000.0505,0x0205.0505,0x0000.0202,0x0202.0407,0x0000.0701,0x0302.0204,0x0000.0402,0x0202.0202,0x0000.0202,0x0602.0201,0x0000.0102,0x0704.0000,0x0000.0001,0x0205.0200,0x0000.0000")) poke4(0x5700, unpack(split "0x0000.0000,0x0000.0000,0x0202.0202,0x0000.0200,0x0000.0505,0x0000.0000,0x0505.0705,0x0000.0507,0x0407.0106,0x0000.0203,0x0204.0100,0x0000.0401,0x0102.0502,0x0000.0305,0x0000.0102,0x0000.0000,0x0101.0102,0x0000.0201,0x0202.0201,0x0000.0102,0x0205.0000,0x0000.0005,0x0702.0000,0x0000.0002,0x0000.0000,0x0000.0102,0x0700.0000,0x0000.0000,0x0000.0000,0x0000.0200,0x0202.0404,0x0000.0101,0x0505.0506,0x0000.0305,0x0202.0302,0x0000.0702,0x0204.0403,0x0000.0701,0x0403.0403,0x0000.0304,0x0406.0505,0x0000.0404,0x0403.0107,0x0000.0304,0x0503.0106,0x0000.0605,0x0204.0407,0x0000.0202,0x0502.0506,0x0000.0305,0x0605.0503,0x0000.0304,0x0002.0000,0x0000.0002,0x0002.0000,0x0000.0102,0x0102.0400,0x0000.0402,0x0007.0000,0x0000.0007,0x0402.0100,0x0000.0102,0x0204.0403,0x0000.0200,0x0505.0506,0x0000.0601,0x0604.0300,0x0000.0705,0x0505.0301,0x0000.0705,0x0101.0600,0x0000.0701,0x0505.0604,0x0000.0705,0x0705.0600,0x0000.0601,0x0702.0204,0x0000.0202,0x0705.0600,0x0000.0304,0x0505.0301,0x0000.0505,0x0202.0002,0x0000.0202,0x0202.0002,0x0000.0102,0x0305.0101,0x0000.0505,0x0202.0202,0x0000.0402,0x0707.0300,0x0000.0507,0x0505.0300,0x0000.0505,0x0505.0600,0x0000.0305,0x0305.0700,0x0000.0101,0x0705.0600,0x0000.0404,0x0101.0600,0x0000.0101,0x0701.0600,0x0000.0304,0x0207.0202,0x0000.0202,0x0505.0500,0x0000.0705,0x0505.0500,0x0000.0205,0x0705.0500,0x0000.0507,0x0205.0500,0x0000.0505,0x0605.0500,0x0000.0304,0x0204.0700,0x0000.0701,0x0101.0103,0x0000.0301,0x0202.0101,0x0000.0404,0x0202.0203,0x0000.0302,0x0000.0502,0x0000.0000,0x0000.0000,0x0000.0403,0x0000.0201,0x0000.0000,0x0507.0506,0x0000.0505,0x0507.0503,0x0000.0705,0x0101.0106,0x0000.0701,0x0505.0503,0x0000.0305,0x0103.0107,0x0000.0701,0x0301.0106,0x0000.0101,0x0501.0106,0x0000.0705,0x0507.0505,0x0000.0505,0x0202.0207,0x0000.0702,0x0404.0407,0x0000.0304,0x0503.0505,0x0000.0505,0x0101.0101,0x0000.0701,0x0507.0705,0x0000.0505,0x0505.0503,0x0000.0505,0x0505.0506,0x0000.0305,0x0103.0507,0x0000.0101,0x0505.0506,0x0000.0403,0x0503.0507,0x0000.0505,0x0407.0106,0x0000.0304,0x0202.0207,0x0000.0202,0x0505.0505,0x0000.0705,0x0505.0505,0x0000.0205,0x0705.0505,0x0000.0507,0x0202.0505,0x0000.0505,0x0205.0505,0x0000.0202,0x0202.0407,0x0000.0701,0x0302.0204,0x0000.0402,0x0202.0202,0x0000.0202,0x0602.0201,0x0000.0102,0x0704.0000,0x0000.0001,0x0205.0200,0x0000.0000"))
#include globals.lua #include globals.lua
-- --

25
bg.lua
View File

@ -5,31 +5,32 @@ function draw_animated_bg(startx)
local color = 1 local color = 1
-- vertical lines -- vertical lines
local t = t()+10 local t = t() + 10
for i=startx-1,127,9 do for i = startx - 1, 127, 9 do
local a=sin(i*t/512)*amplitude+64 local a = sin(i * t / 512) * amplitude + 64
local b=cos(i*t/256)*amplitude+64 local b = cos(i * t / 256) * amplitude + 64
line( line(
i, i,
a, a,
i, i,
b , b,
color) color
)
end end
-- horizontal lines -- horizontal lines
for i=startx-1,127,9 do for i = startx - 1, 127, 9 do
local a=sin(i*t/512)*amplitude+64 local a = sin(i * t / 512) * amplitude + 64
local b=cos(i*t/256)*amplitude+64 local b = cos(i * t / 256) * amplitude + 64
line( line(
a, a,
i, i,
b , b,
i, i,
color) color
)
end end
end end
function draw_bg_menu() function draw_bg_menu()
end end

172
board.lua
View File

@ -2,11 +2,14 @@ local Board = {}
function Board.new() function Board.new()
local debug = false local debug = false
local width = board_size -- tiles local width = board_size
local tile_width = 8 -- pixels -- tiles
local tile_width = 8
-- pixels
local padding = 1 local padding = 1
local tiles = {} local tiles = {}
local locked = {} -- list of indexes local locked = {}
-- list of indexes
local reset = function() local reset = function()
tiles = {} tiles = {}
@ -45,10 +48,9 @@ function Board.new()
end, end,
draw_coords = function(self, x, y) draw_coords = function(self, x, y)
local margin = (128 - (tile_width + padding) * width) / 2- padding local margin = (128 - (tile_width + padding) * width) / 2 - padding
if not y then x, y = self:idx_xy(x) end if not y then x, y = self:idx_xy(x) end
return margin + (x-1)*tile_width + (x-1)*padding, return margin + (x - 1) * tile_width + (x - 1) * padding, margin + (y - 1) * tile_width + (y - 1) * padding
margin + (y-1)*tile_width + (y-1)*padding
end, end,
get_size = function(self) get_size = function(self)
@ -60,7 +62,7 @@ function Board.new()
end, end,
fill = function(self, idx, color, invert) fill = function(self, idx, color, invert)
if idx > width*width then return end if idx > width * width then return end
if invert then if invert then
color = color == YELLOW and BLUE or YELLOW color = color == YELLOW and BLUE or YELLOW
end end
@ -75,20 +77,21 @@ function Board.new()
to_color = YELLOW to_color = YELLOW
elseif tiles[id] == YELLOW then elseif tiles[id] == YELLOW then
to_color = BLUE to_color = BLUE
else tiles[id] = 0 else
tiles[id] = 0
-- empty tile -- empty tile
end end
if to_color then if to_color then
tiles[id] = to_color tiles[id] = to_color
end end
local x,y = self:draw_coords(id) local x, y = self:draw_coords(id)
spawn_tile_transition(x, y, tile_width-1, tile_width-1, from_color, to_color) spawn_tile_transition(x, y, tile_width - 1, tile_width - 1, from_color, to_color)
end, end,
get_rows = function(self) get_rows = function(self)
local ret = {} local ret = {}
for i = 1, width do for i = 1, width do
add(ret, slice(tiles, ((i - 1) * width) + 1, i * width)) add(ret, slice(tiles, (i - 1) * width + 1, i * width))
end end
return ret return ret
end, end,
@ -102,10 +105,12 @@ function Board.new()
return ret return ret
end, end,
--- Returns true if all tiles are filled
is_complete = function(self) is_complete = function(self)
return count(tiles, 0) == 0 return count(tiles, 0) == 0
end, end,
--- Returns true if the board is valid (respects the rules)
is_valid = function(self) is_valid = function(self)
return #self:get_issues() == 0 return #self:get_issues() == 0
end, end,
@ -114,53 +119,47 @@ function Board.new()
get_issues = function(self, details) get_issues = function(self, details)
local rows = self:get_rows() local rows = self:get_rows()
local issues = {} local issues = {}
for y,row in ipairs(rows) do for y, row in ipairs(rows) do
local filled = count(row, 0) == 0 local filled = count(row, 0) == 0
-- check count -- check count
if filled and count(row, BLUE) ~= count(row, YELLOW) then if filled and count(row, BLUE) ~= count(row, YELLOW) then
add(issues, {"row", "count", row, y}) add(issues, { "row", "count", row, y })
if (debug) printh("uneven count on row "..y) if (debug) printh("uneven count on row " .. y) if (not details) return issues
if (not details) return issues
end end
-- check identical lines -- check identical lines
for k,other in ipairs(rows) do for k, other in ipairs(rows) do
if filled and equal(other, row) and other ~= row then if filled and equal(other, row) and other ~= row then
add(issues, {"row", "identical", row, y, k}) add(issues, { "row", "identical", row, y, k })
if (debug) printh("equal rows "..k) if (debug) printh("equal rows " .. k) if (not details) return issues
if (not details) return issues
end end
end end
-- check triples -- check triples
if self:count_consecutives(row) > 2 then if self:count_consecutives(row) > 2 then
add(issues, {"row", "triples", row, y}) add(issues, { "row", "triples", row, y })
if (debug) printh("triples") if (debug) printh("triples") if (not details) return issues
if (not details) return issues
end end
end end
local cols = self:get_cols() local cols = self:get_cols()
for x,col in ipairs(cols) do for x, col in ipairs(cols) do
local filled = count(col, 0) == 0 local filled = count(col, 0) == 0
-- check count -- check count
if filled and count(col, BLUE) ~= count(col, YELLOW) then if filled and count(col, BLUE) ~= count(col, YELLOW) then
add(issues, {"col", "count", col, x}) add(issues, { "col", "count", col, x })
if (debug) printh("uneven count") if (debug) printh("uneven count") if (not details) return issues
if (not details) return issues
end end
-- check identical lines -- check identical lines
for k,other in ipairs(cols) do for k, other in ipairs(cols) do
if filled and equal(other, col) and other ~= col then if filled and equal(other, col) and other ~= col then
add(issues, {"col", "identical", col, x, k}) add(issues, { "col", "identical", col, x, k })
if (debug) printh("equal cols") if (debug) printh("equal cols") if (not details) return issues
if (not details) return issues
end end
end end
-- check triples -- check triples
if self:count_consecutives(col) > 2 then if self:count_consecutives(col) > 2 then
add(issues, {"col", "triples", col, x}) add(issues, { "col", "triples", col, x })
if (debug) printh("triples") if (debug) printh("triples") if (not details) return issues
if (not details) return issues
end end
end end
return issues return issues
@ -175,7 +174,7 @@ function Board.new()
top = max(current, top) top = max(current, top)
current = 1 current = 1
last = v last = v
elseif v~= 0 then elseif v ~= 0 then
current += 1 current += 1
end end
end end
@ -189,7 +188,7 @@ function Board.new()
assert(count(tiles, 0) > 0, "No zero left") assert(count(tiles, 0) > 0, "No zero left")
local zeroes = filter(tiles, function(v) return v == 0 end, true) local zeroes = filter(tiles, function(v) return v == 0 end, true)
local z = {} local z = {}
for k,v in pairs(zeroes) do for k, v in pairs(zeroes) do
add(z, k) add(z, k)
end end
return rnd(z) return rnd(z)
@ -202,7 +201,7 @@ function Board.new()
assert(count(tiles, 0) < #tiles, "All zeroes") assert(count(tiles, 0) < #tiles, "All zeroes")
local numbers = filter(tiles, function(v) return v ~= 0 end, true) local numbers = filter(tiles, function(v) return v ~= 0 end, true)
local z = {} local z = {}
for k,v in pairs(numbers) do for k, v in pairs(numbers) do
add(z, k) add(z, k)
end end
return rnd(z) return rnd(z)
@ -230,43 +229,41 @@ function Board.new()
if not changed and random and not self:is_complete() then if not changed and random and not self:is_complete() then
-- Set a random color -- Set a random color
local z = self:get_random_zero() local z = self:get_random_zero()
self:fill(z, rnd({BLUE, YELLOW})) self:fill(z, rnd({ BLUE, YELLOW }))
if (debug) printh("!!!!!!!!!!!!!!!!! RANDOM FILL AT " .. z) if (debug) printh("!!!!!!!!!!!!!!!!! RANDOM FILL AT " .. z) return "invalid"
return "invalid"
end end
return (changed or self:is_complete()) and "valid" or "invalid" return (changed or self:is_complete()) and "valid" or "invalid"
end, end,
surround_doubles = function(self) surround_doubles = function(self)
for idx,v in ipairs(tiles) do for idx, v in ipairs(tiles) do
local x,y = self:idx_xy(idx) local x, y = self:idx_xy(idx)
if v == 0 then if v == 0 then
local neighbors = {} local neighbors = {}
-- 2 tiles on the left -- 2 tiles on the left
if x >= 3 then if x >= 3 then
add(neighbors, {idx, idx-1, idx-2}) add(neighbors, { idx, idx - 1, idx - 2 })
end end
-- 2 tiles on the right -- 2 tiles on the right
if x <= width-2 then if x <= width - 2 then
add(neighbors, {idx, idx+1, idx+2}) add(neighbors, { idx, idx + 1, idx + 2 })
end end
-- 2 tiles on top -- 2 tiles on top
if y >= 3 then if y >= 3 then
add(neighbors, {idx, idx-width, idx - width*2}) add(neighbors, { idx, idx - width, idx - width * 2 })
end end
-- 2 tiles under -- 2 tiles under
if y <= width-2 then if y <= width - 2 then
add(neighbors, {idx, idx+width, idx + width*2}) add(neighbors, { idx, idx + width, idx + width * 2 })
end end
-- only keep pairs that are identical (and not 0) -- only keep pairs that are identical (and not 0)
neighbors = filter(neighbors, function (o) return tiles[o[2]] == tiles[o[3]] and tiles[o[2]] ~= 0 end) neighbors = filter(neighbors, function(o) return tiles[o[2]] == tiles[o[3]] and tiles[o[2]] ~= 0 end)
-- do the surrounding -- do the surrounding
for item in all(neighbors) do for item in all(neighbors) do
if item[1] then if item[1] then
if (debug) printh("Surrounding at " .. item[1]) if (debug) printh("Surrounding at " .. item[1]) self:fill(item[1], tiles[item[2]], true)
self:fill(item[1], tiles[item[2]], true)
end end
end end
end end
@ -275,26 +272,23 @@ function Board.new()
split_triples = function(self) split_triples = function(self)
for idx, col in ipairs(tiles) do for idx, col in ipairs(tiles) do
local x,y = self:idx_xy(idx) local x, y = self:idx_xy(idx)
if col == 0 then if col == 0 then
if x > 1 and x < width then if x > 1 and x < width then
-- check horizontal -- check horizontal
local prev = tiles[idx-1] local prev = tiles[idx - 1]
local next = tiles[idx+1] local next = tiles[idx + 1]
if prev ~= 0 and prev == next then if prev ~= 0 and prev == next then
if (debug) printh("Splitting at " .. idx) if (debug) printh("Splitting at " .. idx) self:fill(idx, prev, true)
self:fill(idx, prev, true)
end end
end end
if y>1 and y < width then if y > 1 and y < width then
-- check vertical -- check vertical
local prev = tiles[idx-width] local prev = tiles[idx - width]
local next = tiles[idx+width] local next = tiles[idx + width]
if prev ~= 0 and prev == next then if prev ~= 0 and prev == next then
if (debug) printh("Splitting at " .. idx) if (debug) printh("Splitting at " .. idx) self:fill(idx, prev, true)
self:fill(idx, prev, true)
end end
end end
end end
@ -306,22 +300,22 @@ function Board.new()
local cols = self:get_cols() local cols = self:get_cols()
-- rows -- rows
for y,row in ipairs(rows) do for y, row in ipairs(rows) do
local a = count(row, BLUE) local a = count(row, BLUE)
local b = count(row, YELLOW) local b = count(row, YELLOW)
if a ~= b then if a ~= b then
if a == width/2 then self:fill_row(y, YELLOW) end if a == width / 2 then self:fill_row(y, YELLOW) end
if b == width/2 then self:fill_row(y, BLUE) end if b == width / 2 then self:fill_row(y, BLUE) end
end end
end end
-- columns -- columns
for x,col in ipairs(cols) do for x, col in ipairs(cols) do
local a = count(col, BLUE) local a = count(col, BLUE)
local b = count(col, YELLOW) local b = count(col, YELLOW)
if a ~= b then if a ~= b then
if a == width/2 then self:fill_col(x, YELLOW) end if a == width / 2 then self:fill_col(x, YELLOW) end
if b == width/2 then self:fill_col(x, BLUE) end if b == width / 2 then self:fill_col(x, BLUE) end
end end
end end
end, end,
@ -329,7 +323,7 @@ function Board.new()
fill_row = function(self, y, color) fill_row = function(self, y, color)
if (debug) printh("Filling line " .. y .. " in " .. (color == BLUE and "blue" or "yellow")) if (debug) printh("Filling line " .. y .. " in " .. (color == BLUE and "blue" or "yellow"))
local idx = self:xy_idx(1, y) local idx = self:xy_idx(1, y)
for i = idx, (idx+width-1) do for i = idx, idx + width - 1 do
if self:get_tile(i) == 0 then if self:get_tile(i) == 0 then
self:fill(i, color) self:fill(i, color)
end end
@ -350,7 +344,7 @@ function Board.new()
no_identical_lines = function(self) no_identical_lines = function(self)
-- columns -- columns
local cols = self:get_cols() local cols = self:get_cols()
for x,col in ipairs(cols) do for x, col in ipairs(cols) do
-- if the line has the corrent number of colors, -- if the line has the corrent number of colors,
-- but missing 2 tiles -- but missing 2 tiles
if count(col, 0) == 2 and count(col, BLUE) == count(col, YELLOW) then if count(col, 0) == 2 and count(col, BLUE) == count(col, YELLOW) then
@ -359,14 +353,14 @@ function Board.new()
local ab = copy(col) ab[y1] = BLUE ab[y2] = YELLOW local ab = copy(col) ab[y1] = BLUE ab[y2] = YELLOW
local ba = copy(col) ba[y1] = YELLOW ba[y2] = BLUE local ba = copy(col) ba[y1] = YELLOW ba[y2] = BLUE
-- Check if a dupe exists -- Check if a dupe exists
for x2,col in ipairs(cols) do for x2, col in ipairs(cols) do
if equal(col, ab) then if equal(col, ab) then
self:fill(self:xy_idx(x,y1), YELLOW) self:fill(self:xy_idx(x, y1), YELLOW)
self:fill(self:xy_idx(x,y2), BLUE) self:fill(self:xy_idx(x, y2), BLUE)
goto continue goto continue
elseif equal(col, ba) then elseif equal(col, ba) then
self:fill(self:xy_idx(x,y1), BLUE) self:fill(self:xy_idx(x, y1), BLUE)
self:fill(self:xy_idx(x,y2), YELLOW) self:fill(self:xy_idx(x, y2), YELLOW)
goto continue goto continue
end end
end end
@ -376,20 +370,20 @@ function Board.new()
-- rows -- rows
local rows = self:get_rows() local rows = self:get_rows()
for y,row in ipairs(rows) do for y, row in ipairs(rows) do
if count(row, 0) == 2 and count(row, BLUE) == count(row, YELLOW) then if count(row, 0) == 2 and count(row, BLUE) == count(row, YELLOW) then
local x1, x2 = unpack(find(row, 0)) local x1, x2 = unpack(find(row, 0))
local ab = copy(row) ab[x1] = BLUE ab[x2] = YELLOW local ab = copy(row) ab[x1] = BLUE ab[x2] = YELLOW
local ba = copy(row) ba[x1] = YELLOW ba[x2] = BLUE local ba = copy(row) ba[x1] = YELLOW ba[x2] = BLUE
-- Check if a dupe exists -- Check if a dupe exists
for y2,row in ipairs(rows) do for y2, row in ipairs(rows) do
if equal(row, ab) then if equal(row, ab) then
self:fill(self:xy_idx(x1,y), YELLOW) self:fill(self:xy_idx(x1, y), YELLOW)
self:fill(self:xy_idx(x2,y), BLUE) self:fill(self:xy_idx(x2, y), BLUE)
goto continue goto continue
elseif equal(row, ba) then elseif equal(row, ba) then
self:fill(self:xy_idx(x1,y), BLUE) self:fill(self:xy_idx(x1, y), BLUE)
self:fill(self:xy_idx(x2,y), YELLOW) self:fill(self:xy_idx(x2, y), YELLOW)
goto continue goto continue
end end
end end
@ -400,7 +394,7 @@ function Board.new()
lock_tiles = function(self) lock_tiles = function(self)
locked = {} locked = {}
for k,v in ipairs(tiles) do for k, v in ipairs(tiles) do
if v > 0 then locked[k] = true end if v > 0 then locked[k] = true end
end end
end, end,
@ -411,14 +405,14 @@ function Board.new()
draw_bg_tile = function(self, k) draw_bg_tile = function(self, k)
local w = tile_width local w = tile_width
local x,y = self:draw_coords(k) local x, y = self:draw_coords(k)
rectfill2(x+1, y, w-2, w, 1) rectfill2(x + 1, y, w - 2, w, 1)
rectfill2(x, y+1, w, w-2, 1) rectfill2(x, y + 1, w, w - 2, 1)
end, end,
draw = function(self) draw = function(self)
local w = tile_width local w = tile_width
for k,v in ipairs(tiles) do for k, v in ipairs(tiles) do
self:draw_tile(k) self:draw_tile(k)
end end
end, end,
@ -427,7 +421,7 @@ function Board.new()
local w = tile_width local w = tile_width
local v = tiles[idx] local v = tiles[idx]
if v > 0 then if v > 0 then
local x,y = self:draw_coords(idx) local x, y = self:draw_coords(idx)
local color = get_main_color(v) local color = get_main_color(v)
local shade = get_shade_color(v) local shade = get_shade_color(v)
if color == 1 then fillp() else fillp() end if color == 1 then fillp() else fillp() end
@ -435,13 +429,13 @@ function Board.new()
rectfill2(x, y, w, w, color) rectfill2(x, y, w, w, color)
else else
roundedrect(x, y, w, w, color) roundedrect(x, y, w, w, color)
line(x+1, y+w-1, x+w-2, y+w-1, shade) line(x + 1, y + w - 1, x + w - 2, y + w - 1, shade)
line(x+w-1, y+1, x+w-1, y+w-2, shade) line(x + w - 1, y + 1, x + w - 1, y + w - 2, shade)
end end
else else
fillp() fillp()
self:draw_bg_tile(idx) self:draw_bg_tile(idx)
end end
end, end
} }
end end

View File

@ -1,8 +1,9 @@
local coroutines={} local coroutines = {}
-- starts a coroutine and saves it for future reference -- starts a coroutine and saves it for future reference
function startcoroutine(co) function startcoroutine(co)
assert(tostr(co) == "[thread]") -- make sure that co is a coroutine, the return value of cocreate() assert(tostr(co) == "[thread]")
-- make sure that co is a coroutine, the return value of cocreate()
add(coroutines, co) add(coroutines, co)
end end
@ -23,12 +24,12 @@ end
-- to be used inside a coroutine -- to be used inside a coroutine
function wait(seconds) function wait(seconds)
wait_frames(seconds*30) wait_frames(seconds * 30)
end end
-- to be used inside a coroutine -- to be used inside a coroutine
function wait_frames(frames) function wait_frames(frames)
for i=1,frames do for i = 1, frames do
yield() yield()
end end
end end

View File

@ -12,7 +12,7 @@ local YELLOW = 1
-- 🅾️ Z[C]N ❎ [X]VM -- 🅾️ Z[C]N ❎ [X]VM
-- X and C have the same position on QWERTY and AZERTY -- X and C have the same position on QWERTY and AZERTY
local LEFT,RIGHT,UP,DOWN,BTN_O,BTN_X = 0,1,2,3,4,5 local LEFT, RIGHT, UP, DOWN, BTN_O, BTN_X = 0, 1, 2, 3, 4, 5
local patterns = { local patterns = {
0b0000000000000000, 0b0000000000000000,
@ -31,5 +31,5 @@ local patterns = {
0b1111110111110101, 0b1111110111110101,
0b1111110111110111, 0b1111110111110111,
0b1111111111110111, 0b1111111111110111,
0b1111111111111111, 0b1111111111111111
} }

View File

@ -3,11 +3,11 @@
-- --
function custom_font() function custom_font()
poke(0x5f58,0x81) poke(0x5f58, 0x81)
end end
function standard_font(font) function standard_font(font)
poke(0x5f58,0x80) poke(0x5f58, 0x80)
end end
function idx_xy(idx, width) function idx_xy(idx, width)
@ -15,7 +15,7 @@ function idx_xy(idx, width)
end end
function xy_idx(x, y, width) function xy_idx(x, y, width)
return ((y - 1) * width) + x return (y - 1) * width + x
end end
function map(tbl, f) function map(tbl, f)
@ -30,9 +30,10 @@ function filter(tbl, f, keepindex)
local ret = {} local ret = {}
for k, v in pairs(tbl) do for k, v in pairs(tbl) do
if f(v) then if f(v) then
if keepindex if keepindex then
then ret[k] = v ret[k] = v
else add(ret, v) else
add(ret, v)
end end
end end
end end
@ -41,24 +42,24 @@ end
function slice(tbl, first, last, step) function slice(tbl, first, last, step)
local sliced = {} local sliced = {}
for i = (first or 1), (last or #tbl), (step or 1) do for i = first or 1, last or #tbl, step or 1 do
sliced[#sliced + 1] = tbl[i] sliced[#sliced + 1] = tbl[i]
end end
return sliced return sliced
end end
function rectfill2(x, y, w, h, col) function rectfill2(x, y, w, h, col)
rectfill(x, y, x+w-1, y+h-1, col) rectfill(x, y, x + w - 1, y + h - 1, col)
end end
function roundedrect(x, y, w, h, col) function roundedrect(x, y, w, h, col)
rectfill2(x,y,w,h,0) rectfill2(x, y, w, h, 0)
rectfill2(x+1, y, w-2, h, col) rectfill2(x + 1, y, w - 2, h, col)
rectfill2(x, y+1, w, h-2, col) rectfill2(x, y + 1, w, h - 2, col)
end end
function rect2(x, y, w, h, col) function rect2(x, y, w, h, col)
rect(x, y, x+w, y+h, col) rect(x, y, x + w, y + h, col)
end end
-- --
@ -74,7 +75,6 @@ end
-- return c -- return c
-- end -- end
-- function tostring(any) -- function tostring(any)
-- if (type(any)~="table") return tostr(any) -- if (type(any)~="table") return tostr(any)
-- local str = "{" -- local str = "{"
@ -85,7 +85,6 @@ end
-- return str.."}" -- return str.."}"
-- end -- end
-- --
-- main loop -- main loop
-- --
@ -97,11 +96,10 @@ function _init()
printh(" ") printh(" ")
printh("*************") printh("*************")
printh(" ") printh(" ")
local date = stat(80)..stat(81)..stat(82)..stat(84)..stat(85) local date = stat(80) .. stat(81) .. stat(82) .. stat(84) .. stat(85)
srand(date) srand(date)
printh("seed " .. date) printh("seed " .. date)
frame_count = 0 frame_count = 0
states = { states = {
@ -109,11 +107,10 @@ function _init()
menu = state_menu(), menu = state_menu(),
loading = state_loading(), loading = state_loading(),
game = state_game(), game = state_game(),
endgame = state_endgame(), endgame = state_endgame()
} }
set_state(states.menu) set_state(states.menu)
end end
function _update60() function _update60()

View File

@ -7,13 +7,15 @@ function state_endgame()
set_state(states.menu) set_state(states.menu)
end end
local btn_back = make_button({x=1, y=118, h=7, text="🅾️/C bACK TO mENU", color=8, local btn_back = make_button({
on_click=function() go_to_menu() end, x = 1, y = 118, h = 7, text = "🅾️/C bACK TO mENU", color = 8,
on_hover=function(btn) btn.color = 7 end}) on_click = function() go_to_menu() end,
on_hover = function(btn) btn.color = 7 end
})
local function _enter(_board) local function _enter(_board)
board = _board board = _board
message_x = (128 - print(message,0,-100))/2 message_x = (128 - print(message, 0, -100)) / 2
end end
local function _update() local function _update()
@ -28,12 +30,13 @@ function state_endgame()
board:draw() board:draw()
-- wavy message -- wavy message
local offset=0 local offset = 0
for i = 1, #message, 1 do -- loop through every letter for i = 1, #message, 1 do
-- loop through every letter
letter = sub(message, i, i) -- grab this letter letter = sub(message, i, i) -- grab this letter
local st = t() + 0.125 * i -- create a modified time for this letter local st = t() + 0.125 * i -- create a modified time for this letter
print(letter, message_x + offset, 20 + sin(st*0.5)*10, 7) -- draw this letter print(letter, message_x + offset, 20 + sin(st * 0.5) * 10, 7) -- draw this letter
offset += print(letter,0,-100) offset += print(letter, 0, -100)
end end
btn_back:draw() btn_back:draw()

View File

@ -1,9 +1,8 @@
function state_game() function state_game()
local board local board
local selected_id = 1 local selected_id = 1
local timer_clue = 0 local timer_clue = 0
local mx,mx = 0,0 local mx, mx = 0, 0
local clues = {} local clues = {}
local function show_clues() local function show_clues()
@ -12,9 +11,9 @@ function state_game()
for issue in all(issues) do for issue in all(issues) do
local type, err, row, pos, other = unpack(issue) local type, err, row, pos, other = unpack(issue)
printh(type .. " " .. err .. " " .. pos) printh(type .. " " .. err .. " " .. pos)
add(clues, {type=type, pos=pos, t=0}) add(clues, { type = type, pos = pos, t = 0 })
if err == "identical" then if err == "identical" then
add(clues, {type=type, pos=other, t=0}) add(clues, { type = type, pos = other, t = 0 })
end end
end end
end end
@ -23,7 +22,7 @@ function state_game()
local x, y = board:draw_coords(selected_id) local x, y = board:draw_coords(selected_id)
local w = board:get_tile_width() local w = board:get_tile_width()
-- fillp(▒) -- fillp(▒)
rect2(x-1, y-1, w, w, 6) rect2(x - 1, y - 1, w, w, 6)
line() line()
fillp() fillp()
end end
@ -31,14 +30,14 @@ function state_game()
local function update_mouse() local function update_mouse()
-- update mouse position -- update mouse position
if mx == mouse_x and my == mouse_y then return end if mx == mouse_x and my == mouse_y then return end
mx,my = mouse_x, mouse_y mx, my = mouse_x, mouse_y
local board_x, board_y = board:draw_coords(1) local board_x, board_y = board:draw_coords(1)
local tw = board:get_tile_width() local tw = board:get_tile_width()
local bw = board:get_size() local bw = board:get_size()
-- pixels coords to grid coords -- pixels coords to grid coords
local x = mid(1, (mouse_x - board_x) \ tw + 1, bw) local x = mid(1, (mouse_x - board_x) \ tw + 1, bw)
local y = mid(1, (mouse_y - board_y) \ tw + 1, bw) local y = mid(1, (mouse_y - board_y) \ tw + 1, bw)
selected_id = board:xy_idx(x,y) selected_id = board:xy_idx(x, y)
end end
local function check_endgame() local function check_endgame()
@ -89,17 +88,16 @@ function state_game()
show_clues() show_clues()
end end
if (x<1) x=size if (x < 1) x = size
if (x>size) x=1 if (x > size) x = 1
if (y<1) y=size if (y < 1) y = size
if (y>size) y=1 if (y > size) y = 1
check_endgame() check_endgame()
end end
local function _draw() local function _draw()
cls() cls()
local x,y = board:draw_coords(1) local x, y = board:draw_coords(1)
draw_animated_bg(x) draw_animated_bg(x)
board:draw() board:draw()
@ -107,17 +105,18 @@ function state_game()
-- draw clues -- draw clues
for clue in all(clues) do for clue in all(clues) do
palt(0,false) palt(0, false)
palt(5,true) palt(5, true)
local x,y local x, y
if clue.type == "row" then if clue.type == "row" then
x,y = board:draw_coords((clue.pos-1) * board:get_size()+1) x, y = board:draw_coords((clue.pos - 1) * board:get_size() + 1)
x=-32 x = -32
spr(19, x+clue.t%144, y+1+sin(t())*2) spr(19, x + clue.t % 144, y + 1 + sin(t()) * 2)
else -- col else
x,y = board:draw_coords(clue.pos) -- col
y=-32 x, y = board:draw_coords(clue.pos)
spr(19, x+2+sin(t())*2, y+clue.t%144) y = -32
spr(19, x + 2 + sin(t()) * 2, y + clue.t % 144)
end end
pset(x, y, 5) pset(x, y, 5)
clue.t += 1 clue.t += 1

View File

@ -4,7 +4,7 @@ function state_loading()
local og_rt local og_rt
local removing_tile local removing_tile
local spinner = split"-,\\,|,/" local spinner = split "-,\\,|,/"
local loading_messages = { local loading_messages = {
"rETICULATING SPLINES", "rETICULATING SPLINES",
"aLLOCATING RESSOURCES", "aLLOCATING RESSOURCES",
@ -20,7 +20,7 @@ function state_loading()
"sHAKING RED AND BLUE PAINT BUCKETS", "sHAKING RED AND BLUE PAINT BUCKETS",
"gATHERING GRAVITY", "gATHERING GRAVITY",
"sERIALIZING BOARD MATRIX", "sERIALIZING BOARD MATRIX",
"bACKPORTING e2e ENCRYPTION", "bACKPORTING e2e ENCRYPTION"
} }
local message = "" local message = ""
@ -41,10 +41,10 @@ function state_loading()
until board:is_valid() until board:is_valid()
-- Remove tiles that can be removed -- Remove tiles that can be removed
local previous = {board:get_tiles_copy()} -- initial state local previous = { board:get_tiles_copy() }
-- initial state
done = {} done = {}
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
@ -74,8 +74,9 @@ function state_loading()
if solved == "invalid" then if solved == "invalid" then
deli(previous) deli(previous)
end end
end -- end while end
printh("board generated in "..time()-start.." seconds") -- end while
printh("board generated in " .. time() - start .. " seconds")
startcoroutine(cocreate(function() startcoroutine(cocreate(function()
repeat repeat
amplitude -= .5 amplitude -= .5
@ -85,7 +86,7 @@ function state_loading()
board:set_tiles(previous[#previous]) board:set_tiles(previous[#previous])
printh(board:tostring()) printh(board:tostring())
printh(count(board:get_tiles_copy(), 0).." zeroes") printh(count(board:get_tiles_copy(), 0) .. " zeroes")
loaded = true loaded = true
end end
@ -93,8 +94,8 @@ function state_loading()
local function draw_tiles(board) local function draw_tiles(board)
local w = board:get_size() local w = board:get_size()
local tiles = board:get_tiles_copy() local tiles = board:get_tiles_copy()
for k,v in ipairs(tiles) do for k, v in ipairs(tiles) do
if v==0 or contains(done, k) then if v == 0 or contains(done, k) then
board:draw_tile(k) board:draw_tile(k)
end end
end end
@ -103,8 +104,9 @@ function state_loading()
local function _enter() local function _enter()
printh("enter loading") printh("enter loading")
board = Board:new() board = Board:new()
size = board:get_size()*board:get_size() size = board:get_size() * board:get_size()
og_rt = rnd(size)\1+1 -- original removing tile og_rt = rnd(size) \ 1 + 1
-- original removing tile
removing_tile = og_rt removing_tile = og_rt
amplitude = 64 amplitude = 64
@ -135,14 +137,14 @@ function state_loading()
local function _draw() local function _draw()
cls() cls()
local x,y = board:draw_coords(1) local x, y = board:draw_coords(1)
draw_animated_bg(x) draw_animated_bg(x)
-- board:draw_bg() -- board:draw_bg()
draw_tiles(board) draw_tiles(board)
local s = board:get_size()*board:get_size() local s = board:get_size() * board:get_size()
local l = print(message, 0, -100) local l = print(message, 0, -100)
local y = 118+(removing_tile/s)*100/8 local y = 118 + removing_tile / s * 100 / 8
local ci = removing_tile\20+1 local ci = removing_tile \ 20 + 1
-- if not loaded then -- if not loaded then
-- rectfill2(0,y-2,127,10,0) -- rectfill2(0,y-2,127,10,0)
-- print(messages_str, messages_x, y, 3, 0) -- print(messages_str, messages_x, y, 3, 0)
@ -153,6 +155,6 @@ function state_loading()
return { return {
_enter = _enter, _enter = _enter,
_update = _update, _update = _update,
_draw = _draw, _draw = _draw
} }
end end

View File

@ -10,30 +10,32 @@ function state_menu()
-- } -- }
local game_sizes = { local game_sizes = {
{"mINI bOARD - 4X4", 4}, { "mINI bOARD - 4X4", 4 },
{"sMALL bOARD - 6X6", 6}, { "sMALL bOARD - 6X6", 6 },
{"mEDIUM bOARD - 8X8", 8}, { "mEDIUM bOARD - 8X8", 8 },
{"lARGE bOARD - 10X10", 10} { "lARGE bOARD - 10X10", 10 }
} }
for k, item in ipairs(game_sizes) do for k, item in ipairs(game_sizes) do
add(buttons, add(
buttons,
make_button({ make_button({
x=10, y=10+k*10, x = 10, y = 10 + k * 10,
selected_color=7, selected_color = 7,
text=item[1], text = item[1],
on_click=function() board_size=item[2] set_state(states.loading) end, on_click = function() board_size = item[2] set_state(states.loading) end,
on_hover=function() selected=k end, on_hover = function() selected = k end
}) })
) )
end end
local rulesId = #buttons + 1
local rulesId = #buttons+1 add(
add(buttons, buttons,
make_button({x=10, y=20+(#game_sizes+1)*10, w=30, text="rULES", make_button({
color=13, selected_color=12, x = 10, y = 20 + (#game_sizes + 1) * 10, w = 30, text = "rULES",
on_click=function() set_state(states.rules) end, color = 13, selected_color = 12,
on_hover=function() selected=rulesId end, on_click = function() set_state(states.rules) end,
on_hover = function() selected = rulesId end
}) })
) )
@ -48,7 +50,7 @@ function state_menu()
print("pLAY", 10, 8, 8) print("pLAY", 10, 8, 8)
for k,button in ipairs(buttons) do for k, button in ipairs(buttons) do
button:draw(selected == k) button:draw(selected == k)
end end
print("pRESS ❎/X TO CONTINUE", 8, 120, 7) print("pRESS ❎/X TO CONTINUE", 8, 120, 7)
@ -70,7 +72,6 @@ function state_menu()
buttons[selected]:on_click() buttons[selected]:on_click()
end end
selected = mid(1, selected, #buttons) selected = mid(1, selected, #buttons)
end, end,
_draw = _draw _draw = _draw

View File

@ -1,19 +1,20 @@
function state_rules() function state_rules()
local fade = split "0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,4,9,10,9,4,2,1"
local fade = split"0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,4,9,10,9,4,2,1"
local color = 1 local color = 1
local function blink(x,y,w,h) local function blink(x, y, w, h)
rect2(x,y,w,h,fade[color]) rect2(x, y, w, h, fade[color])
end end
local function go_back() local function go_back()
set_state(states.menu) set_state(states.menu)
end end
local btn_back = make_button({x=1, y=118, w=30, h=7, text="🅾️/C mENU", color=8, local btn_back = make_button({
on_click=function() go_back() end, x = 1, y = 118, w = 30, h = 7, text = "🅾️/C mENU", color = 8,
on_hover=function(btn) btn.color = 7 end}) on_click = function() go_back() end,
on_hover = function(btn) btn.color = 7 end
})
return { return {
_enter = function() _enter = function()
@ -23,12 +24,12 @@ function state_rules()
-- standard_font() -- standard_font()
end, end,
_update=function() _update = function()
-- custom_font() -- custom_font()
if frame_count%8==0 then if frame_count % 8 == 0 then
color += 1 color += 1
end end
if color>#fade then if color > #fade then
color = 1 color = 1
end end
@ -40,55 +41,54 @@ function state_rules()
btn_back:update() btn_back:update()
end, end,
_draw=function() _draw = function()
cls() cls()
print("1) yOU CAN'T HAVE MORE THAN\n TWO (2) CONSECUTIVE TILES\n OF THE SAME COLOR", 2,2, 7) print("1) yOU CAN'T HAVE MORE THAN\n TWO (2) CONSECUTIVE TILES\n OF THE SAME COLOR", 2, 2, 7)
local x = 14 local x = 14
local y = 28 local y = 28
sspr(0,32, 12,12, x,y) sspr(0, 32, 12, 12, x, y)
spr(2, x+14, y+1) spr(2, x + 14, y + 1)
sspr(13,32, 12,12, x+26,y) sspr(13, 32, 12, 12, x + 26, y)
blink(x-1, y-1, 9, 3) blink(x - 1, y - 1, 9, 3)
blink(x+25, y-1, 9, 3) blink(x + 25, y - 1, 9, 3)
blink(x-1, y+8, 12, 3) blink(x - 1, y + 8, 12, 3)
blink(x+25, y+8, 12, 3) blink(x + 25, y + 8, 12, 3)
x = 75 x = 75
sspr(26,32, 12,12, x,y) sspr(26, 32, 12, 12, x, y)
spr(2, x+14, y+1) spr(2, x + 14, y + 1)
sspr(39,32, 12,12, x+26,y) sspr(39, 32, 12, 12, x + 26, y)
blink(x+5, y+2, 3, 9) blink(x + 5, y + 2, 3, 9)
blink(x+31, y+2, 3, 9) blink(x + 31, y + 2, 3, 9)
-------------- --------------
x = 44 x = 44
y = 50 y = 50
print("2) eACH LINE CONTAINS AN EQUAL\n NUMBER OF EACH COLOR", 2, y, 7) print("2) eACH LINE CONTAINS AN EQUAL\n NUMBER OF EACH COLOR", 2, y, 7)
sspr(52,32, 12,12, x,y+20) sspr(52, 32, 12, 12, x, y + 20)
spr(2, x+14, y+21) spr(2, x + 14, y + 21)
sspr(65,32, 12,12, x+26,y+20) sspr(65, 32, 12, 12, x + 26, y + 20)
blink(x+5, y+22, 6, 3) blink(x + 5, y + 22, 6, 3)
blink(x+31, y+22, 6, 3) blink(x + 31, y + 22, 6, 3)
blink(x-1, y+19, 3, 6) blink(x - 1, y + 19, 3, 6)
blink(x+25, y+19, 3, 6) blink(x + 25, y + 19, 3, 6)
-------------- --------------
x = 44 x = 44
y = 90 y = 90
print("3) aLL ROWS AND COLUMNS\n ARE DIFFERENT", 2, y, 7) print("3) aLL ROWS AND COLUMNS\n ARE DIFFERENT", 2, y, 7)
sspr(78,32, 12,12, x,y+20) sspr(78, 32, 12, 12, x, y + 20)
spr(2, x+14, y+21) spr(2, x + 14, y + 21)
sspr(91,32, 12,12, x+26,y+20) sspr(91, 32, 12, 12, x + 26, y + 20)
blink(x-1, y+25, 12, 6) blink(x - 1, y + 25, 12, 6)
blink(x+25, y+25, 12, 6) blink(x + 25, y + 25, 12, 6)
-------------- --------------
btn_back:draw() btn_back:draw()
end, end
} }
end end

View File

@ -2,6 +2,6 @@ local Tile = {}
function Tile.new(color) function Tile.new(color)
return { return {
color=color color = color
} }
end end

15
ui.lua
View File

@ -1,5 +1,6 @@
function make_button(options) function make_button(options)
local state = 0 -- 0 = normal, 1 = hovered, 2 = pressed local state = 0
-- 0 = normal, 1 = hovered, 2 = pressed
local w = print(options.text, 0, -100) local w = print(options.text, 0, -100)
return { return {
x = options.x, x = options.x,
@ -14,21 +15,21 @@ function make_button(options)
selected_color = options.selected_color or 5, selected_color = options.selected_color or 5,
color = options.color or 5, color = options.color or 5,
draw=function(self, selected) draw = function(self, selected)
standard_font() standard_font()
local color = selected and self.selected_color or self.color local color = selected and self.selected_color or self.color
print(self.text, self.x, self.y, color) print(self.text, self.x, self.y, color)
-- rect(self.x, self.y, self.x+self.w, self.y+self.h, color) -- rect(self.x, self.y, self.x+self.w, self.y+self.h, color)
end, end,
update=function(self) update = function(self)
self.color = self.ogColor self.color = self.ogColor
if mouse_x >= self.x and mouse_x <= self.x + self.w and if mouse_x >= self.x and mouse_x <= self.x + self.w
mouse_y >= self.y and mouse_y <= self.y + self.h then and mouse_y >= self.y and mouse_y <= self.y + self.h then
if stat(34)&1 == 0 and state == 2 and self.on_click then if stat(34) & 1 == 0 and state == 2 and self.on_click then
self.on_click(self) self.on_click(self)
end end
if stat(34)&1 == 1 then if stat(34) & 1 == 1 then
state = 2 state = 2
else else
if self.on_hover then self:on_hover() end if self.on_hover then self:on_hover() end

View File

@ -1,9 +1,9 @@
local oldprint = print local oldprint = print
function print(t,x,y,col1,col2) function print(t, x, y, col1, col2)
if col2 then if col2 then
for i=-1,1 do for i = -1, 1 do
for j=-1,1 do for j = -1, 1 do
oldprint(t, x+i, y+j, col2) oldprint(t, x + i, y + j, col2)
end end
end end
end end
@ -11,29 +11,28 @@ function print(t,x,y,col1,col2)
end end
function str_width(str) function str_width(str)
return print(str,0,-8) return print(str, 0, -8)
end end
function print_shade(t,x,y,col1,col2) function print_shade(t, x, y, col1, col2)
print(t,x,y+1,col2) print(t, x, y + 1, col2)
print(t,x+1,y+1,col2) print(t, x + 1, y + 1, col2)
print(t,x,y,col1) print(t, x, y, col1)
end end
function set_state(state, ...) function set_state(state, ...)
local args = {...} local args = { ... }
if gs and gs._leave then gs._leave() end if gs and gs._leave then gs._leave() end
gs = state gs = state
if gs and gs._enter then gs._enter(unpack(args)) end if gs and gs._enter then gs._enter(unpack(args)) end
end end
-- --
-- Returns the indices of found occurences of `o` within `tbl` -- Returns the indices of found occurences of `o` within `tbl`
-- --
function find(tbl, o) function find(tbl, o)
local indices = {} local indices = {}
for k,v in ipairs(tbl) do for k, v in ipairs(tbl) do
if v == o then add(indices, k) end if v == o then add(indices, k) end
end end
return indices return indices
@ -49,7 +48,7 @@ end
-- Makes a shallow table copy -- Makes a shallow table copy
-- --
function copy(tbl) function copy(tbl)
return map(tbl, function (o) return o end) return map(tbl, function(o) return o end)
end end
-- --

View File

@ -24,16 +24,18 @@ function spawn_tile_transition(x, y, w, h, from_tint, to_tint)
local p = #patterns local p = #patterns
local from_color = get_main_color(from_tint) local from_color = get_main_color(from_tint)
local to_color = get_main_color(to_tint) local to_color = get_main_color(to_tint)
add(overlays, { add(
overlays, {
_draw = function(self) _draw = function(self)
fillp() fillp()
rectfill(x, y, x + w, y + h, from_color) rectfill(x, y, x + w, y + h, from_color)
fillp(patterns[p\1]+0b0.1) fillp(patterns[p \ 1] + 0b0.1)
rectfill(x, y, x + w, y + h, to_color) rectfill(x, y, x + w, y + h, to_color)
p -= 1 p -= 1
if p < 1 then if p < 1 then
del(overlays, self) del(overlays, self)
end end
end end
}) }
)
end end