Reasignados los controles para ordenador, mando y consola

This commit is contained in:
2023-02-12 18:50:40 +01:00
parent ca99857b5b
commit cbb5d54250
8 changed files with 154 additions and 140 deletions

View File

@@ -11,17 +11,15 @@ Input::Input(std::string file)
keyBindings_t kb;
kb.scancode = 0;
kb.active = false;
keyBindings.resize(17, kb);
keyBindings.resize(input_number_of_inputs, kb);
GameControllerBindings_t gcb;
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
gcb.active = false;
gameControllerBindings.resize(17, gcb);
gameControllerBindings.resize(input_number_of_inputs, gcb);
verbose = true;
enabled = true;
numGamepads = 0;
}
// Actualiza el estado del objeto

View File

@@ -7,23 +7,30 @@
#ifndef INPUT_H
#define INPUT_H
#define INPUT_NULL 0
#define INPUT_UP 1
#define INPUT_DOWN 2
#define INPUT_LEFT 3
#define INPUT_RIGHT 4
#define INPUT_ACCEPT 5
#define INPUT_CANCEL 6
#define INPUT_BUTTON_1 7
#define INPUT_BUTTON_2 8
#define INPUT_BUTTON_3 9
#define INPUT_BUTTON_4 10
#define INPUT_BUTTON_5 11
#define INPUT_BUTTON_6 12
#define INPUT_BUTTON_7 13
#define INPUT_BUTTON_8 14
#define INPUT_BUTTON_PAUSE 15
#define INPUT_BUTTON_ESCAPE 16
enum inputs_e
{
// Inputs obligatorios
input_null,
input_up,
input_down,
input_left,
input_right,
input_pause,
input_exit,
input_accept,
input_cancel,
// Inputs personalizados
input_fire_left,
input_fire_center,
input_fire_right,
input_window_fullscreen,
input_window_inc_size,
input_window_dec_size,
// Input obligatorio
input_number_of_inputs
};
#define REPEAT_TRUE true
#define REPEAT_FALSE false
@@ -81,7 +88,7 @@ public:
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
// Comprueba si un input esta activo
bool checkInput(Uint8 input, bool repeat, int device = INPUT_USE_ANY, int index = 0);
bool checkInput(Uint8 input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0);
// Comprueba si hay almenos un input activo
bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0);

View File

