|
|
pico-8 cartridge // http://www.pico-8.com
|
|
|
version 39
|
|
|
__lua__
|
|
|
-- maths attacks --
|
|
|
-- by djib --
|
|
|
function _init()
|
|
|
cls(1)
|
|
|
init_btn_status()
|
|
|
end
|
|
|
|
|
|
function _update()
|
|
|
update_btn_status(❎)
|
|
|
update_btn_status(🅾️)
|
|
|
end
|
|
|
|
|
|
function _draw()
|
|
|
draw_keypad()
|
|
|
result=get_input()
|
|
|
if result!="" then
|
|
|
print(get_input(),0)
|
|
|
end
|
|
|
end
|
|
|
-->8
|
|
|
-- button management --
|
|
|
|
|
|
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
|
|
|
-- keypad input --
|
|
|
|
|
|
keys = {
|
|
|
{ --1
|
|
|
dx=0,dy=0,
|
|
|
up=true,down=false,
|
|
|
left=true,right=false
|
|
|
},
|
|
|
{ --2
|
|
|
dx=1,dy=0,
|
|
|
up=true,down=false,
|
|
|
left=false,right=false
|
|
|
},
|
|
|
{ --3
|
|
|
dx=2,dy=0,
|
|
|
up=true,down=false,
|
|
|
left=false,right=true
|
|
|
},
|
|
|
{ --4
|
|
|
dx=0,dy=1,
|
|
|
up=false,down=false,
|
|
|
left=true,right=false
|
|
|
},
|
|
|
{ --5
|
|
|
dx=1,dy=1,
|
|
|
up=false,down=false,
|
|
|
left=false,right=false
|
|
|
},
|
|
|
{ --6
|
|
|
dx=2,dy=1,
|
|
|
up=false,down=false,
|
|
|
left=false,right=true
|
|
|
},
|
|
|
{ --7
|
|
|
dx=0,dy=2,
|
|
|
up=false,down=true,
|
|
|
left=true,right=false
|
|
|
},
|
|
|
{ --8
|
|
|
dx=1,dy=2,
|
|
|
up=false,down=true,
|
|
|
left=false,right=false
|
|
|
},
|
|
|
{ --9
|
|
|
dx=2,dy=2,
|
|
|
up=false,down=true,
|
|
|
left=false,right=true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function get_input()
|
|
|
result=""
|
|
|
if btn_pressed(❎) then
|
|
|
for k,v in pairs(keys) do
|
|
|
if input_matches(v) then
|
|
|
result=tostr(k)
|
|
|
end
|
|
|
end
|
|
|
elseif btn_held(❎) then
|
|
|
result = "0"
|
|
|
elseif btn_pressed(🅾️) then
|
|
|
result = "clear!"
|
|
|
elseif btn_held(🅾️) then
|
|
|
result = "fire!"
|
|
|
end
|
|
|
return result
|
|
|
end
|
|
|
|
|
|
function input_matches(v)
|
|
|
return btn(⬆️)==v.up and
|
|
|
btn(⬇️)==v.down and
|
|
|
btn(⬅️)==v.left and
|
|
|
btn(➡️)==v.right
|
|
|
end
|
|
|
|
|
|
function draw_keypad()
|
|
|
-- size of keys
|
|
|
local delta=8
|
|
|
-- keypad location
|
|
|
local kx=(127-delta*3)/2
|
|
|
local ky=127-delta*3
|
|
|
rectfill(kx-1,ky-1,kx+3*delta,ky+3*delta,0)
|
|
|
|
|
|
for k,v in pairs(keys) do
|
|
|
if input_matches(v) then
|
|
|
offset=16
|
|
|
else
|
|
|
offset=0
|
|
|
end
|
|
|
spr(k+offset,
|
|
|
kx+v.dx*delta,
|
|
|
ky+v.dy*delta
|
|
|
)
|
|
|
end
|
|
|
end
|
|
|
__gfx__
|
|
|
66666660666666606666666066666660666666606666666066666660666666606666666066666660000000000000000000000000000000000000000000000000
|
|
|
67111765671177656711176567111765671717656711176567111765671117656711176567111765000000000000000000000000000000000000000000000000
|
|
|
67171765677177656777176567771765671717656717776567177765677717656717176567171765000000000000000000000000000000000000000000000000
|
|
|
67171765677177656711176567711765671117656711176567111765677117656711176567111765000000000000000000000000000000000000000000000000
|
|
|
67171765677177656717776567771765677717656777176567171765677717656717176567771765000000000000000000000000000000000000000000000000
|
|
|
67111765671117656711176567111765677717656711176567111765677717656711176567771765000000000000000000000000000000000000000000000000
|
|
|
66666665666666656666666566666665666666656666666566666665666666656666666566666665000000000000000000000000000000000000000000000000
|
|
|
05555555055555550555555505555555055555550555555505555555055555550555555505555555000000000000000000000000000000000000000000000000
|
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
|
06666666066666660666666606666666066666660666666606666666066666660666666606666666000000000000000000000000000000000000000000000000
|
|
|
06711176067117760671117606711176067171760671117606711176067111760671117606711176000000000000000000000000000000000000000000000000
|
|
|
06717176067717760677717606777176067171760671777606717776067771760671717606717176000000000000000000000000000000000000000000000000
|
|
|
06717176067717760671117606771176067111760671117606711176067711760671117606711176000000000000000000000000000000000000000000000000
|
|
|
06717176067717760671777606777176067771760677717606717176067771760671717606777176000000000000000000000000000000000000000000000000
|
|
|
06711176067111760671117606711176067771760671117606711176067771760671117606777176000000000000000000000000000000000000000000000000
|
|
|
06666666066666660666666606666666066666660666666606666666066666660666666606666666000000000000000000000000000000000000000000000000
|