From 7a293234c95bee653f11301a34ebe33ed9d0ed02 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sun, 29 May 2022 22:55:43 +0200 Subject: [PATCH] Keyboard navigration + start of rules --- 0hh1.p8 | 53 ++++++++++++++++++++++++++++++++++++++++-------- board.lua | 3 ++- main.lua | 7 ++++++- states/menu.lua | 13 +++++++++++- states/rules.lua | 12 +++++++++++ 5 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 states/rules.lua diff --git a/0hh1.p8 b/0hh1.p8 index 872d28d..cff9c53 100644 --- a/0hh1.p8 +++ b/0hh1.p8 @@ -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 diff --git a/board.lua b/board.lua index 420bb07..473a0db 100644 --- a/board.lua +++ b/board.lua @@ -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), diff --git a/main.lua b/main.lua index c4868e6..0950b03 100644 --- a/main.lua +++ b/main.lua @@ -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 diff --git a/states/menu.lua b/states/menu.lua index 98d3ef8..2e587ab 100644 --- a/states/menu.lua +++ b/states/menu.lua @@ -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 \ No newline at end of file diff --git a/states/rules.lua b/states/rules.lua new file mode 100644 index 0000000..57abda5 --- /dev/null +++ b/states/rules.lua @@ -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 \ No newline at end of file