blobwarsAttrition/src/system/controls.c

79 lines
1.8 KiB
C
Raw Normal View History

2018-02-05 23:08:35 +01:00
/*
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)
{
2018-02-07 20:20:36 +01:00
int key, btn;
2018-02-08 22:53:32 +01:00
key = app.config.keyControls[type];
btn = app.config.joypadControls[type];
2018-02-07 20:20:36 +01:00
if (type == CONTROL_LEFT && app.joypadAxis[JOYPAD_AXIS_X] <= -16384)
{
return 1;
}
if (type == CONTROL_RIGHT && app.joypadAxis[JOYPAD_AXIS_X] >= 16384)
{
return 1;
}
if (type == CONTROL_UP && app.joypadAxis[JOYPAD_AXIS_Y] <= -16384)
{
return 1;
}
if (type == CONTROL_DOWN && app.joypadAxis[JOYPAD_AXIS_Y] >= 16384)
{
return 1;
}
2018-02-05 23:08:35 +01:00
2018-02-07 19:27:42 +01:00
return ((key != 0 && app.keyboard[key]) || (btn != -1 && app.joypadButton[btn]));
2018-02-05 23:08:35 +01:00
}
int isAcceptControl(void)
{
return (app.keyboard[SDL_SCANCODE_SPACE] ||app.keyboard[SDL_SCANCODE_RETURN] || isControl(CONTROL_FIRE));
}
void clearControl(int type)
{
2018-02-08 22:53:32 +01:00
int key = app.config.keyControls[type];
int btn = app.config.joypadControls[type];
2018-02-05 23:08:35 +01:00
if (key != 0)
{
app.keyboard[key] = 0;
}
if (btn != 0)
{
2018-02-06 23:26:05 +01:00
app.joypadButton[btn] = 0;
2018-02-05 23:08:35 +01:00
}
}
void clearControls(void)
2018-02-05 23:08:35 +01:00
{
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
memset(&app.joypadButton, 0, sizeof(int) * SDL_CONTROLLER_BUTTON_MAX);
2018-02-05 23:08:35 +01:00
}