- Moviment
This commit is contained in:
45
source/jinput.cpp
Normal file
45
source/jinput.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "jinput.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
namespace input
|
||||
{
|
||||
static const uint8_t *keys = nullptr;
|
||||
static uint8_t keypressed = 0;
|
||||
static uint8_t keydown = 0;
|
||||
|
||||
void init()
|
||||
{
|
||||
keys = SDL_GetKeyboardState(NULL);
|
||||
}
|
||||
|
||||
// Determina si la tecla especificada està sent polsada ara mateix
|
||||
bool keyDown(const uint8_t key)
|
||||
{
|
||||
return keys[key];
|
||||
}
|
||||
|
||||
// Determina si la tecla especificada ha sigut polsada, pero no tornarà a ser true fins
|
||||
bool keyPressed(const uint8_t key)
|
||||
{
|
||||
return key == keypressed;
|
||||
}
|
||||
|
||||
// Determina si hi ha alguna tecla polsada ara mateix
|
||||
bool anyKey()
|
||||
{
|
||||
return keydown != 0;
|
||||
}
|
||||
|
||||
// Torna el codi de la tecla que està sent polsada ara mateix
|
||||
const uint8_t whichKey()
|
||||
{
|
||||
return keydown;
|
||||
}
|
||||
|
||||
void update(uint8_t key, uint8_t keyp)
|
||||
{
|
||||
keypressed = keyp;
|
||||
keydown = key;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user