118 lines
2.7 KiB
Lua
118 lines
2.7 KiB
Lua
pico-8 cartridge // http://www.pico-8.com
|
||
version 37
|
||
__lua__
|
||
-- maths attacks --
|
||
-- by djib --
|
||
function _init()
|
||
cls()
|
||
init_btn_status()
|
||
end
|
||
|
||
function _update()
|
||
update_btn_status(❎)
|
||
update_btn_status(🅾️)
|
||
end
|
||
|
||
function _draw()
|
||
result=get_input()
|
||
if result!="" then
|
||
print(get_input())
|
||
end
|
||
end
|
||
-->8
|
||
-- buttons --
|
||
|
||
function init_btn_status()
|
||
-- no repeating delay for keyboard
|
||
poke(0x5f5d,255)
|
||
-- true when pressed
|
||
btn_down_status={}
|
||
-- true when quickly released
|
||
btn_up_status={}
|
||
-- true when held
|
||
btn_held_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 --
|
||
elseif btn_down_status[button] then
|
||
-- button was held
|
||
if btnp(button) then
|
||
btn_held_status[button]=true
|
||
btn_down_status[button]=false
|
||
end
|
||
-- button no longer pressed
|
||
if not btn(button) then
|
||
btn_up_status[button]=true
|
||
btn_down_status[button]=false
|
||
end
|
||
else
|
||
if btnp(button) then
|
||
btn_down_status[button]=true
|
||
end
|
||
if not btn(button) then
|
||
btn_held_status[button]=false
|
||
btn_down_status[button]=false
|
||
btn_up_status[button]=false
|
||
end
|
||
end
|
||
end
|
||
|
||
function btn_held(button)
|
||
return btn_held_status[button]
|
||
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
|
||
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|