Tweaked rendering

This commit is contained in:
Simon Cambier 2022-07-02 13:52:31 +02:00
parent 529703b7e4
commit 6f54ba9477
4 changed files with 18 additions and 8 deletions

View File

@ -4,7 +4,6 @@ function Board.new()
local width = 10 local width = 10
local tile_width = 10 local tile_width = 10
local margin = 4
local padding = 1 local padding = 1
local tiles = {} local tiles = {}
local locked = {} -- list of indexes local locked = {} -- list of indexes
@ -46,9 +45,10 @@ 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
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+1), return margin + (x-1)*tile_width + (x-1)*padding,
margin + (y-1)*tile_width + (y-1)*(padding+1) margin + (y-1)*tile_width + (y-1)*padding
end, end,
get_size = function(self) get_size = function(self)
@ -425,10 +425,12 @@ function Board.new()
local x,y = self:draw_coords(idx) local x,y = self:draw_coords(idx)
local color = v == BLUE and 12 or 8 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)
if self:is_locked(idx) then if self:is_locked(idx) then
line(x, y+w, x+w, y+w, v == BLUE and 6 or 14) rectfill2(x, y, w, w, color)
line(x+w, y, x+w, y+w, v == BLUE and 6 or 14) line(x, y+w-1, x+w-1, y+w-1, v == BLUE and 13 or 2)
line(x+w-1, y, x+w-1, y+w-1, v == BLUE and 13 or 2)
else
roundedrect(x, y, w, w, color)
end end
end end
end, end,

View File

@ -59,7 +59,13 @@ function slice(tbl, first, last, step)
end end
function rectfill2(x, y, w, h, col) function rectfill2(x, y, w, h, col)
rectfill(x, y, x+w, y+h, col) rectfill(x, y, x+w-1, y+h-1, col)
end
function roundedrect(x, y, w, h, col)
rectfill2(x,y,w,h,0)
rectfill2(x+1, y, w-2, h, 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)

View File

@ -9,7 +9,7 @@ function state_menu()
local buttons = { local buttons = {
make_button({x=10, y=10, w=30, text="play", data={i=1}, make_button({x=10, y=10, w=30, text="play", data={i=1},
on_click=function() set_state(states.game) end, on_click=function() set_state(states.loading) end,
on_hover=function(btn) btn.color = 7 selected = 1 end, on_hover=function(btn) btn.color = 7 selected = 1 end,
on_draw=on_btn_draw}), on_draw=on_btn_draw}),
make_button({x=10, y=20, w=30, text="rules", data={i=2}, make_button({x=10, y=20, w=30, text="rules", data={i=2},
@ -42,6 +42,7 @@ function state_menu()
end, end,
_draw = function() _draw = function()
cls()
for k,button in ipairs(buttons) do for k,button in ipairs(buttons) do
button:draw(selected == k) button:draw(selected == k)
end end

View File

@ -33,6 +33,7 @@ function state_rules()
end, end,
_draw=function() _draw=function()
cls()
custom_font() custom_font()
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)