![KikooDX](/assets/img/avatar_default.png)
- [input] Completely rewrote most of the code - [input/camera] Renamed `*_draw` functions used in debug section to `*_draw_debug` - [main/input] Now use `_Bool` instead of `int` when appropriate - [input] Added function `input_is_up` - [player] Added function `player_draw_debug` - [vec] Use `int` instead of `float`, new macro `VEC_PRECISION` - [main/camera/player/vec] Updated vector related code to work with the new system
62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
#include <gint/keyboard.h>
|
|
#include <gint/display.h>
|
|
|
|
#include "input.h"
|
|
|
|
void input_step(Input *input)
|
|
{
|
|
/* read all inputs */
|
|
clearevents();
|
|
/* for each key, update it's state */
|
|
for (int i = 0; i < KEYS_COUNT; ++i)
|
|
{
|
|
uint8_t *state = &input->states[i];
|
|
uint8_t key = input->keys[i];
|
|
/* get if the key is pressed */
|
|
_Bool pressed = keydown(key);
|
|
/* update input status */
|
|
if (pressed)
|
|
{
|
|
*state = (*state == S_RELEASED || *state == S_UP) ? S_PRESSED : S_DOWN;
|
|
}
|
|
else
|
|
{
|
|
*state = (*state == S_PRESSED || *state == S_DOWN) ? S_RELEASED : S_UP;
|
|
}
|
|
}
|
|
}
|
|
|
|
void input_draw_debug(Input *input)
|
|
{
|
|
for (int i = 0; i < KEYS_COUNT; ++i)
|
|
{
|
|
dprint(0, i * 10, C_BLACK, "%d", i);
|
|
dprint(16, i * 10, C_BLACK, "%d", input->states[i]);
|
|
dprint(32, i * 10, C_BLACK, "D%d", input_is_down(input, i));
|
|
dprint(48, i * 10, C_BLACK, "P%d", input_is_pressed(input, i));
|
|
dprint(64, i * 10, C_BLACK, "U%d", input_is_up(input, i));
|
|
dprint(80, i * 10, C_BLACK, "R%d", input_is_released(input, i));
|
|
dprint(96, i * 10, C_BLACK, "V%d", (int)input_is_down(input, i));
|
|
}
|
|
}
|
|
|
|
_Bool input_is_pressed(Input *input, uint8_t key)
|
|
{
|
|
return input->states[key] == S_PRESSED;
|
|
}
|
|
|
|
_Bool input_is_down(Input *input, uint8_t key)
|
|
{
|
|
return (input->states[key] == S_DOWN) || (input->states[key] == S_PRESSED);
|
|
}
|
|
|
|
_Bool input_is_released(Input *input, uint8_t key)
|
|
{
|
|
return input->states[key] == S_RELEASED;
|
|
}
|
|
|
|
_Bool input_is_up(Input *input, uint8_t key)
|
|
{
|
|
return (input->states[key] == S_UP) || (input->states[key] == S_RELEASED);
|
|
}
|