acabats els nous estats dels jugadors

This commit is contained in:
2024-08-14 14:09:54 +02:00
parent 5c7bb842ec
commit 7e60a742ca
3 changed files with 61 additions and 24 deletions

View File

@@ -108,10 +108,12 @@ void Game::init(int playerID)
// Crea los dos jugadores // Crea los dos jugadores
Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[0], playerAnimations); Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[0], playerAnimations);
player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL); player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL);
player1->setName(lang->getText(53));
players.push_back(player1); players.push_back(player1);
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[1], playerAnimations); Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[1], playerAnimations);
player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL); player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL);
player2->setName(lang->getText(54));
players.push_back(player2); players.push_back(player2);
// Cambia el estado del jugador seleccionado // Cambia el estado del jugador seleccionado
@@ -150,13 +152,13 @@ void Game::init(int playerID)
// Variables para el marcador // Variables para el marcador
scoreboard->setPos({param->scoreboard.x, param->scoreboard.y, param->scoreboard.w, param->scoreboard.h}); scoreboard->setPos({param->scoreboard.x, param->scoreboard.y, param->scoreboard.w, param->scoreboard.h});
if (players[0]->isWaiting()) for (auto player : players)
{ {
scoreboard->setMode(SCOREBOARD_LEFT_PANEL, SCOREBOARD_MODE_GAME_OVER); scoreboard->setName(player->getScoreBoardPanel(), player->getName());
} if (player->isWaiting())
if (!players[1]->isWaiting()) {
{ scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_GAME_OVER);
scoreboard->setMode(SCOREBOARD_RIGHT_PANEL, SCOREBOARD_MODE_GAME_OVER); }
} }
scoreboard->setMode(SCOREBOARD_CENTER_PANEL, SCOREBOARD_MODE_STAGE_INFO); scoreboard->setMode(SCOREBOARD_CENTER_PANEL, SCOREBOARD_MODE_STAGE_INFO);
@@ -2346,10 +2348,20 @@ void Game::checkInput()
} }
else else
{ {
// Si no está jugando, el botón de start le permite continuar jugando
if (input->checkInput(input_start, ALLOW_REPEAT, options->controller[i].deviceType, options->controller[i].index)) if (input->checkInput(input_start, ALLOW_REPEAT, options->controller[i].deviceType, options->controller[i].index))
{ {
player->setStatusPlaying(PLAYER_STATUS_PLAYING); player->setStatusPlaying(PLAYER_STATUS_PLAYING);
} }
// Si está continuando, los botones de fuego hacen decrementar el contador
const bool fire1 = input->checkInput(input_fire_left, false, options->controller[i].deviceType, options->controller[i].index);
const bool fire2 = input->checkInput(input_fire_center, false, options->controller[i].deviceType, options->controller[i].index);
const bool fire3 = input->checkInput(input_fire_right, false, options->controller[i].deviceType, options->controller[i].index);
if (fire1 || fire2 || fire3)
{
player->decContinueCounter();
}
i++; i++;
} }
} }
@@ -2807,13 +2819,11 @@ void Game::setHiScore()
// Actualiza el marcador // Actualiza el marcador
void Game::updateScoreboard() void Game::updateScoreboard()
{ {
// Jugador 1 for (auto player : players)
scoreboard->setScore1(players[0]->getScore()); {
scoreboard->setMult1(players[0]->getScoreMultiplier()); scoreboard->setScore(player->getScoreBoardPanel(), player->getScore());
scoreboard->setMult(player->getScoreBoardPanel(), player->getScoreMultiplier());
// Jugador 2 }
scoreboard->setScore2(players[1]->getScore());
scoreboard->setMult2(players[1]->getScoreMultiplier());
// Resto de marcador // Resto de marcador
scoreboard->setStage(enemyFormations->getStage(currentStage).number); scoreboard->setStage(enemyFormations->getStage(currentStage).number);
@@ -2854,7 +2864,7 @@ void Game::checkPlayersStatus()
case PLAYER_STATUS_CONTINUE: case PLAYER_STATUS_CONTINUE:
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_CONTINUE); scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_CONTINUE);
scoreboard->setContinue1(player->getContinueCounter()); scoreboard->setContinue(player->getScoreBoardPanel(), player->getContinueCounter());
break; break;
case PLAYER_STATUS_WAITING: case PLAYER_STATUS_WAITING:

View File

@@ -20,6 +20,8 @@ Player::Player(float x, int y, std::vector<Texture *> texture, std::vector<std::
// Inicializa variables // Inicializa variables
// enabled = false; // enabled = false;
statusPlaying = PLAYER_STATUS_WAITING; statusPlaying = PLAYER_STATUS_WAITING;
scoreBoardPanel = 0;
name = "";
init(); init();
} }
@@ -542,16 +544,7 @@ void Player::updateContinueCounter()
if (SDL_GetTicks() - continueTicks > ticksSpeed) if (SDL_GetTicks() - continueTicks > ticksSpeed)
{ {
// Actualiza el contador de ticks decContinueCounter();
continueTicks = SDL_GetTicks();
// Decrementa el contador
continueCounter--;
if (continueCounter < 0)
{
setStatusPlaying(PLAYER_STATUS_WAITING);
}
} }
} }
} }
@@ -566,4 +559,28 @@ void Player::setScoreBoardPanel(int panel)
int Player::getScoreBoardPanel() int Player::getScoreBoardPanel()
{ {
return scoreBoardPanel; return scoreBoardPanel;
}
// Decrementa el contador de continuar
void Player::decContinueCounter()
{
continueTicks = SDL_GetTicks();
continueCounter--;
if (continueCounter < 0)
{
setStatusPlaying(PLAYER_STATUS_WAITING);
}
}
// Establece el nombre del jugador
void Player::setName(std::string name)
{
this->name = name;
}
// Obtiene el nombre del jugador
std::string Player::getName()
{
return name;
} }

View File

@@ -68,6 +68,7 @@ private:
int continueCounter; // Contador para poder continuar int continueCounter; // Contador para poder continuar
Uint32 continueTicks; // Variable para poder cambiar el contador de continue en función del tiempo Uint32 continueTicks; // Variable para poder cambiar el contador de continue en función del tiempo
int scoreBoardPanel; // Panel del marcador asociado al jugador int scoreBoardPanel; // Panel del marcador asociado al jugador
std::string name; // Nombre del jugador
// Actualiza el circulo de colisión a la posición del jugador // Actualiza el circulo de colisión a la posición del jugador
void shiftColliders(); void shiftColliders();
@@ -225,4 +226,13 @@ public:
// Obtiene el valor de la variable // Obtiene el valor de la variable
int getScoreBoardPanel(); int getScoreBoardPanel();
// Decrementa el contador de continuar
void decContinueCounter();
// Establece el nombre del jugador
void setName(std::string name);
// Obtiene el nombre del jugador
std::string getName();
}; };