painfull-success-cg/include/input.h

36 lines
671 B
C

#pragma once
#include <stdint.h>
#include <stdbool.h>
#define KEYS_COUNT 6
enum {
K_LEFT,
K_RIGHT,
K_DOWN,
K_JUMP,
K_RESTART,
K_EXIT
};
#define S_PRESSED 0
#define S_DOWN 1
#define S_RELEASED 2
#define S_UP 3
typedef struct Input {
uint8_t keys[KEYS_COUNT];
uint8_t states[KEYS_COUNT];
} Input;
/* Check for new key inputs and update accordingly. */
void input_update(Input *input);
/* Initialize values. */
void input_init(Input *input);
/* Get state of keys. */
bool input_is_pressed(Input *input, uint8_t key);
bool input_is_down(Input *input, uint8_t key);
bool input_is_released(Input *input, uint8_t key);
bool input_is_up(Input *input, uint8_t key);