Added controls.c.

This commit is contained in:
Steve 2018-02-05 22:08:35 +00:00
parent cc280f326f
commit 89b4b05a11
4 changed files with 85 additions and 2 deletions

View File

@ -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

View File

@ -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;

57
src/system/controls.c Normal file
View File

@ -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);
}

23
src/system/controls.h Normal file
View File

@ -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;