From cbc6417dfd16c4e593cdc8ff837ac49be4b1dc28 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Sat, 12 Nov 2016 22:28:07 -0700 Subject: [PATCH] whatever: Joystick can can no longer be used with arrows to double speed --- sdl/whatever/whatever.c | 57 +++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/sdl/whatever/whatever.c b/sdl/whatever/whatever.c index 97c37e0..0bb2e03 100644 --- a/sdl/whatever/whatever.c +++ b/sdl/whatever/whatever.c @@ -71,8 +71,6 @@ int main ( int argc, char *argv[] ) int xDir = 0; int yDir = 0; - SDL_JoyButtonEvent jbutton; - /* message pump */ while (!gameover) { @@ -140,35 +138,37 @@ int main ( int argc, char *argv[] ) /* move the player with the above input */ - gPlayer_dest.x += xDir; - gPlayer_dest.y += yDir; - - const Uint8* currentKeyStates = SDL_GetKeyboardState( NULL ); - if (currentKeyStates[ SDL_SCANCODE_ESCAPE ] || - currentKeyStates[ SDL_SCANCODE_Q ] ) + if (xDir != 0 || yDir != 0) { - gameover = 1; + gPlayer_dest.x += (xDir * movement_speed); + gPlayer_dest.y += (yDir * movement_speed); } - - if (currentKeyStates[ SDL_SCANCODE_LEFT ] ) + else { - gPlayer_dest.x -= movement_speed; - } - if (currentKeyStates[ SDL_SCANCODE_RIGHT ] ) - { - gPlayer_dest.x += movement_speed; - } - if (currentKeyStates[ SDL_SCANCODE_UP ] ) - { - gPlayer_dest.y -= movement_speed; - } - if (currentKeyStates[ SDL_SCANCODE_DOWN ] ) - { - gPlayer_dest.y += movement_speed; - } - - + const Uint8* currentKeyStates = SDL_GetKeyboardState( NULL ); + if (currentKeyStates[ SDL_SCANCODE_ESCAPE ] || + currentKeyStates[ SDL_SCANCODE_Q ] ) + { + gameover = 1; + } + if (currentKeyStates[ SDL_SCANCODE_LEFT ] ) + { + gPlayer_dest.x -= movement_speed; + } + if (currentKeyStates[ SDL_SCANCODE_RIGHT ] ) + { + gPlayer_dest.x += movement_speed; + } + if (currentKeyStates[ SDL_SCANCODE_UP ] ) + { + gPlayer_dest.y -= movement_speed; + } + if (currentKeyStates[ SDL_SCANCODE_DOWN ] ) + { + gPlayer_dest.y += movement_speed; + } + } /* render the background */ SDL_RenderCopy(gRenderer, gBackground_texture, NULL, NULL); @@ -179,10 +179,7 @@ int main ( int argc, char *argv[] ) /* Render here */ SDL_RenderPresent(gRenderer); } - - return 0; - } int init()