diff --git a/common.mk b/common.mk index d4d611c..d0fd0db 100644 --- a/common.mk +++ b/common.mk @@ -32,7 +32,7 @@ DEPS += defs.h structs.h OBJS += atlas.o atlasTest.o aquaBlob.o OBJS += battery.o blaze.o bob.o boss.o blobBoss.o bullet.o -OBJS += camera.o cannon.o cardReader.o cell.o cherry.o combat.o consumable.o +OBJS += camera.o cannon.o cardReader.o cell.o cherry.o combat.o controls.o consumable.o OBJS += debris.o destructable.o door.o draw.o OBJS += effects.o ending.o entities.o entity.o entityFactory.o exit.o explosions.o eyeDroid.o eyeDroidCommander.o evilBlob.o OBJS += fleshChunk.o frost.o diff --git a/src/structs.h b/src/structs.h index 034192c..6e966ff 100644 --- a/src/structs.h +++ b/src/structs.h @@ -323,6 +323,9 @@ typedef struct { int hideMouse; Mouse mouse; int keyboard[MAX_KEYBOARD_KEYS]; + int joypad[SDL_CONTROLLER_BUTTON_MAX]; + int keyControls[CONTROL_MAX]; + int joypadControls[CONTROL_MAX]; SDL_Texture *backBuffer; SDL_Renderer *renderer; SDL_Window *window; @@ -358,7 +361,7 @@ typedef struct { int isComplete; char **mias; char **targets; - int keys[MAX_KEY_TYPES][MAX_NAME_LENGTH]; + Tuple keys[MAX_KEY_TYPES]; Tuple missionStatusHead, *missionStatusTail; Config config; } Game; diff --git a/src/system/controls.c b/src/system/controls.c new file mode 100644 index 0000000..cbbc76d --- /dev/null +++ b/src/system/controls.c @@ -0,0 +1,57 @@ +/* +Copyright (C) 2015-2017 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "controls.h" + +int isControl(int type) +{ + int key = app.keyControls[type]; + int btn = app.joypadControls[type]; + + return ((key != 0 && app.keyboard[key]) || (btn != 0 && app.joypad[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]; + int btn = app.joypadControls[type]; + + if (key != 0) + { + app.keyboard[key] = 0; + } + + if (btn != 0) + { + app.joypad[btn] = 0; + } +} + +void resetAcceptControls(void) +{ + app.keyboard[SDL_SCANCODE_SPACE] = app.keyboard[SDL_SCANCODE_RETURN] = 0; + + clearControl(CONTROL_FIRE); +} diff --git a/src/system/controls.h b/src/system/controls.h new file mode 100644 index 0000000..2ed81bd --- /dev/null +++ b/src/system/controls.h @@ -0,0 +1,23 @@ +/* +Copyright (C) 2018 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "../common.h" + +extern App app;