From 45f6759baf83c7ca7dc7595daabeb1ba00607cb7 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 9 Apr 2018 17:34:30 +0100 Subject: [PATCH] Added support for WASD controls as well as arrow keys --- breakout/breakout.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/breakout/breakout.c b/breakout/breakout.c index c3d09a8..ced9d4a 100644 --- a/breakout/breakout.c +++ b/breakout/breakout.c @@ -130,13 +130,13 @@ int main(void) { * ---------------- */ - char subSteps = 1; // Draw every N+1 frames, thereby calculating movement more precisely + char subSteps = 0; // Draw every N+1 frames, thereby calculating movement more precisely int targetFPS = 90; // Limit FPS to this value, to stop unneccessary calculations char moveX=0; // Toggled between -1, 0 and 1 by keypresses later int playerScore = 0; - int level = 1; + int level = 2; int playerLives = 3; brick bricks[2048]; // Sets up array for the bricks to be stored in, max no. bricks is 2048 @@ -250,9 +250,15 @@ int main(void) { case SDLK_ESCAPE: go = 0; break; + case SDLK_a: + moveX = -1; + break; case SDLK_LEFT: moveX=-1; break; + case SDLK_d: + moveX = 1; + break; case SDLK_RIGHT: moveX=1; break; @@ -270,10 +276,16 @@ int main(void) { case SDL_KEYUP: switch(incomingEvent.key.keysym.sym) { case SDLK_LEFT: - moveX=0; + moveX = 0; + break; + case SDLK_a: + moveX = 0; break; case SDLK_RIGHT: - moveX=0; + moveX = 0; + break; + case SDLK_d: + moveX = 0; break; } break;