Add basic implementation of game input
This commit is contained in:
@ -4,6 +4,7 @@ __lua__
|
|||||||
-- maths attacks --
|
-- maths attacks --
|
||||||
-- by djib --
|
-- by djib --
|
||||||
function _init()
|
function _init()
|
||||||
|
cls()
|
||||||
init_btn_status()
|
init_btn_status()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -13,9 +14,10 @@ function _update()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function _draw()
|
function _draw()
|
||||||
cls()
|
result=get_input()
|
||||||
print("❎ - pressed:"..tostr(btn_pressed(❎)).." - held:"..tostr(btn_held(❎)),1,1)
|
if result!="" then
|
||||||
print("🅾️ - pressed:"..tostr(btn_pressed(🅾️)).." - held:"..tostr(btn_held(🅾️)),1,10)
|
print(get_input())
|
||||||
|
end
|
||||||
end
|
end
|
||||||
-->8
|
-->8
|
||||||
-- buttons --
|
-- buttons --
|
||||||
@ -32,8 +34,11 @@ function init_btn_status()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function update_btn_status(button)
|
function update_btn_status(button)
|
||||||
|
-- clear held status
|
||||||
|
if btn_held_status[button] then
|
||||||
|
btn_held_status[button]=false
|
||||||
-- button was already pressed --
|
-- button was already pressed --
|
||||||
if btn_down_status[button] then
|
elseif btn_down_status[button] then
|
||||||
-- button was held
|
-- button was held
|
||||||
if btnp(button) then
|
if btnp(button) then
|
||||||
btn_held_status[button]=true
|
btn_held_status[button]=true
|
||||||
@ -63,6 +68,46 @@ end
|
|||||||
function btn_pressed(button)
|
function btn_pressed(button)
|
||||||
return btn_up_status[button]
|
return btn_up_status[button]
|
||||||
end
|
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__
|
__gfx__
|
||||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
Reference in New Issue
Block a user