painfull-success-cg/include/input.h

44 lines
983 B
C

/* SPDX-License-Identifier: MIT
* Copyright (c) 2021 KikooDX
* This file is part of
* [Painfull Success CG](https://git.sr.ht/~kikoodx/painfull-success-cg),
* which is MIT licensed. The MIT license requires this copyright notice to be
* included in all copies and substantial portions of the software. */
#pragma once
#include "lazyint.h"
#include <stdbool.h>
#define KEYS_COUNT 8
enum {
K_LEFT,
K_RIGHT,
K_DOWN,
K_JUMP,
K_RESTART,
K_CAM_UP,
K_CAM_DOWN,
K_EXIT
};
#define S_PRESSED 0
#define S_DOWN 1
#define S_RELEASED 2
#define S_UP 3
typedef struct Input {
u8 keys[KEYS_COUNT];
u8 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, u8 key);
bool input_is_down(Input input, u8 key);
bool input_is_released(Input input, u8 key);
bool input_is_up(Input input, u8 key);