From 06f7867013be12f2a6680cff4f2302bcf88e5bea Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 27 Mar 2016 08:55:58 +0100 Subject: [PATCH] Use CONTROL_NEXT_FIGHTER / CONTROL_PREV_FIGHTER to select fighters during epic missions. --- src/battle/player.c | 12 ++++++------ src/battle/player.h | 2 ++ src/system/controls.c | 12 ++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/battle/player.c b/src/battle/player.c index 7bf2ca0..a47e192 100644 --- a/src/battle/player.c +++ b/src/battle/player.c @@ -362,27 +362,27 @@ void initPlayerSelect(void) void doPlayerSelect(void) { - if (app.keyboard[SDL_SCANCODE_A] || app.mouse.button[SDL_BUTTON_X1]) + if (isControl(CONTROL_PREV_FIGHTER)) { selectNewPlayer(-1); - app.mouse.button[SDL_BUTTON_X1] = app.keyboard[SDL_SCANCODE_A] = 0; + clearControl(CONTROL_PREV_FIGHTER); } - if (app.keyboard[SDL_SCANCODE_D] || app.mouse.button[SDL_BUTTON_X2]) + if (isControl(CONTROL_NEXT_FIGHTER)) { selectNewPlayer(1); - app.mouse.button[SDL_BUTTON_X2] = app.keyboard[SDL_SCANCODE_D] = 0; + clearControl(CONTROL_NEXT_FIGHTER); } - if (player->health > 0 && app.mouse.button[SDL_BUTTON_LEFT]) + if (player->health > 0 && isAcceptControl()) { battle.playerSelect = 0; initPlayer(); - app.mouse.button[SDL_BUTTON_LEFT] = 0; + resetAcceptControls(); } } diff --git a/src/battle/player.h b/src/battle/player.h index aedfc9f..ace2b8c 100644 --- a/src/battle/player.h +++ b/src/battle/player.h @@ -42,6 +42,8 @@ extern int isControl(int type); extern void clearControl(int type); extern long lookup(char *name); extern Entity *spawnFighter(char *name, int x, int y, int side); +extern int isAcceptControl(void); +extern void resetAcceptControls(void); extern App app; extern Battle battle; diff --git a/src/system/controls.c b/src/system/controls.c index 1120e37..b4a150d 100644 --- a/src/system/controls.c +++ b/src/system/controls.c @@ -80,6 +80,11 @@ int isControl(int type) return ((key != -1 && app.keyboard[key]) || (btn != -1 && app.mouse.button[btn])); } +int isAcceptControl(void) +{ + return (app.keyboard[SDL_SCANCODE_SPACE] ||app.keyboard[SDL_SCANCODE_RETURN] || isControl(CONTROL_FIRE)); +} + void clearControl(int type) { int key = app.keyControls[type]; @@ -96,6 +101,13 @@ void clearControl(int type) } } +void resetAcceptControls(void) +{ + app.keyboard[SDL_SCANCODE_SPACE] = app.keyboard[SDL_SCANCODE_RETURN] = 0; + + clearControl(CONTROL_FIRE); +} + void updateControlKey(char *name) { app.keyControls[lookup(name)] = app.lastKeyPressed;