diff --git a/source/game.cpp b/source/game.cpp index 08c10a6..76505e5 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -108,10 +108,12 @@ void Game::init(int playerID) // 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); player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL); + player1->setName(lang->getText(53)); 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); player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL); + player2->setName(lang->getText(54)); players.push_back(player2); // Cambia el estado del jugador seleccionado @@ -150,13 +152,13 @@ void Game::init(int playerID) // Variables para el marcador 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); - } - if (!players[1]->isWaiting()) - { - scoreboard->setMode(SCOREBOARD_RIGHT_PANEL, SCOREBOARD_MODE_GAME_OVER); + scoreboard->setName(player->getScoreBoardPanel(), player->getName()); + if (player->isWaiting()) + { + scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_GAME_OVER); + } } scoreboard->setMode(SCOREBOARD_CENTER_PANEL, SCOREBOARD_MODE_STAGE_INFO); @@ -2346,10 +2348,20 @@ void Game::checkInput() } 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)) { 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++; } } @@ -2807,13 +2819,11 @@ void Game::setHiScore() // Actualiza el marcador void Game::updateScoreboard() { - // Jugador 1 - scoreboard->setScore1(players[0]->getScore()); - scoreboard->setMult1(players[0]->getScoreMultiplier()); - - // Jugador 2 - scoreboard->setScore2(players[1]->getScore()); - scoreboard->setMult2(players[1]->getScoreMultiplier()); + for (auto player : players) + { + scoreboard->setScore(player->getScoreBoardPanel(), player->getScore()); + scoreboard->setMult(player->getScoreBoardPanel(), player->getScoreMultiplier()); + } // Resto de marcador scoreboard->setStage(enemyFormations->getStage(currentStage).number); @@ -2854,7 +2864,7 @@ void Game::checkPlayersStatus() case PLAYER_STATUS_CONTINUE: scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_CONTINUE); - scoreboard->setContinue1(player->getContinueCounter()); + scoreboard->setContinue(player->getScoreBoardPanel(), player->getContinueCounter()); break; case PLAYER_STATUS_WAITING: diff --git a/source/player.cpp b/source/player.cpp index 49d2854..64bb57e 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -20,6 +20,8 @@ Player::Player(float x, int y, std::vector texture, std::vector ticksSpeed) { - // Actualiza el contador de ticks - continueTicks = SDL_GetTicks(); - - // Decrementa el contador - continueCounter--; - - if (continueCounter < 0) - { - setStatusPlaying(PLAYER_STATUS_WAITING); - } + decContinueCounter(); } } } @@ -566,4 +559,28 @@ void Player::setScoreBoardPanel(int panel) int Player::getScoreBoardPanel() { 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; } \ No newline at end of file diff --git a/source/player.h b/source/player.h index d04a209..2d743ce 100644 --- a/source/player.h +++ b/source/player.h @@ -68,6 +68,7 @@ private: int continueCounter; // Contador para poder continuar Uint32 continueTicks; // Variable para poder cambiar el contador de continue en función del tiempo 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 void shiftColliders(); @@ -225,4 +226,13 @@ public: // Obtiene el valor de la variable 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(); };