Buttons mostly ok

This commit is contained in:
2022-06-01 21:26:57 +02:00
parent d1946315e9
commit f7dab009b3
5 changed files with 92 additions and 49 deletions
+15 -7
View File
@@ -1,13 +1,21 @@
function stateMenu()
local selected = 1
function onBtnDraw(btn)
if selected == btn.data.i then
btn.color = 7
end
end
local buttons = {
makeButton(10, 10, 30, 6, "play",
function() setState(states.game) end,
function() selected = 1 end),
makeButton(10, 20, 30, 6, "rules",
function() setState(states.rules) end,
function() selected = 2 end)
makeButton({x=10, y=10, w=30, text="play", data={i=1},
onClick=function() setState(states.game) end,
onHover=function(btn) btn.color = 7 selected = 1 end,
onDraw=onBtnDraw}),
makeButton({x=10, y=20, w=30, text="rules", data={i=2},
onClick=function() setState(states.rules) end,
onHover=function(btn) btn.color = 7 selected = 2 end,
onDraw=onBtnDraw})
}
function _enter()
+21 -1
View File
@@ -1,12 +1,19 @@
function stateRules()
local fade = split"0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,4,9,10,9,4,2"
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
function blink(x,y,w,h)
rect2(x,y,w,h,fade[color])
end
function goBack()
setState(states.menu)
end
local btnBack = makeButton({x=1, y=118, w=30, h=7, text="❎ mENU", color=8,
onClick=function() goBack() end,
onHover=function(btn) btn.color = 7 end})
return {
_update=function()
@@ -16,9 +23,18 @@ function stateRules()
if color>#fade then
color = 1
end
-- Back to the menu
if btnp(BTN_X) then
goBack()
end
btnBack:update()
end,
_draw=function()
customFont()
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 y = 28
@@ -61,6 +77,10 @@ function stateRules()
sspr(91,32, 12,12, x+26,y+20)
blink(x-1, y+25, 12, 6)
blink(x+25, y+25, 12, 6)
--------------
btnBack:draw()
end,
}
end