Mapeados los jugadores a los dos mandos
This commit is contained in:
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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user