Add gamepad support

This commit is contained in:
2025-06-19 10:33:04 -05:00
parent 78837b3212
commit f023a1f052

View File

@ -11,9 +11,14 @@
typedef struct {
int32_t key;
uint8_t bind;
} inputmap_t;
} inputkbmap_t;
inputmap_t INPUT_MAP[] = {
typedef struct {
GamepadButton button;
uint8_t bind;
} inputgpmap_t;
inputkbmap_t INPUT_KB_MAP[] = {
{ KEY_UP, INPUT_BIND_UP },
{ KEY_W, INPUT_BIND_UP },
{ KEY_DOWN, INPUT_BIND_DOWN },
@ -34,12 +39,36 @@ inputmap_t INPUT_MAP[] = {
{ 0, 0 }
};
inputgpmap_t INPUT_GP_MAP[] = {
{ GAMEPAD_BUTTON_LEFT_FACE_UP, INPUT_BIND_UP },
{ GAMEPAD_BUTTON_LEFT_FACE_DOWN, INPUT_BIND_DOWN },
{ GAMEPAD_BUTTON_LEFT_FACE_LEFT, INPUT_BIND_LEFT },
{ GAMEPAD_BUTTON_LEFT_FACE_RIGHT, INPUT_BIND_RIGHT },
{ GAMEPAD_BUTTON_RIGHT_FACE_RIGHT, INPUT_BIND_ACTION },
{ GAMEPAD_BUTTON_RIGHT_FACE_DOWN, INPUT_BIND_CANCEL },
{ 0, 0 }
};
uint8_t inputStateGet() {
uint8_t state = 0;
inputmap_t *map = INPUT_MAP;
inputkbmap_t *kbMap = INPUT_KB_MAP;
do {
if(IsKeyDown(map->key)) state |= map->bind;
map++;
} while(map->key != 0);
if(IsKeyDown(kbMap->key)) state |= kbMap->bind;
kbMap++;
} while(kbMap->key != 0);
for(uint32_t i = 0; i < 32; i++) {
if(!IsGamepadAvailable(i)) continue;
inputgpmap_t *gpMap = INPUT_GP_MAP;
do {
if(IsGamepadButtonDown(i, gpMap->button)) state |= gpMap->bind;
gpMap++;
} while(gpMap->button != 0);
}
return state;
}