diff --git a/maths-attacks.p8 b/maths-attacks.p8 index 3f00d5d..069c8f7 100644 --- a/maths-attacks.p8 +++ b/maths-attacks.p8 @@ -4,6 +4,7 @@ __lua__ -- maths attacks -- -- by djib -- function _init() + cls() init_btn_status() end @@ -13,9 +14,10 @@ function _update() end function _draw() - cls() - print("❎ - pressed:"..tostr(btn_pressed(❎)).." - held:"..tostr(btn_held(❎)),1,1) - print("🅾️ - pressed:"..tostr(btn_pressed(🅾️)).." - held:"..tostr(btn_held(🅾️)),1,10) + result=get_input() + if result!="" then + print(get_input()) + end end -->8 -- buttons -- @@ -32,8 +34,11 @@ function init_btn_status() end function update_btn_status(button) + -- clear held status + if btn_held_status[button] then + btn_held_status[button]=false -- button was already pressed -- - if btn_down_status[button] then + elseif btn_down_status[button] then -- button was held if btnp(button) then btn_held_status[button]=true @@ -63,6 +68,46 @@ end function btn_pressed(button) return btn_up_status[button] end +-->8 +-- game logic -- + +function get_input() + result="" + if btn_pressed(❎) then + if btn(⬆️) then + if btn(⬅️) then + result = "1" + elseif btn(➡️) then + result = "3" + else + result = "2" + end + elseif btn(⬇️) then + if btn(⬅️) then + result = "7" + elseif btn(➡️) then + result = "9" + else + result = "8" + end + else + if btn(⬅️) then + result = "4" + elseif btn(➡️) then + result = "6" + else + result = "5" + end + end + elseif btn_held(❎) then + result = "clear!" + elseif btn_pressed(🅾️) then + result = "0" + elseif btn_held(🅾️) then + result = "fire!" + end + return result +end __gfx__ 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000