Keyboard navigration + start of rules

This commit is contained in:
Simon Cambier 2022-05-29 22:55:43 +02:00
parent f793c3e17a
commit 7a293234c9
5 changed files with 77 additions and 11 deletions

53
0hh1.p8
View File

@ -5,12 +5,49 @@ __lua__
#include board.lua
#include states/menu.lua
#include states/game.lua
#include states/rules.lua
__gfx__
00000000110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000171000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700177100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000177710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000177771000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700177710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000171771000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000010171000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000110000000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000171000000001711000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700177100001111771100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000177710001777777100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000177771001777777100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700177710001111771100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000171771000001711000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000010171000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
11011011011001101101101100110110110110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
11011011011001101101101100110110110110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
cc0cc01101100cc0cc08801100cc0cc0880110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
cc0cc01101100cc0cc08801100cc0cc0880110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
11011011011001101101101100110110cc0110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
11011011011001101101101100110110cc0110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
11011088011001101108801100110110880110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
11011088011001101108801100110110880110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

View File

@ -372,7 +372,8 @@ function Board.new()
local margin = 4
for k,v in ipairs(tiles) do
local x,y = self:idx_xy(k)
local color = v == BLUE and 9 or v == YELLOW and 3 or 1
local color = v == BLUE and 12 or v == YELLOW and 8 or 1
if color == 1 then fillp() else fillp() end
rectfill(
margin + (x-1)*w + (x-1)*(padding+1),
margin + (y-1)*w + (y-1)*(padding+1),

View File

@ -7,6 +7,10 @@ poke(0x5F2D, 1)
local BLUE = 1
local YELLOW = 2
-- 🅾️ Z[C]N ❎ [X]VM
-- 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
--
-- Utils
--
@ -161,11 +165,12 @@ function _init()
mouse_y = 0
states = {
rules = stateRules(),
menu = stateMenu(),
game = stateGame()
}
setState(states.menu)
setState(states.rules)
end

View File

@ -1,6 +1,5 @@
function stateMenu()
local items = {"play", "rules"}
local selected = 1
local buttons = {
makeButton(10, 10, 30, 6, "play",
@ -17,16 +16,28 @@ function stateMenu()
return {
_enter = _enter,
_update = function()
for button in all(buttons) do
button:update()
end
if btnp(UP) then
selected -= 1
elseif btnp(DOWN) then
selected += 1
elseif btnp(BTN_O) then
buttons[selected]:onClick()
end
selected = mid(1, selected, #buttons)
end,
_draw = function()
for k,button in ipairs(buttons) do
button:draw(selected == k)
end
print("press 🅾️/c to continue", 8, 120, 7)
end
}
end

12
states/rules.lua Normal file
View File

@ -0,0 +1,12 @@
function stateRules()
return {
_update=function()
end,
_draw=function()
print("1) you can't have more than\n 2 tiles of the same color\n in a row.", 2,2, 7)
sspr(0,32, 12,12, 8,24)
spr(2, 23, 25)
sspr(12,32, 12,12, 34,24)
end,
}
end