@@ -851,7 +851,7 @@ void Menu::setDefaultActionWhenCancel(int item)
// Gestiona la entrada de teclado y mando durante el menu
void Menu::checkInput()
{
if (input->checkInput(INPUT_UP, REPEAT_FALSE))
if (input->checkInput(input_up, REPEAT_FALSE))
{
if (decreaseSelectorIndex())
{
@@ -862,7 +862,7 @@ void Menu::checkInput()
}
}
if (input->checkInput(INPUT_DOWN, REPEAT_FALSE))
if (input->checkInput(input_down, REPEAT_FALSE))
{
if (increaseSelectorIndex())
{
@@ -873,7 +873,7 @@ void Menu::checkInput()
}
}
if (input->checkInput(INPUT_ACCEPT, REPEAT_FALSE))
if (input->checkInput(input_accept, REPEAT_FALSE))
{
itemSelected = selector.index;
if (soundAccept)
@@ -882,7 +882,7 @@ void Menu::checkInput()
}
}
if (input->checkInput(INPUT_CANCEL, REPEAT_FALSE))
if (input->checkInput(input_cancel, REPEAT_FALSE))
{
itemSelected = defaultActionWhenCancel;
if (soundCancel)

View File

@@ -78,31 +78,46 @@ Director::~Director()
// Inicializa el objeto input
void Director::initInput()
{
// Teclado
input->bindKey(INPUT_UP, SDL_SCANCODE_UP);
input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
input->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
input->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
input->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q);
input->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W);
input->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E);
input->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE
input->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE
// Establece si ha de mostrar mensajes
input->setVerbose(options->console);
// Mando
input->bindGameControllerButton(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
input->bindGameControllerButton(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
input->bindGameControllerButton(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
input->bindGameControllerButton(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
input->bindGameControllerButton(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_B);
input->bindGameControllerButton(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_A);
input->bindGameControllerButton(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X);
input->bindGameControllerButton(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y);
input->bindGameControllerButton(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B);
input->bindGameControllerButton(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE
input->bindGameControllerButton(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE
// Busca si hay un mando conectado
input->discoverGameController();
// Teclado - Movimiento del jugador
input->bindKey(input_up, SDL_SCANCODE_UP);
input->bindKey(input_down, SDL_SCANCODE_DOWN);
input->bindKey(input_left, SDL_SCANCODE_LEFT);
input->bindKey(input_right, SDL_SCANCODE_RIGHT);
input->bindKey(input_fire_left, SDL_SCANCODE_Q);
input->bindKey(input_fire_center, SDL_SCANCODE_W);
input->bindKey(input_fire_right, SDL_SCANCODE_E);
// Teclado - Otros
input->bindKey(input_accept, SDL_SCANCODE_RETURN);
input->bindKey(input_cancel, SDL_SCANCODE_ESCAPE);
input->bindKey(input_pause, SDL_SCANCODE_ESCAPE);
input->bindKey(input_exit, SDL_SCANCODE_ESCAPE);
// Mando - Movimiento del jugador
input->bindGameControllerButton(input_up, SDL_CONTROLLER_BUTTON_DPAD_UP);
input->bindGameControllerButton(input_down, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
input->bindGameControllerButton(input_left, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
input->bindGameControllerButton(input_right, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
input->bindGameControllerButton(input_fire_left, SDL_CONTROLLER_BUTTON_X);
input->bindGameControllerButton(input_fire_center, SDL_CONTROLLER_BUTTON_Y);
input->bindGameControllerButton(input_fire_right, SDL_CONTROLLER_BUTTON_B);
// Mando - Otros
input->bindGameControllerButton(input_accept, SDL_CONTROLLER_BUTTON_B);
input->bindGameControllerButton(input_cancel, SDL_CONTROLLER_BUTTON_A);
#ifdef GAME_CONSOLE
input->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_BACK);
input->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_START);
#else
input->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_START);
input->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_BACK);
#endif
}
// Inicializa JailAudio
@@ -591,7 +606,7 @@ void Director::setSection(section_t section)
void Director::runLogo()
{
logo = new Logo(renderer, screen, asset);
logo = new Logo(renderer, screen, asset, input);
setSection(logo->run());
delete logo;
}
@@ -675,10 +690,7 @@ void Director::initOnline()
}
}
// OLD
// OLD
if (!options->online.enabled)
{

View File

@@ -3018,33 +3018,34 @@ void Game::checkGameInput()
const int index = 0;
if (demo.dataFile[demo.counter].left == 1)
{
players[index]->setInput(INPUT_LEFT);
players[index]->setInput(input_left);
}
if (demo.dataFile[demo.counter].right == 1)
{
players[index]->setInput(INPUT_RIGHT);
players[index]->setInput(input_right);
}
if (demo.dataFile[demo.counter].noInput == 1)
{
players[index]->setInput(INPUT_NULL);
players[index]->setInput(input_null);
}
if (demo.dataFile[demo.counter].fire == 1)
{
if (players[index]->canFire())
{
players[index]->setInput(INPUT_BUTTON_2);
players[index]->setInput(input_fire_center);
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
players[index]->setFireCooldown(10);
}
}
if (demo.dataFile[demo.counter].fireLeft == 1)
{
if (players[index]->canFire())
{
players[index]->setInput(INPUT_BUTTON_1);
players[index]->setInput(input_fire_left);
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
players[index]->setFireCooldown(10);
}
@@ -3054,14 +3055,14 @@ void Game::checkGameInput()
{
if (players[index]->canFire())
{
players[index]->setInput(INPUT_BUTTON_3);
players[index]->setInput(input_fire_right);
createBullet(players[index]->getPosX() + (players[index]->getWidth() / 2) - 4, players[index]->getPosY() + (players[index]->getHeight() / 2), BULLET_UP, players[index]->isPowerUp(), index);
players[index]->setFireCooldown(10);
}
}
// Comprueba el input de pausa
if (input->checkInput(INPUT_BUTTON_PAUSE, REPEAT_FALSE))
if (input->checkInput(input_pause, REPEAT_FALSE))
{
section.name = PROG_SECTION_TITLE;
}
@@ -3085,32 +3086,32 @@ void Game::checkGameInput()
if (player->isAlive())
{
// Input a la izquierda
if (input->checkInput(INPUT_LEFT, REPEAT_TRUE, options->input[i].deviceType, options->input[i].id))
if (input->checkInput(input_left, REPEAT_TRUE, options->input[i].deviceType, options->input[i].id))
{
player->setInput(INPUT_LEFT);
player->setInput(input_left);
demo.keys.left = 1;
}
else
{
// Input a la derecha
if (input->checkInput(INPUT_RIGHT, REPEAT_TRUE, options->input[i].deviceType, options->input[i].id))
if (input->checkInput(input_right, REPEAT_TRUE, options->input[i].deviceType, options->input[i].id))
{
player->setInput(INPUT_RIGHT);
player->setInput(input_right);
demo.keys.right = 1;
}
else
{
// Ninguno de los dos inputs anteriores
player->setInput(INPUT_NULL);
player->setInput(input_null);
demo.keys.noInput = 1;
}
}
// Comprueba el input de disparar al centro
if (input->checkInput(INPUT_BUTTON_2, REPEAT_TRUE, options->input[i].deviceType, options->input[i].id))
if (input->checkInput(input_fire_center, REPEAT_TRUE, options->input[i].deviceType, options->input[i].id))
{
if (player->canFire())
{
player->setInput(INPUT_BUTTON_2);
player->setInput(input_fire_center);
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_UP, player->isPowerUp(), i);
player->setFireCooldown(10);
@@ -3122,11 +3123,11 @@ void Game::checkGameInput()
}
// Comprueba el input de disparar a la izquierda
if (input->checkInput(INPUT_BUTTON_1, REPEAT_TRUE, options->input[i].deviceType, options->input[i].id))
if (input->checkInput(input_fire_left, REPEAT_TRUE, options->input[i].deviceType, options->input[i].id))
{
if (player->canFire())
{
player->setInput(INPUT_BUTTON_1);
player->setInput(input_fire_left);
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_LEFT, player->isPowerUp(), i);
player->setFireCooldown(10);
@@ -3138,11 +3139,11 @@ void Game::checkGameInput()
}
// Comprueba el input de disparar a la derecha
if (input->checkInput(INPUT_BUTTON_3, REPEAT_TRUE, options->input[i].deviceType, options->input[i].id))
if (input->checkInput(input_fire_right, REPEAT_TRUE, options->input[i].deviceType, options->input[i].id))
{
if (player->canFire())
{
player->setInput(INPUT_BUTTON_3);
player->setInput(input_fire_right);
createBullet(player->getPosX() + (player->getWidth() / 2) - 4, player->getPosY() + (player->getHeight() / 2), BULLET_RIGHT, player->isPowerUp(), i);
player->setFireCooldown(10);
@@ -3154,7 +3155,7 @@ void Game::checkGameInput()
}
// Comprueba el input de pausa
if (input->checkInput(INPUT_CANCEL, REPEAT_FALSE, options->input[i].deviceType, options->input[i].id))
if (input->checkInput(input_cancel, REPEAT_FALSE, options->input[i].deviceType, options->input[i].id))
{
section.subsection = GAME_SECTION_PAUSE;
}

View File

@@ -4,12 +4,13 @@
#define END_LOGO 200
// Constructor
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset)
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
{
// Copia la dirección de los objetos
this->renderer = renderer;
this->screen = screen;
this->asset = asset;
this->input = input;
// Reserva memoria para los punteros
eventHandler = new SDL_Event();
@@ -56,47 +57,36 @@ void Logo::checkEventHandler()
section.name = PROG_SECTION_QUIT;
break;
}
}
}
// Cualquier tecla pulsada
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
// Comprueba las entradas
void Logo::checkInput()
{
if (input->checkInput(input_exit, REPEAT_FALSE))
{
switch (eventHandler->key.keysym.scancode)
section.name = PROG_SECTION_QUIT;
}
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE))
{
case SDL_SCANCODE_F:
screen->switchVideoMode();
texture->reLoad();
break;
}
case SDL_SCANCODE_F1:
screen->setWindowSize(1);
texture->reLoad();
break;
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
{
screen->decWindowSize();
}
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
texture->reLoad();
break;
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
{
screen->incWindowSize();
}
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
texture->reLoad();
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
texture->reLoad();
break;
case SDL_SCANCODE_F5:
screen->showNotification("Conectado a Jailers.net");
break;
default:
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE))
{
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
break;
}
}
}
}
@@ -117,6 +107,7 @@ void Logo::renderFade()
void Logo::update()
{
checkEventHandler();
checkInput();
if (SDL_GetTicks() - ticks > ticksSpeed)
{

View File

@@ -2,6 +2,7 @@
#include <SDL2/SDL.h>
#include "common/asset.h"
#include "common/input.h"
#include "common/jail_audio.h"
#include "common/screen.h"
#include "common/sprite.h"
@@ -19,6 +20,7 @@ private:
SDL_Renderer *renderer; // El renderizador de la ventana
Screen *screen; // Objeto encargado de dibujar en pantalla
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
Input *input; // Objeto pata gestionar la entrada
Texture *texture; // Textura con los graficos
SDL_Event *eventHandler; // Manejador de eventos
Sprite *sprite; // Sprite con la textura del logo
@@ -41,12 +43,15 @@ private:
// Comprueba los eventos
void checkEventHandler();
// Comprueba las entradas
void checkInput();
// Dibuja el fade
void renderFade();
public:
// Constructor
Logo(SDL_Renderer *renderer, Screen *screen, Asset *mAsset);
Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input);
// Destructor
~Logo();

View File

@@ -95,25 +95,25 @@ void Player::setInput(Uint8 input)
{
switch (input)
{
case INPUT_LEFT:
case input_left:
velX = -baseSpeed;
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
break;
case INPUT_RIGHT:
case input_right:
velX = baseSpeed;
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
break;
case INPUT_BUTTON_2:
case input_fire_center:
setFiringStatus(PLAYER_STATUS_FIRING_UP);
break;
case INPUT_BUTTON_1:
case input_fire_left:
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
break;
case INPUT_BUTTON_3:
case input_fire_right:
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
break;