From 6f54ba9477c8f2044d5509fea6b0110790f17a63 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sat, 2 Jul 2022 13:52:31 +0200 Subject: [PATCH] Tweaked rendering --- board.lua | 14 ++++++++------ main.lua | 8 +++++++- states/menu.lua | 3 ++- states/rules.lua | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/board.lua b/board.lua index 2c10604..0163738 100644 --- a/board.lua +++ b/board.lua @@ -4,7 +4,6 @@ function Board.new() local width = 10 local tile_width = 10 - local margin = 4 local padding = 1 local tiles = {} local locked = {} -- list of indexes @@ -46,9 +45,10 @@ function Board.new() end, 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 - return margin + (x-1)*tile_width + (x-1)*(padding+1), - margin + (y-1)*tile_width + (y-1)*(padding+1) + return margin + (x-1)*tile_width + (x-1)*padding, + margin + (y-1)*tile_width + (y-1)*padding end, get_size = function(self) @@ -425,10 +425,12 @@ function Board.new() 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) + rectfill2(x, y, w, w, color) + 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, diff --git a/main.lua b/main.lua index 257d652..2706dd9 100644 --- a/main.lua +++ b/main.lua @@ -59,7 +59,13 @@ function slice(tbl, first, last, step) end 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 function rect2(x, y, w, h, col) diff --git a/states/menu.lua b/states/menu.lua index 7119872..4b07530 100644 --- a/states/menu.lua +++ b/states/menu.lua @@ -9,7 +9,7 @@ function state_menu() local buttons = { 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_draw=on_btn_draw}), make_button({x=10, y=20, w=30, text="rules", data={i=2}, @@ -42,6 +42,7 @@ function state_menu() end, _draw = function() + cls() for k,button in ipairs(buttons) do button:draw(selected == k) end diff --git a/states/rules.lua b/states/rules.lua index 92d9af2..9029c28 100644 --- a/states/rules.lua +++ b/states/rules.lua @@ -33,6 +33,7 @@ function state_rules() end, _draw=function() + cls() custom_font() print("1) yOU CAN'T HAVE MORE THAN\n TWO (2) CONSECUTIVE TILES\n OF THE SAME COLOR", 2,2, 7)