sokol input works

This commit is contained in:
nesbox 2018-09-20 17:43:30 +03:00
parent 7149b6cd8a
commit 9a49ef7d02
1 changed files with 31 additions and 0 deletions

View File

@ -302,7 +302,38 @@ static void app_frame(void)
static void app_input(const sapp_event* event) static void app_input(const sapp_event* event)
{ {
static const sapp_keycode Keys[] =
{
SAPP_KEYCODE_UP,
SAPP_KEYCODE_DOWN,
SAPP_KEYCODE_LEFT,
SAPP_KEYCODE_RIGHT,
SAPP_KEYCODE_Z,
SAPP_KEYCODE_X,
SAPP_KEYCODE_A,
SAPP_KEYCODE_S,
};
switch (event->type)
{
case SAPP_EVENTTYPE_KEY_DOWN:
case SAPP_EVENTTYPE_KEY_UP:
for (int i = 0; i < sizeof Keys / sizeof Keys[0]; i++)
{
if (event->key_code == Keys[i])
{
if(event->type == SAPP_EVENTTYPE_KEY_DOWN)
tic_input.gamepads.first.data |= (1 << i);
else
tic_input.gamepads.first.data &= ~(1 << i);
}
}
break;
default:
break;
}
} }
static void app_cleanup(void) static void app_cleanup(void)