Mapeados los jugadores a los dos mandos
This commit is contained in:
4
Makefile
4
Makefile
@@ -25,7 +25,7 @@ INCLUDES:= -I$(DIR_SOURCES)
|
||||
ifeq ($(OS),Windows_NT)
|
||||
FixPath = $(subst /,\,$1)
|
||||
SOURCES := source/*.cpp source/common/*.cpp
|
||||
CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows
|
||||
CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++
|
||||
LDFLAGS := -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32
|
||||
RM = del /Q
|
||||
MKD:= mkdir
|
||||
@@ -124,7 +124,7 @@ peiv:
|
||||
|
||||
windows:
|
||||
@echo off
|
||||
$(CXX) $(SOURCES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE).exe"
|
||||
$(CXX) $(SOURCES) $(CXXFLAGS) -Wl,-subsystem,windows $(LDFLAGS) -o "$(TARGET_FILE).exe"
|
||||
strip -s -R .comment -R .gnu.version "$(TARGET_FILE).exe" --strip-unneeded
|
||||
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ fadeRandomSquaresMult 500
|
||||
fadePostDuration 50
|
||||
|
||||
#SCOREBOARD
|
||||
scoreboard.x 10
|
||||
scoreboard.x 0
|
||||
scoreboard.y 208
|
||||
scoreboard.w 300
|
||||
scoreboard.w 320
|
||||
scoreboard.h 32
|
||||
|
||||
#TITLE
|
||||
|
||||
@@ -40,19 +40,19 @@ void Input::update()
|
||||
}
|
||||
|
||||
// Asigna inputs a teclas
|
||||
void Input::bindKey(Uint8 input, SDL_Scancode code)
|
||||
void Input::bindKey(inputs_e input, SDL_Scancode code)
|
||||
{
|
||||
keyBindings[input].scancode = code;
|
||||
}
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
|
||||
void Input::bindGameControllerButton(inputs_e input, SDL_GameControllerButton button)
|
||||
{
|
||||
gameControllerBindings[input].button = button;
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
bool Input::checkInput(inputs_e input, bool repeat, int device, int index)
|
||||
{
|
||||
if (!enabled)
|
||||
{
|
||||
@@ -244,7 +244,7 @@ bool Input::discoverGameController()
|
||||
connectedControllers.push_back(pad);
|
||||
const std::string separator(" #");
|
||||
std::string name = SDL_GameControllerNameForIndex(i);
|
||||
name.resize(25);
|
||||
//name.resize(25);
|
||||
name = name + separator + std::to_string(i);
|
||||
if (verbose)
|
||||
{
|
||||
|
||||
@@ -64,10 +64,8 @@ private:
|
||||
bool active; // Indica si está activo
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
||||
|
||||
// Variables
|
||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
||||
std::vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
std::vector<GameControllerBindings_t> gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
||||
@@ -86,13 +84,13 @@ public:
|
||||
void update();
|
||||
|
||||
// Asigna inputs a teclas
|
||||
void bindKey(Uint8 input, SDL_Scancode code);
|
||||
void bindKey(inputs_e input, SDL_Scancode code);
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
|
||||
void bindGameControllerButton(inputs_e input, SDL_GameControllerButton button);
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool checkInput(Uint8 input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0);
|
||||
bool checkInput(inputs_e 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);
|
||||
|
||||
@@ -87,6 +87,7 @@ void Director::initInput()
|
||||
{
|
||||
// Establece si ha de mostrar mensajes
|
||||
input->setVerbose(options->console);
|
||||
input->setVerbose(true);
|
||||
|
||||
// Busca si hay un mando conectado
|
||||
input->discoverGameController();
|
||||
@@ -117,18 +118,27 @@ void Director::initInput()
|
||||
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);
|
||||
input->bindGameControllerButton(input_fire_right, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
|
||||
|
||||
// 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
|
||||
|
||||
// Pone valores por defecto a las opciones de control
|
||||
options->game.input.clear();
|
||||
|
||||
input_t i;
|
||||
i.id = 0;
|
||||
i.name = "MANDO 1";
|
||||
i.deviceType = INPUT_USE_ANY;
|
||||
options->game.input.push_back(i);
|
||||
|
||||
i.id = 1;
|
||||
i.name = "MANDO 2";
|
||||
i.deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
options->game.input.push_back(i);
|
||||
}
|
||||
|
||||
// Inicializa JailAudio
|
||||
@@ -402,11 +412,11 @@ void Director::initOptions()
|
||||
|
||||
input_t inp;
|
||||
inp.id = 0;
|
||||
inp.name = "KEYBOARD";
|
||||
inp.deviceType = INPUT_USE_KEYBOARD;
|
||||
inp.name = "GAME CONTROLLER";
|
||||
inp.deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
options->game.input.push_back(inp);
|
||||
|
||||
inp.id = 0;
|
||||
inp.id = 1;
|
||||
inp.name = "GAME CONTROLLER";
|
||||
inp.deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
options->game.input.push_back(inp);
|
||||
@@ -414,8 +424,6 @@ void Director::initOptions()
|
||||
// Opciones de video
|
||||
options->video.mode = 0;
|
||||
options->video.window.size = 3;
|
||||
// options->video.window.width = options->video.window.size * param->gameWidth;
|
||||
// options->video.window.height = options->video.window.size * param->gameHeight;
|
||||
options->video.filter = FILTER_NEAREST;
|
||||
options->video.vSync = true;
|
||||
options->video.integerScale = true;
|
||||
|
||||
@@ -2767,6 +2767,11 @@ void Game::checkGameInput()
|
||||
screen->incWindowSize();
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_video_shaders, REPEAT_FALSE))
|
||||
{
|
||||
screen->switchShaders();
|
||||
}
|
||||
|
||||
// Modo Demo activo
|
||||
if (demo.enabled)
|
||||
{
|
||||
@@ -2935,6 +2940,10 @@ void Game::checkGameInput()
|
||||
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
136
source/title.cpp
136
source/title.cpp
@@ -77,36 +77,6 @@ void Title::init()
|
||||
fade->setType(FADE_RANDOM_SQUARE);
|
||||
fade->setPost(param->fadePostDuration);
|
||||
demo = true;
|
||||
|
||||
// Pone valores por defecto a las opciones de control
|
||||
options->game.input.clear();
|
||||
|
||||
input_t i;
|
||||
i.id = 0;
|
||||
i.name = "KEYBOARD";
|
||||
i.deviceType = INPUT_USE_KEYBOARD;
|
||||
options->game.input.push_back(i);
|
||||
|
||||
i.id = 0;
|
||||
i.name = "GAME CONTROLLER";
|
||||
i.deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
options->game.input.push_back(i);
|
||||
|
||||
// Comprueba si hay mandos conectados
|
||||
checkInputDevices();
|
||||
|
||||
// Pone valores por defecto. El primer jugador el teclado. El segundo jugador el primer mando
|
||||
deviceIndex.clear();
|
||||
deviceIndex.push_back(availableInputDevices.size() - 1); // El último dispositivo encontrado es el teclado
|
||||
deviceIndex.push_back(0); // El primer mando encontrado. Si no ha encontrado ninguno es el teclado
|
||||
|
||||
// Si ha encontrado un mando se lo asigna al segundo jugador
|
||||
if (input->gameControllerFound())
|
||||
{
|
||||
options->game.input[1].id = availableInputDevices[deviceIndex[1]].id;
|
||||
options->game.input[1].name = availableInputDevices[deviceIndex[1]].name;
|
||||
options->game.input[1].deviceType = availableInputDevices[deviceIndex[1]].deviceType;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
@@ -163,6 +133,12 @@ void Title::update()
|
||||
JA_StopMusic();
|
||||
break;
|
||||
|
||||
case 1: // 2 PLAYER
|
||||
section->name = SECTION_PROG_GAME;
|
||||
section->subsection = SUBSECTION_GAME_PLAY_2P;
|
||||
JA_StopMusic();
|
||||
break;
|
||||
|
||||
case 3: // TIME OUT
|
||||
section->name = SECTION_PROG_GAME_DEMO;
|
||||
break;
|
||||
@@ -273,6 +249,7 @@ void Title::checkInput()
|
||||
{
|
||||
fade->activate();
|
||||
postFade = 0;
|
||||
postFade = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,105 +286,6 @@ void Title::run()
|
||||
}
|
||||
}
|
||||
|
||||
// Modifica las opciones para los controles de los jugadores
|
||||
bool Title::updatePlayerInputs(int numPlayer)
|
||||
{
|
||||
const int numDevices = availableInputDevices.size();
|
||||
|
||||
if (!input->gameControllerFound())
|
||||
{ // Si no hay mandos se deja todo de manera prefijada
|
||||
deviceIndex[0] = 0;
|
||||
deviceIndex[1] = 0;
|
||||
|
||||
options->game.input[0].id = -1;
|
||||
options->game.input[0].name = "KEYBOARD";
|
||||
options->game.input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||
|
||||
options->game.input[1].id = 0;
|
||||
options->game.input[1].name = "GAME CONTROLLER";
|
||||
options->game.input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{ // Si hay mas de un dispositivo, se recorre el vector
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "numplayer:" << numPlayer << std::endl;
|
||||
std::cout << "deviceindex:" << deviceIndex[numPlayer] << std::endl;
|
||||
}
|
||||
|
||||
// Incrementa el indice
|
||||
if (deviceIndex[numPlayer] < numDevices - 1)
|
||||
{
|
||||
deviceIndex[numPlayer]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceIndex[numPlayer] = 0;
|
||||
}
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "deviceindex:" << deviceIndex[numPlayer] << std::endl;
|
||||
}
|
||||
|
||||
// Si coincide con el del otro jugador, se lo intercambian
|
||||
if (deviceIndex[0] == deviceIndex[1])
|
||||
{
|
||||
const int theOtherPlayer = (numPlayer + 1) % 2;
|
||||
deviceIndex[theOtherPlayer]--;
|
||||
if (deviceIndex[theOtherPlayer] < 0)
|
||||
{
|
||||
deviceIndex[theOtherPlayer] = numDevices - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador
|
||||
options->game.input[0] = availableInputDevices[deviceIndex[0]];
|
||||
options->game.input[1] = availableInputDevices[deviceIndex[1]];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones
|
||||
void Title::checkInputDevices()
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Filling devices for options menu..." << std::endl;
|
||||
}
|
||||
input->discoverGameController();
|
||||
const int numControllers = input->getNumControllers();
|
||||
availableInputDevices.clear();
|
||||
input_t temp;
|
||||
|
||||
// Añade todos los mandos
|
||||
if (numControllers > 0)
|
||||
for (int i = 0; i < numControllers; ++i)
|
||||
{
|
||||
temp.id = i;
|
||||
temp.name = input->getControllerName(i);
|
||||
temp.deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
availableInputDevices.push_back(temp);
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Device " << (int)availableInputDevices.size() << " - " << temp.name.c_str() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Añade el teclado al final
|
||||
temp.id = -1;
|
||||
temp.name = "KEYBOARD";
|
||||
temp.deviceType = INPUT_USE_KEYBOARD;
|
||||
availableInputDevices.push_back(temp);
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Device " << (int)availableInputDevices.size() << " - " << temp.name.c_str() << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Recarga las texturas
|
||||
void Title::reLoadTextures()
|
||||
{
|
||||
|
||||
@@ -61,9 +61,6 @@ private:
|
||||
Uint8 postFade; // Opción a realizar cuando termina el fundido
|
||||
options_t *options; // Variable con todas las variables de las opciones del programa
|
||||
param_t *param; // Puntero con todos los parametros del programa
|
||||
options_t optionsPrevious; // Variable de respaldo para las opciones
|
||||
std::vector<input_t> availableInputDevices; // Vector con todos los metodos de control disponibles
|
||||
std::vector<int> deviceIndex; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles
|
||||
|
||||
// Inicializa los valores de las variables
|
||||
void init();
|
||||
@@ -83,12 +80,6 @@ private:
|
||||
// Cambia el valor de la variable de modo de pantalla completa
|
||||
void switchFullScreenModeVar();
|
||||
|
||||
// Modifica las opciones para los controles de los jugadores
|
||||
bool updatePlayerInputs(int numPlayer);
|
||||
|
||||
// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones
|
||||
void checkInputDevices();
|
||||
|
||||
// Recarga las texturas
|
||||
void reLoadTextures();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user