simple config.h to change keyboard settings

This commit is contained in:
Iris Lightshard 2018-09-25 10:59:52 -07:00
parent bff466bba7
commit 07cee04177
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
5 changed files with 52 additions and 30 deletions

View file

@ -6,7 +6,9 @@
#include "SDL/SDL_ttf.h" #include "SDL/SDL_ttf.h"
#include "SDL/SDL_mixer.h" #include "SDL/SDL_mixer.h"
#include "config.h"
#include "enum.h" #include "enum.h"
#include "Engine.h" #include "Engine.h"
#include "Timer.h" #include "Timer.h"
#include "Player.h" #include "Player.h"
@ -16,6 +18,7 @@
#include "Kaos.h" #include "Kaos.h"
#include "HyperKaos.h" #include "HyperKaos.h"
#include "Scene.h" #include "Scene.h"
#include "extern.h" #include "extern.h"
// //
@ -89,25 +92,25 @@ void interact()
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch (event.key.keysym.sym) switch (event.key.keysym.sym)
{ {
case SDLK_w: case DPAD_UP:
hero->bearing.y = -2; hero->bearing.y = -2;
break; break;
case SDLK_a: case DPAD_LEFT:
hero->bearing.x = -2; hero->bearing.x = -2;
break; break;
case SDLK_s: case DPAD_DOWN:
hero->bearing.y = 2; hero->bearing.y = 2;
break; break;
case SDLK_d: case DPAD_RIGHT:
hero->bearing.x = 2; hero->bearing.x = 2;
break; break;
case SDLK_j: case A_BUTTON:
actionbutton = 1; actionbutton = 1;
break; break;
case SDLK_q: case PAUSE_BUTTON:
pausemenu(); pausemenu();
break; break;
case SDLK_f: case FS_BUTTON:
toggleFullscreen(); toggleFullscreen();
break; break;
default: break; default: break;
@ -116,31 +119,31 @@ void interact()
case SDL_KEYUP: case SDL_KEYUP:
switch( event.key.keysym.sym ) switch( event.key.keysym.sym )
{ {
case SDLK_w: case DPAD_UP:
if (hero->bearing.y < 0) if (hero->bearing.y < 0)
{ {
hero->bearing.y = 0; hero->bearing.y = 0;
} }
break; break;
case SDLK_a: case DPAD_LEFT:
if (hero->bearing.x < 0) if (hero->bearing.x < 0)
{ {
hero->bearing.x = 0 ; hero->bearing.x = 0 ;
} }
break; break;
case SDLK_s: case DPAD_DOWN:
if (hero->bearing.y > 0) if (hero->bearing.y > 0)
{ {
hero->bearing.y = 0; hero->bearing.y = 0;
} }
break; break;
case SDLK_d: case DPAD_RIGHT:
if (hero->bearing.x > 0) if (hero->bearing.x > 0)
{ {
hero->bearing.x = 0; hero->bearing.x = 0;
} }
break; break;
case SDLK_j: case A_BUTTON:
actionbutton = 0; actionbutton = 0;
break; break;
default: break; default: break;
@ -312,17 +315,17 @@ void mainmenu()
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch (event.key.keysym.sym) switch (event.key.keysym.sym)
{ {
case SDLK_w: case DPAD_UP:
menucounter--; menucounter--;
break; break;
case SDLK_s: case DPAD_DOWN:
menucounter++; menucounter++;
break; break;
case SDLK_j: case A_BUTTON:
select = 1; select = 1;
break; break;
case SDLK_f: case FS_BUTTON:
toggleFullscreen(); toggleFullscreen();
break; break;
default: break; default: break;
@ -423,19 +426,19 @@ void pausemenu()
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch (event.key.keysym.sym) switch (event.key.keysym.sym)
{ {
case SDLK_w: case DPAD_UP:
menucounter--; menucounter--;
break; break;
case SDLK_s: case DPAD_DOWN:
menucounter++; menucounter++;
break; break;
case SDLK_j: case A_BUTTON:
select = 1; select = 1;
break; break;
case SDLK_q: case PAUSE_BUTTON:
paused = 0; paused = 0;
break; break;
case SDLK_f: case FS_BUTTON:
toggleFullscreen(); toggleFullscreen();
break; break;
default: break; default: break;

10
Kaos.c
View file

@ -3,6 +3,8 @@
#include "SDL/SDL_ttf.h" #include "SDL/SDL_ttf.h"
#include "SDL/SDL_mixer.h" #include "SDL/SDL_mixer.h"
#include "config.h"
#include "enum.h" #include "enum.h"
#include "Engine.h" #include "Engine.h"
#include "Timer.h" #include "Timer.h"
@ -98,17 +100,17 @@ void runChoice(Kaos* self)
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch(event.key.keysym.sym) switch(event.key.keysym.sym)
{ {
case SDLK_a: case DPAD_LEFT:
case SDLK_d: case DPAD_RIGHT:
if (choice == 0) choice = 1; if (choice == 0) choice = 1;
else choice = 0; else choice = 0;
break; break;
case SDLK_j: case A_BUTTON:
textIsRelevent = 0; textIsRelevent = 0;
if (choice == 0) run(kSelf->path1); if (choice == 0) run(kSelf->path1);
else run(kSelf->path2); else run(kSelf->path2);
break; break;
case SDLK_f: case FS_BUTTON:
toggleFullscreen(); toggleFullscreen();
break; break;
default: break; default: break;

View file

@ -5,6 +5,8 @@
#include <SDL/SDL_ttf.h> #include <SDL/SDL_ttf.h>
#include <SDL/SDL_mixer.h> #include <SDL/SDL_mixer.h>
#include "config.h"
#include "Scene.h" #include "Scene.h"
#include "Timer.h" #include "Timer.h"
#include "Engine.h" #include "Engine.h"
@ -77,10 +79,10 @@ void sceneInput(Scene* self, int* counter)
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch (event.key.keysym.sym) switch (event.key.keysym.sym)
{ {
case SDLK_j: case A_BUTTON:
*counter = self->time - 1; *counter = self->time - 1;
break; break;
case SDLK_f: case FS_BUTTON:
toggleFullscreen(); toggleFullscreen();
break; break;
default: break; default: break;

View file

@ -2,6 +2,9 @@
#include "SDL/SDL_image.h" #include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h" #include "SDL/SDL_ttf.h"
#include "SDL/SDL_mixer.h" #include "SDL/SDL_mixer.h"
#include "config.h"
#include "Engine.h" #include "Engine.h"
#include "Timer.h" #include "Timer.h"
#include "Player.h" #include "Player.h"
@ -77,9 +80,12 @@ void textBoxInput(TextBox* self, int* textIsRelevent)
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch (event.key.keysym.sym) switch (event.key.keysym.sym)
{ {
case SDLK_j: case A_BUTTON:
if (self->cursor < 15) self->cursor += 3; if (self->cursor < 15) self->cursor += 3;
break; break;
case FS_BUTTON:
toggleFullscreen();
break;
default: break; default: break;
} }
} }
@ -103,7 +109,7 @@ void textBoxInput(TextBox* self, int* textIsRelevent)
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch (event.key.keysym.sym) switch (event.key.keysym.sym)
{ {
case SDLK_j: case A_BUTTON:
if (self->scroll + 1 != self->lines) if (self->scroll + 1 != self->lines)
{ {
self->cursor = 0; self->cursor = 0;
@ -112,7 +118,7 @@ void textBoxInput(TextBox* self, int* textIsRelevent)
} }
else *textIsRelevent = 0; else *textIsRelevent = 0;
break; break;
case SDLK_f: case FS_BUTTON:
toggleFullscreen(); toggleFullscreen();
break; break;

9
config.h Normal file
View file

@ -0,0 +1,9 @@
/* see http://sdlk.beuc.net/sdl.wiki/SDLKey for keysyms */
#define DPAD_UP SDLK_w
#define DPAD_DOWN SDLK_s
#define DPAD_LEFT SDLK_a
#define DPAD_RIGHT SDLK_d
#define A_BUTTON SDLK_j
#define FS_BUTTON SDLK_f
#define PAUSE_BUTTON SDLK_q