Els panels del marcador ara canvien de mode a petició i no a cada frame
This commit is contained in:
@@ -128,14 +128,14 @@ void Game::init(int playerID)
|
||||
players.clear();
|
||||
|
||||
// Crea los dos jugadores
|
||||
Player *player1 = new Player(1, (param.game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, ¶m.game.playArea.rect, playerTextures[0], playerAnimations);
|
||||
Player *player1 = new Player(1, (param.game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, demo.enabled, ¶m.game.playArea.rect, playerTextures[0], playerAnimations);
|
||||
player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL);
|
||||
player1->setName(lang::getText(53));
|
||||
const int controller1 = getController(player1->getId());
|
||||
player1->setController(controller1);
|
||||
players.push_back(player1);
|
||||
|
||||
Player *player2 = new Player(2, (param.game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, ¶m.game.playArea.rect, playerTextures[1], playerAnimations);
|
||||
Player *player2 = new Player(2, (param.game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, demo.enabled, ¶m.game.playArea.rect, playerTextures[1], playerAnimations);
|
||||
player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL);
|
||||
player2->setName(lang::getText(54));
|
||||
const int controller2 = getController(player2->getId());
|
||||
@@ -1895,7 +1895,7 @@ void Game::update()
|
||||
updatePlayers();
|
||||
|
||||
// Actualiza el marcador
|
||||
checkPlayersStatusPlaying();
|
||||
// checkPlayersStatusPlaying();
|
||||
updateScoreboard();
|
||||
|
||||
// Actualiza el fondo
|
||||
@@ -2691,14 +2691,14 @@ void Game::checkEvents()
|
||||
// Ralentiza mucho la lógica
|
||||
case SDLK_4:
|
||||
{
|
||||
ticksSpeed *= 10;
|
||||
ticksSpeed *= 10;
|
||||
break;
|
||||
}
|
||||
|
||||
// Acelera mucho la lógica
|
||||
case SDLK_5:
|
||||
{
|
||||
ticksSpeed /= 10;
|
||||
ticksSpeed /= 10;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2828,7 +2828,7 @@ void Game::addScoreToScoreBoard(std::string name, int score)
|
||||
}
|
||||
|
||||
// Comprueba el estado de los jugadores
|
||||
void Game::checkPlayersStatusPlaying()
|
||||
/*void Game::checkPlayersStatusPlaying()
|
||||
{
|
||||
if (demo.enabled)
|
||||
{
|
||||
@@ -2840,23 +2840,31 @@ void Game::checkPlayersStatusPlaying()
|
||||
switch (player->getStatusPlaying())
|
||||
{
|
||||
case playerStatus::PLAYING:
|
||||
{
|
||||
scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::SCORE);
|
||||
break;
|
||||
}
|
||||
|
||||
case playerStatus::CONTINUE:
|
||||
{
|
||||
scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::CONTINUE);
|
||||
scoreboard->setContinue(player->getScoreBoardPanel(), player->getContinueCounter());
|
||||
break;
|
||||
}
|
||||
|
||||
case playerStatus::WAITING:
|
||||
{
|
||||
scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::WAITING);
|
||||
break;
|
||||
}
|
||||
|
||||
case playerStatus::ENTERING_NAME:
|
||||
{
|
||||
scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::ENTER_NAME);
|
||||
scoreboard->setRecordName(player->getScoreBoardPanel(), player->getRecordName());
|
||||
scoreboard->setSelectorPos(player->getScoreBoardPanel(), player->getRecordNamePos());
|
||||
break;
|
||||
}
|
||||
|
||||
case playerStatus::DYING:
|
||||
break;
|
||||
@@ -2869,20 +2877,16 @@ void Game::checkPlayersStatusPlaying()
|
||||
}
|
||||
|
||||
case playerStatus::GAME_OVER:
|
||||
{
|
||||
scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::GAME_OVER);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
|
||||
bool Game::IsEligibleForHighScore(int score)
|
||||
{
|
||||
return score > options.game.hiScoreTable.back().score;
|
||||
}
|
||||
}*/
|
||||
|
||||
// Obtiene un jugador a partir de su "id"
|
||||
Player *Game::getPlayer(int id)
|
||||
|
||||
@@ -444,11 +444,8 @@ private:
|
||||
// Añade una puntuación a la tabla de records
|
||||
void addScoreToScoreBoard(std::string name, int score);
|
||||
|
||||
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
|
||||
bool IsEligibleForHighScore(int score);
|
||||
|
||||
// Comprueba el estado de juego de los jugadores
|
||||
void checkPlayersStatusPlaying();
|
||||
//void checkPlayersStatusPlaying();
|
||||
|
||||
// Obtiene un jugador a partir de su "id"
|
||||
Player *getPlayer(int id);
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
#include "input.h" // for inputs_e
|
||||
#include "param.h" // for param
|
||||
#include "texture.h" // for Texture
|
||||
#include "scoreboard.h" // for Texture
|
||||
#include "options.h"
|
||||
|
||||
// Constructor
|
||||
Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
|
||||
Player::Player(int id, float x, int y, bool demo, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
|
||||
{
|
||||
// Reserva memoria para los objetos
|
||||
playerSprite = std::unique_ptr<AnimatedSprite>(new AnimatedSprite(texture[0], "", animations[0]));
|
||||
@@ -30,6 +32,7 @@ Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *
|
||||
|
||||
// Inicializa variables
|
||||
this->id = id;
|
||||
this->demo = demo;
|
||||
statusPlaying = playerStatus::WAITING;
|
||||
scoreBoardPanel = 0;
|
||||
name = "";
|
||||
@@ -337,6 +340,7 @@ void Player::update()
|
||||
updatePowerUpCounter();
|
||||
updateInvulnerable();
|
||||
updateContinueCounter();
|
||||
updateScoreboard();
|
||||
}
|
||||
|
||||
// Obtiene la puntuación del jugador
|
||||
@@ -402,6 +406,39 @@ bool Player::isGameOver() const
|
||||
return statusPlaying == playerStatus::GAME_OVER;
|
||||
}
|
||||
|
||||
// Actualiza el panel del marcador
|
||||
void Player::updateScoreboard()
|
||||
{
|
||||
switch (statusPlaying)
|
||||
{
|
||||
|
||||
case playerStatus::CONTINUE:
|
||||
{
|
||||
Scoreboard::get()->setContinue(getScoreBoardPanel(), getContinueCounter());
|
||||
break;
|
||||
}
|
||||
|
||||
case playerStatus::ENTERING_NAME:
|
||||
{
|
||||
Scoreboard::get()->setRecordName(getScoreBoardPanel(), getRecordName());
|
||||
Scoreboard::get()->setSelectorPos(getScoreBoardPanel(), getRecordNamePos());
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el modo del marcador
|
||||
void Player::setScoreboardMode(scoreboardMode mode)
|
||||
{
|
||||
if (!demo)
|
||||
{
|
||||
Scoreboard::get()->setMode(getScoreBoardPanel(), mode);
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el estado del jugador en el juego
|
||||
void Player::setStatusPlaying(playerStatus value)
|
||||
{
|
||||
@@ -413,6 +450,7 @@ void Player::setStatusPlaying(playerStatus value)
|
||||
{
|
||||
statusPlaying = playerStatus::PLAYING;
|
||||
init();
|
||||
setScoreboardMode(scoreboardMode::SCORE);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -422,14 +460,21 @@ void Player::setStatusPlaying(playerStatus value)
|
||||
continueTicks = SDL_GetTicks();
|
||||
continueCounter = 9;
|
||||
enterName->init();
|
||||
setScoreboardMode(scoreboardMode::CONTINUE);
|
||||
break;
|
||||
}
|
||||
|
||||
case playerStatus::WAITING:
|
||||
{
|
||||
setScoreboardMode(scoreboardMode::WAITING);
|
||||
break;
|
||||
}
|
||||
|
||||
case playerStatus::ENTERING_NAME:
|
||||
{
|
||||
setScoreboardMode(scoreboardMode::ENTER_NAME);
|
||||
break;
|
||||
}
|
||||
|
||||
case playerStatus::DYING:
|
||||
{
|
||||
@@ -441,10 +486,17 @@ void Player::setStatusPlaying(playerStatus value)
|
||||
}
|
||||
|
||||
case playerStatus::DIED:
|
||||
{
|
||||
const auto nextPlayerStatus = IsEligibleForHighScore() ? playerStatus::ENTERING_NAME : playerStatus::CONTINUE;
|
||||
demo ? setStatusPlaying(playerStatus::WAITING) : setStatusPlaying(nextPlayerStatus);
|
||||
break;
|
||||
}
|
||||
|
||||
case playerStatus::GAME_OVER:
|
||||
{
|
||||
setScoreboardMode(scoreboardMode::GAME_OVER);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -733,4 +785,10 @@ int Player::getId() const
|
||||
bool Player::isRenderable() const
|
||||
{
|
||||
return isPlaying() || isDying();
|
||||
}
|
||||
|
||||
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
|
||||
bool Player::IsEligibleForHighScore()
|
||||
{
|
||||
return score > options.game.hiScoreTable.back().score;
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for circle_t
|
||||
#include "enter_name.h"
|
||||
#include "scoreboard.h"
|
||||
#include <memory>
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
@@ -77,6 +78,7 @@ private:
|
||||
std::string name; // Nombre del jugador
|
||||
std::string recordName; // Nombre del jugador para l atabla de mejores puntuaciones
|
||||
int controllerIndex; // Indice del array de mandos que utilizará para moverse
|
||||
bool demo; // Para que el jugador sepa si está en el modo demostración
|
||||
|
||||
// Actualiza el circulo de colisión a la posición del jugador
|
||||
void shiftColliders();
|
||||
@@ -90,9 +92,18 @@ private:
|
||||
// Indica si el jugador se puede dibujar
|
||||
bool isRenderable() const;
|
||||
|
||||
// Actualiza el panel del marcador
|
||||
void updateScoreboard();
|
||||
|
||||
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
|
||||
bool IsEligibleForHighScore();
|
||||
|
||||
// Cambia el modo del marcador
|
||||
void setScoreboardMode(scoreboardMode mode);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations);
|
||||
Player(int id, float x, int y, bool demo, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations);
|
||||
|
||||
// Destructor
|
||||
~Player() = default;
|
||||
|
||||
@@ -306,6 +306,7 @@ void Scoreboard::fillPanelTextures()
|
||||
{
|
||||
// GAME OVER
|
||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(102));
|
||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y + 4, lang::getText(114));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user