Added support for WASD controls as well as arrow keys

This commit is contained in:
Joe Adams 2018-04-09 17:34:30 +01:00
parent a0a70d69ed
commit 45f6759baf

View File

@ -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 int targetFPS = 90; // Limit FPS to this value, to stop unneccessary calculations
char moveX=0; // Toggled between -1, 0 and 1 by keypresses later char moveX=0; // Toggled between -1, 0 and 1 by keypresses later
int playerScore = 0; int playerScore = 0;
int level = 1; int level = 2;
int playerLives = 3; int playerLives = 3;
brick bricks[2048]; // Sets up array for the bricks to be stored in, max no. bricks is 2048 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: case SDLK_ESCAPE:
go = 0; go = 0;
break; break;
case SDLK_a:
moveX = -1;
break;
case SDLK_LEFT: case SDLK_LEFT:
moveX=-1; moveX=-1;
break; break;
case SDLK_d:
moveX = 1;
break;
case SDLK_RIGHT: case SDLK_RIGHT:
moveX=1; moveX=1;
break; break;
@ -270,10 +276,16 @@ int main(void) {
case SDL_KEYUP: case SDL_KEYUP:
switch(incomingEvent.key.keysym.sym) { switch(incomingEvent.key.keysym.sym) {
case SDLK_LEFT: case SDLK_LEFT:
moveX=0; moveX = 0;
break;
case SDLK_a:
moveX = 0;
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
moveX=0; moveX = 0;
break;
case SDLK_d:
moveX = 0;
break; break;
} }
break; break;