diff options
Diffstat (limited to 'src/input.c')
-rw-r--r-- | src/input.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/input.c b/src/input.c new file mode 100644 index 0000000..86264b3 --- /dev/null +++ b/src/input.c @@ -0,0 +1,38 @@ +#include "input.h" +#include "lzy.h" + +static const unsigned int keys[6] = {LZYK_LEFT, LZYK_RIGHT, LZYK_UP, + LZYK_DOWN, LZYK_O, LZYK_X}; +static int states[6] = {0}; + +void input_update(void) +{ + int i = 6; + while (i-- > 0) + if (LZY_KeyDown(keys[i])) + states[i] = + (states[i] == KS_UP) ? (KS_PRESSED) : (KS_DOWN); + else + states[i] = KS_UP; +} + +int input_up(unsigned int k) +{ + if (k >= 6) + return 0; + return states[k] == KS_UP; +} + +int input_down(unsigned int k) +{ + if (k >= 6) + return 0; + return states[k] == KS_DOWN; +} + +int input_pressed(unsigned int k) +{ + if (k >= 6) + return 0; + return states[k] == KS_PRESSED; +} |