Añadida opción para intercambiar los jugadores de los dos primeros mandos

This commit is contained in:
2024-09-11 13:59:40 +02:00
parent ecf34558f4
commit 3d41da0fdf
5 changed files with 55 additions and 38 deletions

View File

@@ -69,7 +69,7 @@ void DefineButtons::render()
{
if (enabled)
{
text->writeCentered(x, y - 10, "JUGADOR " + std::to_string(indexController + 1));
text->writeCentered(x, y - 10, "JUGADOR " + std::to_string(options->controller[indexController].playerId));
text->writeCentered(x, y, controllerNames[indexController]);
text->writeCentered(x, y + 10, buttons[indexButton].label);
}
@@ -117,7 +117,9 @@ void DefineButtons::checkInput()
}
if (event.type == SDL_CONTROLLERBUTTONDOWN)
{
doControllerButtonDown(&event.cbutton);
}
}
}
}
@@ -171,4 +173,12 @@ void DefineButtons::saveBindingsToOptions()
{
options->controller[indexController].buttons[j] = input->getControllerBinding(indexController, options->controller[indexController].inputs[j]);
}
}
// Intercambia los jugadores asignados a los dos primeros mandos
void DefineButtons::swapControllers()
{
const int temp = options->controller[0].playerId;
options->controller[0].playerId = options->controller[1].playerId;
options->controller[1].playerId = temp;
}

View File

@@ -65,4 +65,7 @@ public:
// Comprueba si está habilitado
bool isEnabled();
// Intercambia los jugadores asignados a los dos primeros mandos
void swapControllers();
};

View File

@@ -877,7 +877,7 @@ void Director::runTitle()
// Ejecuta la sección donde se juega al juego
void Director::runGame()
{
const int playerID = section->options == SECTION_OPTIONS_GAME_PLAY_1P ? 0 : 1;
const int playerID = section->options;
game = new Game(playerID, 0, screen, asset, lang, input, false, param, options, section, getMusic(musics, "playing.ogg"));
game->run();
delete game;

View File

@@ -122,11 +122,14 @@ void Game::init(int playerID)
player2->setController(controller2);
players.push_back(player2);
// Obtiene el "id" del jugador que va a jugar
Player *player = getPlayer(playerID);
// Cambia el estado del jugador seleccionado
players[playerID]->setStatusPlaying(PLAYER_STATUS_PLAYING);
player->setStatusPlaying(PLAYER_STATUS_PLAYING);
// Como es el principio del juego, empieza sin inmunidad
players[playerID]->setInvulnerable(false);
player->setInvulnerable(false);
// Variables relacionadas con la dificultad
switch (difficulty)
@@ -224,8 +227,9 @@ void Game::init(int playerID)
// Activa o no al otro jugador
if (rand() % 2 == 0)
{
const int otherPlayer = playerID == 1 ? 1 : 0;
players[otherPlayer]->setStatusPlaying(PLAYER_STATUS_PLAYING);
const int otherPlayer = playerID == 1 ? 2 : 1;
Player *player = getPlayer(otherPlayer);
player->setStatusPlaying(PLAYER_STATUS_PLAYING);
}
for (auto player : players)

View File

@@ -91,26 +91,16 @@ void Title::update()
fade->update();
if (fade->hasEnded())
{
switch (postFade)
if (postFade == -1)
{
case 1: // 1 PLAYER
section->name = SECTION_PROG_GAME;
section->options = SECTION_OPTIONS_GAME_PLAY_1P;
JA_StopMusic();
break;
case 2: // 2 PLAYER
section->name = SECTION_PROG_GAME;
section->options = SECTION_OPTIONS_GAME_PLAY_2P;
JA_StopMusic();
break;
case 3: // TIME OUT
section->name = SECTION_PROG_GAME_DEMO;
break;
default:
break;
}
else
{
section->name = SECTION_PROG_GAME;
section->options = postFade;
JA_StopMusic();
}
}
@@ -148,7 +138,7 @@ void Title::update()
if (counter == param->title.titleDuration)
{
fade->activate();
postFade = 3;
postFade = -1;
}
}
}
@@ -220,6 +210,28 @@ void Title::checkEvents()
reLoadTextures();
}
else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0)
{
switch (eventHandler->key.keysym.sym)
{
case SDLK_1:
defineButtons->enable(0);
break;
case SDLK_2:
defineButtons->enable(1);
break;
case SDLK_3:
defineButtons->swapControllers();
screen->showNotification("Swap Controllers");
break;
default:
break;
}
}
// Comprueba en el primer mando el botón de salir del programa
// else if (eventHandler->type == SDL_CONTROLLERBUTTONDOWN)
//{
@@ -257,22 +269,10 @@ void Title::checkInput()
if (section->options == SECTION_OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
{
fade->activate();
postFade = 1;
postFade = options->controller[0].playerId;
}
}
// Comprueba si se ha pulsado la tecla 1 o 2 para definir los controladores
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
if (keyStates[SDL_SCANCODE_1] != 0)
{
defineButtons->enable(0);
}
else if (keyStates[SDL_SCANCODE_2] != 0)
{
defineButtons->enable(1);
}
//////////////////////////////////////////////////
// MANDO //
@@ -306,7 +306,7 @@ void Title::checkInput()
if (section->options == SECTION_OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
{
fade->activate();
postFade = i + 1;
postFade = options->controller[i].playerId;
}
}
}