From ccf228f8756f392a6831533ea070352ba1dbe62a Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 8 Feb 2018 21:53:32 +0000 Subject: [PATCH] Control and input updates. --- src/defs.h | 3 ++- src/structs.h | 19 +++++++++---------- src/system/controls.c | 32 ++++++++++++++++---------------- src/world/world.c | 10 +++++----- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/defs.h b/src/defs.h index e9e03f8..43080af 100644 --- a/src/defs.h +++ b/src/defs.h @@ -191,7 +191,8 @@ enum CONTROL_FIRE, CONTROL_JUMP, CONTROL_JETPACK, - CONTROL_STATUS, + CONTROL_PAUSE, + CONTROL_MAP, CONTROL_MAX }; diff --git a/src/structs.h b/src/structs.h index 6409592..1cdb061 100644 --- a/src/structs.h +++ b/src/structs.h @@ -309,6 +309,14 @@ typedef struct { int dragging; } Mouse; +typedef struct { + int fullscreen; + int soundVolume; + int musicVolume; + int keyControls[CONTROL_MAX]; + int joypadControls[CONTROL_MAX]; +} Config; + typedef struct { char saveDir[MAX_FILENAME_LENGTH]; int winWidth; @@ -328,17 +336,9 @@ typedef struct { int awaitingWidgetInput; int lastKeyPressed; int lastButtonPressed; + Config config; } App; -typedef struct { - int fullscreen; - int soundVolume; - int musicVolume; - int control[CONTROL_MAX]; - int keyControls[CONTROL_MAX]; - int joypadControls[CONTROL_MAX]; -} Config; - typedef struct { int cells; int hearts; @@ -361,7 +361,6 @@ typedef struct { char **targets; Tuple keys[MAX_KEY_TYPES]; Tuple missionStatusHead, *missionStatusTail; - Config config; } Game; struct Marker { diff --git a/src/system/controls.c b/src/system/controls.c index 1e4f805..7f33eca 100644 --- a/src/system/controls.c +++ b/src/system/controls.c @@ -24,32 +24,32 @@ void initControls(void) { int i; - game.config.keyControls[CONTROL_LEFT] = SDL_SCANCODE_A; - game.config.keyControls[CONTROL_RIGHT] = SDL_SCANCODE_D; - game.config.keyControls[CONTROL_UP] = SDL_SCANCODE_W; - game.config.keyControls[CONTROL_DOWN] = SDL_SCANCODE_S; - game.config.keyControls[CONTROL_JUMP] = SDL_SCANCODE_I; - game.config.keyControls[CONTROL_FIRE] = SDL_SCANCODE_J; - game.config.keyControls[CONTROL_JETPACK] = SDL_SCANCODE_L; - game.config.keyControls[CONTROL_STATUS] = SDL_SCANCODE_TAB; + app.config.keyControls[CONTROL_LEFT] = SDL_SCANCODE_A; + app.config.keyControls[CONTROL_RIGHT] = SDL_SCANCODE_D; + app.config.keyControls[CONTROL_UP] = SDL_SCANCODE_W; + app.config.keyControls[CONTROL_DOWN] = SDL_SCANCODE_S; + app.config.keyControls[CONTROL_JUMP] = SDL_SCANCODE_I; + app.config.keyControls[CONTROL_FIRE] = SDL_SCANCODE_J; + app.config.keyControls[CONTROL_JETPACK] = SDL_SCANCODE_L; + app.config.keyControls[CONTROL_PAUSE] = SDL_SCANCODE_TAB; /* can't use memset here, as it doesn't work */ for (i = 0 ; i < CONTROL_MAX ; i++) { - game.config.joypadControls[i] = -1; + app.config.joypadControls[i] = -1; } - game.config.joypadControls[CONTROL_JUMP] = 1; - game.config.joypadControls[CONTROL_FIRE] = 3; - game.config.joypadControls[CONTROL_JETPACK] = 2; + app.config.joypadControls[CONTROL_JUMP] = 1; + app.config.joypadControls[CONTROL_FIRE] = 3; + app.config.joypadControls[CONTROL_JETPACK] = 2; } int isControl(int type) { int key, btn; - key = game.config.keyControls[type]; - btn = game.config.joypadControls[type]; + key = app.config.keyControls[type]; + btn = app.config.joypadControls[type]; if (type == CONTROL_LEFT && app.joypadAxis[JOYPAD_AXIS_X] <= -16384) { @@ -81,8 +81,8 @@ int isAcceptControl(void) void clearControl(int type) { - int key = game.config.keyControls[type]; - int btn = game.config.joypadControls[type]; + int key = app.config.keyControls[type]; + int btn = app.config.joypadControls[type]; if (key != 0) { diff --git a/src/world/world.c b/src/world/world.c index 5166529..ced1877 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -242,10 +242,10 @@ static void doWorldInProgress(void) doLocationTriggers(); - if (isControl(CONTROL_STATUS)) + if (isControl(CONTROL_PAUSE)) { world.state = WS_PAUSED; - clearControl(CONTROL_STATUS); + clearControl(CONTROL_PAUSE); } if (world.allObjectivesComplete && world.state != WS_COMPLETE) @@ -315,10 +315,10 @@ static void doWorldPaused(void) { animateSprites(); - if (isControl(CONTROL_STATUS)) + if (isControl(CONTROL_PAUSE)) { world.state = WS_IN_PROGRESS; - clearControl(CONTROL_STATUS); + clearControl(CONTROL_PAUSE); } } @@ -451,7 +451,7 @@ static void spawnEnemies(void) if (x >= world.map.bounds.x && y >= world.map.bounds.y && x < world.map.bounds.w + SCREEN_WIDTH - 64 && y < world.map.bounds.h + SCREEN_HEIGHT - 64) { - sprintf(name, "%s%s", world.enemyTypes[r], (rand() % 2 ? "Blob" : "Droid")); + sprintf(name, "%s%s", world.enemyTypes[r], (rand() % 2 ? "Blob" : "EyeDroid")); u = (Unit*) createEntity(name);