first commit
This commit is contained in:
32
src/engine/keyboard.c
Normal file
32
src/engine/keyboard.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include "keyboard.h"
|
||||
|
||||
void
|
||||
keyboard_update(Keyboard* self)
|
||||
{
|
||||
const u8* state;
|
||||
|
||||
memcpy(&self->previous, &self->current, sizeof(u8) * KEYBOARD_KEY_COUNT);
|
||||
memset(&self->current, '\0', sizeof(u8) * KEYBOARD_KEY_COUNT);
|
||||
|
||||
state = SDL_GetKeyboardState(NULL);
|
||||
|
||||
memcpy(&self->current, state, KEYBOARD_KEY_COUNT);
|
||||
}
|
||||
|
||||
bool
|
||||
keyboard_press(Keyboard* self, KeyboardKeyType type)
|
||||
{
|
||||
return (self->current[type] && !self->previous[type]);
|
||||
}
|
||||
|
||||
bool
|
||||
keyboard_held(Keyboard* self, KeyboardKeyType type)
|
||||
{
|
||||
return (self->current[type] && self->previous[type]);
|
||||
}
|
||||
|
||||
bool
|
||||
keyboard_release(Keyboard* self, KeyboardKeyType type)
|
||||
{
|
||||
return (!self->current[type] && self->previous[type]);
|
||||
}
|
Reference in New Issue
Block a user