SDL Joypad controls for MBC7 games
This commit is contained in:
parent
4f91b19a94
commit
197a475fab
13
SDL/main.c
13
SDL/main.c
@ -272,9 +272,14 @@ static void handle_events(GB_gameboy_t *gb)
|
|||||||
|
|
||||||
case SDL_JOYAXISMOTION: {
|
case SDL_JOYAXISMOTION: {
|
||||||
static bool axis_active[2] = {false, false};
|
static bool axis_active[2] = {false, false};
|
||||||
|
static double accel_values[2] = {0, 0};
|
||||||
joypad_axis_t axis = get_joypad_axis(event.jaxis.axis);
|
joypad_axis_t axis = get_joypad_axis(event.jaxis.axis);
|
||||||
if (axis == JOYPAD_AXISES_X) {
|
if (axis == JOYPAD_AXISES_X) {
|
||||||
if (event.jaxis.value > JOYSTICK_HIGH) {
|
if (GB_has_accelerometer(gb)) {
|
||||||
|
accel_values[0] = event.jaxis.value / (double)32768.0;
|
||||||
|
GB_set_accelerometer_values(gb, -accel_values[0], -accel_values[1]);
|
||||||
|
}
|
||||||
|
else if (event.jaxis.value > JOYSTICK_HIGH) {
|
||||||
axis_active[0] = true;
|
axis_active[0] = true;
|
||||||
GB_set_key_state(gb, GB_KEY_RIGHT, true);
|
GB_set_key_state(gb, GB_KEY_RIGHT, true);
|
||||||
GB_set_key_state(gb, GB_KEY_LEFT, false);
|
GB_set_key_state(gb, GB_KEY_LEFT, false);
|
||||||
@ -291,7 +296,11 @@ static void handle_events(GB_gameboy_t *gb)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (axis == JOYPAD_AXISES_Y) {
|
else if (axis == JOYPAD_AXISES_Y) {
|
||||||
if (event.jaxis.value > JOYSTICK_HIGH) {
|
if (GB_has_accelerometer(gb)) {
|
||||||
|
accel_values[1] = event.jaxis.value / (double)32768.0;
|
||||||
|
GB_set_accelerometer_values(gb, -accel_values[0], -accel_values[1]);
|
||||||
|
}
|
||||||
|
else if (event.jaxis.value > JOYSTICK_HIGH) {
|
||||||
axis_active[1] = true;
|
axis_active[1] = true;
|
||||||
GB_set_key_state(gb, GB_KEY_DOWN, true);
|
GB_set_key_state(gb, GB_KEY_DOWN, true);
|
||||||
GB_set_key_state(gb, GB_KEY_UP, false);
|
GB_set_key_state(gb, GB_KEY_UP, false);
|
||||||
|
Loading…
Reference in New Issue
Block a user