Canviats defines per constexpr i enum class

Canviats punters a unique_ptr
Afegit const a alguns metodes de classse
fix: el segon jugador no podia unirse a la partida
new: Quan els dos jugadors han decidit no continuar, ja no poden continuar i el marcador així ho reflectix
fix: al posar el nom per segona vegada en la mateixa partida, no es reseteja la posició del selector
fix: el fade venetian no netejava la textura i de vegades eixien gràfics corruptes
fix: ara grava a disco cada vegada que es posa nom al morir
This commit is contained in:
2024-10-05 23:53:42 +02:00
parent ee721ff573
commit 25a2753b13
10 changed files with 322 additions and 238 deletions

View File

@@ -3,12 +3,17 @@
// Constructor // Constructor
EnterName::EnterName() EnterName::EnterName()
{
init();
}
// Inicializa el objeto
void EnterName::init()
{ {
// Obtiene el puntero al nombre // Obtiene el puntero al nombre
name = "A"; name = "A";
// Inicia la lista de caracteres permitidos // Inicia la lista de caracteres permitidos
// characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()"; characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()";
pos = 0; pos = 0;
numCharacters = (int)characterList.size(); numCharacters = (int)characterList.size();
@@ -20,11 +25,6 @@ EnterName::EnterName()
updateName(); updateName();
} }
// Destructor
EnterName::~EnterName()
{
}
// Incrementa la posición // Incrementa la posición
void EnterName::incPos() void EnterName::incPos()
{ {
@@ -101,13 +101,13 @@ int EnterName::findIndex(char character)
} }
// Obtiene el nombre // Obtiene el nombre
std::string EnterName::getName() std::string EnterName::getName() const
{ {
return name; return name;
} }
// Obtiene la posición que se está editando // Obtiene la posición que se está editando
int EnterName::getPos() int EnterName::getPos() const
{ {
return pos; return pos;
} }

View File

@@ -36,7 +36,10 @@ public:
EnterName(); EnterName();
// Destructor // Destructor
~EnterName(); ~EnterName() = default;
// Inicializa el objeto
void init();
// Incrementa la posición // Incrementa la posición
void incPos(); void incPos();
@@ -51,8 +54,8 @@ public:
void decIndex(); void decIndex();
// Obtiene el nombre // Obtiene el nombre
std::string getName(); std::string getName() const;
// Obtiene la posición que se está editando // Obtiene la posición que se está editando
int getPos(); int getPos() const;
}; };

View File

@@ -270,6 +270,7 @@ void Fade::activate()
case FADE_VENETIAN: case FADE_VENETIAN:
{ {
cleanBackbuffer(0, 0, 0, 0);
rect1 = {0, 0, param.game.width, 0}; rect1 = {0, 0, param.game.width, 0};
square.clear(); square.clear();
a = 255; a = 255;

View File

@@ -24,7 +24,7 @@
#include "manage_hiscore_table.h" // for ManageHiScoreTable #include "manage_hiscore_table.h" // for ManageHiScoreTable
#include "options.h" // for options #include "options.h" // for options
#include "param.h" // for param #include "param.h" // for param
#include "player.h" // for Player, PLAYER_STATUS_PLAYING, PLA... #include "player.h" // for Player, playerStatus::PLAYING, PLA...
#include "scoreboard.h" // for Scoreboard, scoreboard_modes_e #include "scoreboard.h" // for Scoreboard, scoreboard_modes_e
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "smart_sprite.h" // for SmartSprite #include "smart_sprite.h" // for SmartSprite
@@ -155,7 +155,7 @@ void Game::init(int playerID)
Player *player = getPlayer(playerID); Player *player = getPlayer(playerID);
// Cambia el estado del jugador seleccionado // Cambia el estado del jugador seleccionado
player->setStatusPlaying(PLAYER_STATUS_PLAYING); player->setStatusPlaying(playerStatus::PLAYING);
// Como es el principio del juego, empieza sin inmunidad // Como es el principio del juego, empieza sin inmunidad
player->setInvulnerable(false); player->setInvulnerable(false);
@@ -164,25 +164,31 @@ void Game::init(int playerID)
switch (difficulty) switch (difficulty)
{ {
case DIFFICULTY_EASY: case DIFFICULTY_EASY:
{
defaultEnemySpeed = BALLOON_SPEED_1; defaultEnemySpeed = BALLOON_SPEED_1;
difficultyScoreMultiplier = 0.5f; difficultyScoreMultiplier = 0.5f;
difficultyColor = difficultyEasyColor; difficultyColor = difficultyEasyColor;
scoreboard->setColor(difficultyColor); scoreboard->setColor(difficultyColor);
break; break;
}
case DIFFICULTY_NORMAL: case DIFFICULTY_NORMAL:
{
defaultEnemySpeed = BALLOON_SPEED_1; defaultEnemySpeed = BALLOON_SPEED_1;
difficultyScoreMultiplier = 1.0f; difficultyScoreMultiplier = 1.0f;
difficultyColor = difficultyNormalColor; difficultyColor = difficultyNormalColor;
scoreboard->setColor(scoreboardColor); scoreboard->setColor(scoreboardColor);
break; break;
}
case DIFFICULTY_HARD: case DIFFICULTY_HARD:
{
defaultEnemySpeed = BALLOON_SPEED_5; defaultEnemySpeed = BALLOON_SPEED_5;
difficultyScoreMultiplier = 1.5f; difficultyScoreMultiplier = 1.5f;
difficultyColor = difficultyHardColor; difficultyColor = difficultyHardColor;
scoreboard->setColor(difficultyColor); scoreboard->setColor(difficultyColor);
break; break;
}
default: default:
break; break;
@@ -195,10 +201,10 @@ void Game::init(int playerID)
scoreboard->setName(player->getScoreBoardPanel(), player->getName()); scoreboard->setName(player->getScoreBoardPanel(), player->getName());
if (player->isWaiting()) if (player->isWaiting())
{ {
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_GAME_OVER); scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::WAITING);
} }
} }
scoreboard->setMode(SCOREBOARD_CENTER_PANEL, SCOREBOARD_MODE_STAGE_INFO); scoreboard->setMode(SCOREBOARD_CENTER_PANEL, scoreboardMode::STAGE_INFO);
// Resto de variables // Resto de variables
hiScore.score = options.game.hiScoreTable[0].score; hiScore.score = options.game.hiScoreTable[0].score;
@@ -258,7 +264,7 @@ void Game::init(int playerID)
{ {
const int otherPlayer = playerID == 1 ? 2 : 1; const int otherPlayer = playerID == 1 ? 2 : 1;
Player *player = getPlayer(otherPlayer); Player *player = getPlayer(otherPlayer);
player->setStatusPlaying(PLAYER_STATUS_PLAYING); player->setStatusPlaying(playerStatus::PLAYING);
} }
for (auto player : players) for (auto player : players)
@@ -277,8 +283,8 @@ void Game::init(int playerID)
JA_EnableSound(false); JA_EnableSound(false);
// Configura los marcadores // Configura los marcadores
scoreboard->setMode(SCOREBOARD_LEFT_PANEL, SCOREBOARD_MODE_DEMO); scoreboard->setMode(SCOREBOARD_LEFT_PANEL, scoreboardMode::DEMO);
scoreboard->setMode(SCOREBOARD_RIGHT_PANEL, SCOREBOARD_MODE_DEMO); scoreboard->setMode(SCOREBOARD_RIGHT_PANEL, scoreboardMode::DEMO);
} }
initPaths(); initPaths();
@@ -859,12 +865,13 @@ void Game::updatePlayers()
player->update(); player->update();
if (player->isPlaying()) if (player->isPlaying())
{ // Comprueba la colisión entre el jugador y los globos {
// Comprueba la colisión entre el jugador y los globos
if (checkPlayerBalloonCollision(player)) if (checkPlayerBalloonCollision(player))
{ {
killPlayer(player); killPlayer(player);
if (demo.enabled && allPlayersAreWaiting()) if (demo.enabled && allPlayersAreNotPlaying())
{ {
fade->setType(FADE_RANDOM_SQUARE); fade->setType(FADE_RANDOM_SQUARE);
fade->activate(); fade->activate();
@@ -947,8 +954,18 @@ void Game::updateStage()
// Actualiza el estado de fin de la partida // Actualiza el estado de fin de la partida
void Game::updateGameOver() void Game::updateGameOver()
{ {
// Comprueba si todos los jugadores estan muertos // Comprueba si todos los jugadores estan esperando
if (allPlayersAreWaiting()) if (allPlayersAreWaiting())
{
// Entonces los pone en estado de Game Over
for (auto player : players)
{
player->setStatusPlaying(playerStatus::GAME_OVER);
}
}
// Si todos estan en estado de Game Over
if (allPlayersAreGameOver())
{ {
if (gameOverCounter > 0) if (gameOverCounter > 0)
{ {
@@ -1745,7 +1762,7 @@ void Game::killPlayer(Player *player)
JA_PlaySound(playerCollisionSound); JA_PlaySound(playerCollisionSound);
screen->shake(); screen->shake();
JA_PlaySound(coffeeOutSound); JA_PlaySound(coffeeOutSound);
player->setStatusPlaying(PLAYER_STATUS_DYING); player->setStatusPlaying(playerStatus::DYING);
if (!demo.enabled) if (!demo.enabled)
{ // En el modo DEMO ni se para la musica ni se añade la puntuación a la tabla { // En el modo DEMO ni se para la musica ni se añade la puntuación a la tabla
allPlayersAreNotPlaying() ? JA_StopMusic() : JA_ResumeMusic(); allPlayersAreNotPlaying() ? JA_StopMusic() : JA_ResumeMusic();
@@ -2237,16 +2254,12 @@ void Game::checkInput()
} }
#endif #endif
} }
else if (player->isContinue()) else if (player->isContinue() || player->isWaiting())
{ {
// Si no está jugando, el botón de start le permite continuar jugando // Si no está jugando, el botón de start le permite continuar jugando
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index)) if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
{ {
// Si no ha entrado ya en el estado de game over, entonces se puede continuar player->setStatusPlaying(playerStatus::PLAYING);
if (gameOverCounter == GAME_OVER_COUNTER)
{
player->setStatusPlaying(PLAYER_STATUS_PLAYING);
}
} }
// Si está continuando, los botones de fuego hacen decrementar el contador // Si está continuando, los botones de fuego hacen decrementar el contador
@@ -2269,7 +2282,7 @@ void Game::checkInput()
{ {
player->setInput(input_start); player->setInput(input_start);
addScoreToScoreBoard(player->getRecordName(), player->getScore()); addScoreToScoreBoard(player->getRecordName(), player->getScore());
player->setStatusPlaying(PLAYER_STATUS_CONTINUE); player->setStatusPlaying(playerStatus::CONTINUE);
} }
else else
{ {
@@ -2296,7 +2309,7 @@ void Game::checkInput()
{ {
player->setInput(input_start); player->setInput(input_start);
addScoreToScoreBoard(player->getRecordName(), player->getScore()); addScoreToScoreBoard(player->getRecordName(), player->getScore());
player->setStatusPlaying(PLAYER_STATUS_CONTINUE); player->setStatusPlaying(playerStatus::CONTINUE);
} }
} }
} }
@@ -2403,7 +2416,7 @@ void Game::checkMusicStatus()
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{ {
// Si se ha completado el juego o los jugadores han terminado, detiene la música // Si se ha completado el juego o los jugadores han terminado, detiene la música
gameCompleted || allPlayersAreWaiting() ? JA_StopMusic() : JA_PlayMusic(music); gameCompleted || allPlayersAreGameOver() ? JA_StopMusic() : JA_PlayMusic(music);
} }
} }
@@ -2589,6 +2602,18 @@ bool Game::allPlayersAreWaiting()
return success; return success;
} }
// Comprueba si todos los jugadores han terminado de jugar
bool Game::allPlayersAreGameOver()
{
bool success = true;
for (auto player : players)
{
success &= player->isGameOver();
}
return success;
}
// Comprueba si todos los jugadores han terminado de jugar // Comprueba si todos los jugadores han terminado de jugar
bool Game::allPlayersAreNotPlaying() bool Game::allPlayersAreNotPlaying()
{ {
@@ -2793,6 +2818,7 @@ void Game::addScoreToScoreBoard(std::string name, int score)
const hiScoreEntry_t entry = {trim(name), score}; const hiScoreEntry_t entry = {trim(name), score};
ManageHiScoreTable *manager = new ManageHiScoreTable(&options.game.hiScoreTable); ManageHiScoreTable *manager = new ManageHiScoreTable(&options.game.hiScoreTable);
manager->add(entry); manager->add(entry);
manager->saveToFile(asset->get("score.bin"));
delete manager; delete manager;
} }
@@ -2808,36 +2834,40 @@ void Game::checkPlayersStatusPlaying()
{ {
switch (player->getStatusPlaying()) switch (player->getStatusPlaying())
{ {
case PLAYER_STATUS_PLAYING: case playerStatus::PLAYING:
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_SCORE); scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::SCORE);
break; break;
case PLAYER_STATUS_CONTINUE: case playerStatus::CONTINUE:
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_CONTINUE); scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::CONTINUE);
scoreboard->setContinue(player->getScoreBoardPanel(), player->getContinueCounter()); scoreboard->setContinue(player->getScoreBoardPanel(), player->getContinueCounter());
break; break;
case PLAYER_STATUS_WAITING: case playerStatus::WAITING:
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_GAME_OVER); scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::WAITING);
break; break;
case PLAYER_STATUS_ENTERING_NAME: case playerStatus::ENTERING_NAME:
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_ENTER_NAME); scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::ENTER_NAME);
scoreboard->setRecordName(player->getScoreBoardPanel(), player->getRecordName()); scoreboard->setRecordName(player->getScoreBoardPanel(), player->getRecordName());
scoreboard->setSelectorPos(player->getScoreBoardPanel(), player->getRecordNamePos()); scoreboard->setSelectorPos(player->getScoreBoardPanel(), player->getRecordNamePos());
break; break;
case PLAYER_STATUS_DYING: case playerStatus::DYING:
break; break;
case PLAYER_STATUS_DIED: case playerStatus::DIED:
{ {
const int nextPlayerStatus = IsEligibleForHighScore(player->getScore()) ? PLAYER_STATUS_ENTERING_NAME : PLAYER_STATUS_CONTINUE; const playerStatus nextPlayerStatus = IsEligibleForHighScore(player->getScore()) ? playerStatus::ENTERING_NAME : playerStatus::CONTINUE;
demo.enabled ? player->setStatusPlaying(PLAYER_STATUS_WAITING) : player->setStatusPlaying(nextPlayerStatus); demo.enabled ? player->setStatusPlaying(playerStatus::WAITING) : player->setStatusPlaying(nextPlayerStatus);
// addScoreToScoreBoard(player->getName(), player->getScore()); // addScoreToScoreBoard(player->getName(), player->getScore());
break; break;
} }
case playerStatus::GAME_OVER:
scoreboard->setMode(player->getScoreBoardPanel(), scoreboardMode::GAME_OVER);
break;
default: default:
break; break;
} }

View File

@@ -411,6 +411,9 @@ private:
// Comprueba si todos los jugadores han terminado de jugar // Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreWaiting(); bool allPlayersAreWaiting();
// Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreGameOver();
// Comprueba si todos los jugadores han terminado de jugar // Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreNotPlaying(); bool allPlayersAreNotPlaying();

View File

@@ -4,7 +4,6 @@
#include <stdlib.h> // for rand #include <stdlib.h> // for rand
#include <algorithm> // for max, min #include <algorithm> // for max, min
#include "animated_sprite.h" // for AnimatedSprite #include "animated_sprite.h" // for AnimatedSprite
#include "enter_name.h"
#include "input.h" // for inputs_e #include "input.h" // for inputs_e
#include "param.h" // for param #include "param.h" // for param
#include "texture.h" // for Texture #include "texture.h" // for Texture
@@ -13,10 +12,10 @@
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, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
{ {
// Reserva memoria para los objetos // Reserva memoria para los objetos
playerSprite = new AnimatedSprite(texture[0], "", animations[0]); playerSprite = std::unique_ptr<AnimatedSprite>(new AnimatedSprite(texture[0], "", animations[0]));
powerSprite = new AnimatedSprite(texture[1], "", animations[1]); powerSprite = std::unique_ptr<AnimatedSprite>(new AnimatedSprite(texture[1], "", animations[1]));
powerSprite->getTexture()->setAlpha(224); powerSprite->getTexture()->setAlpha(224);
enterName = new EnterName(); enterName = std::unique_ptr<EnterName>(new EnterName());
// Rectangulo con la zona de juego // Rectangulo con la zona de juego
this->playArea = playArea; this->playArea = playArea;
@@ -31,32 +30,21 @@ Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *
// Inicializa variables // Inicializa variables
this->id = id; this->id = id;
statusPlaying = PLAYER_STATUS_WAITING; statusPlaying = playerStatus::WAITING;
scoreBoardPanel = 0; scoreBoardPanel = 0;
name = ""; name = "";
setRecordName(enterName->getName()); setRecordName(enterName->getName());
init(); init();
} }
// Destructor
Player::~Player()
{
delete playerSprite;
delete powerSprite;
if (enterName)
{
delete enterName;
}
}
// Iniciador // Iniciador
void Player::init() void Player::init()
{ {
// Inicializa variables de estado // Inicializa variables de estado
posX = defaultPosX; posX = defaultPosX;
posY = defaultPosY; posY = defaultPosY;
statusWalking = PLAYER_STATUS_WALKING_STOP; statusWalking = playerStatus::WALKING_STOP;
statusFiring = PLAYER_STATUS_FIRING_NO; statusFiring = playerStatus::FIRING_NO;
invulnerable = true; invulnerable = true;
invulnerableCounter = PLAYER_INVULNERABLE_COUNTER; invulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
powerUp = false; powerUp = false;
@@ -90,13 +78,16 @@ void Player::setInput(int input)
{ {
switch (statusPlaying) switch (statusPlaying)
{ {
case PLAYER_STATUS_PLAYING: case playerStatus::PLAYING:
setInputPlaying(input); setInputPlaying(input);
break; break;
case PLAYER_STATUS_ENTERING_NAME: case playerStatus::ENTERING_NAME:
setInputEnteringName(input); setInputEnteringName(input);
break; break;
default:
break;
} }
} }
@@ -107,29 +98,29 @@ void Player::setInputPlaying(int input)
{ {
case input_left: case input_left:
velX = -baseSpeed; velX = -baseSpeed;
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT); setWalkingStatus(playerStatus::WALKING_LEFT);
break; break;
case input_right: case input_right:
velX = baseSpeed; velX = baseSpeed;
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT); setWalkingStatus(playerStatus::WALKING_RIGHT);
break; break;
case input_fire_center: case input_fire_center:
setFiringStatus(PLAYER_STATUS_FIRING_UP); setFiringStatus(playerStatus::FIRING_UP);
break; break;
case input_fire_left: case input_fire_left:
setFiringStatus(PLAYER_STATUS_FIRING_LEFT); setFiringStatus(playerStatus::FIRING_LEFT);
break; break;
case input_fire_right: case input_fire_right:
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT); setFiringStatus(playerStatus::FIRING_RIGHT);
break; break;
default: default:
velX = 0; velX = 0;
setWalkingStatus(PLAYER_STATUS_WALKING_STOP); setWalkingStatus(playerStatus::WALKING_STOP);
break; break;
} }
} }
@@ -156,7 +147,7 @@ void Player::setInputEnteringName(int input)
break; break;
case input_start: case input_start:
recordName = enterName->getName(); setRecordName(enterName->getName());
break; break;
default: default:
@@ -204,7 +195,7 @@ void Player::move()
// Si el cadaver abandona el area de juego por abajo // Si el cadaver abandona el area de juego por abajo
if (playerSprite->getPosY() > param.game.playArea.rect.h) if (playerSprite->getPosY() > param.game.playArea.rect.h)
{ {
setStatusPlaying(PLAYER_STATUS_DIED); setStatusPlaying(playerStatus::DIED);
} }
} }
} }
@@ -220,11 +211,12 @@ void Player::render()
} }
} }
if (isRenderable())
playerSprite->render(); playerSprite->render();
} }
// Establece el estado del jugador cuando camina // Establece el estado del jugador cuando camina
void Player::setWalkingStatus(int status) void Player::setWalkingStatus(playerStatus status)
{ {
// Si cambiamos de estado, reiniciamos la animación // Si cambiamos de estado, reiniciamos la animación
if (statusWalking != status) if (statusWalking != status)
@@ -234,7 +226,7 @@ void Player::setWalkingStatus(int status)
} }
// Establece el estado del jugador cuando dispara // Establece el estado del jugador cuando dispara
void Player::setFiringStatus(int status) void Player::setFiringStatus(playerStatus status)
{ {
// Si cambiamos de estado, reiniciamos la animación // Si cambiamos de estado, reiniciamos la animación
if (statusFiring != status) if (statusFiring != status)
@@ -247,16 +239,16 @@ void Player::setFiringStatus(int status)
void Player::setAnimation() void Player::setAnimation()
{ {
// Crea cadenas de texto para componer el nombre de la animación // Crea cadenas de texto para componer el nombre de la animación
const std::string aWalking = statusWalking == PLAYER_STATUS_WALKING_STOP ? "stand" : "walk"; const std::string aWalking = statusWalking == playerStatus::WALKING_STOP ? "stand" : "walk";
const std::string aFiring = statusFiring == PLAYER_STATUS_FIRING_UP ? "centershoot" : "sideshoot"; const std::string aFiring = statusFiring == playerStatus::FIRING_UP ? "centershoot" : "sideshoot";
const SDL_RendererFlip flipWalk = statusWalking == PLAYER_STATUS_WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE; const SDL_RendererFlip flipWalk = statusWalking == playerStatus::WALKING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
const SDL_RendererFlip flipFire = statusFiring == PLAYER_STATUS_FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE; const SDL_RendererFlip flipFire = statusFiring == playerStatus::FIRING_RIGHT ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
// Establece la animación a partir de las cadenas // Establece la animación a partir de las cadenas
if (isPlaying()) if (isPlaying())
{ {
if (statusFiring == PLAYER_STATUS_FIRING_NO) if (statusFiring == playerStatus::FIRING_NO)
{ // No esta disparando { // No esta disparando
playerSprite->setCurrentAnimation(aWalking); playerSprite->setCurrentAnimation(aWalking);
playerSprite->setFlip(flipWalk); playerSprite->setFlip(flipWalk);
@@ -282,31 +274,31 @@ void Player::setAnimation()
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
int Player::getPosX() int Player::getPosX() const
{ {
return int(posX); return int(posX);
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
int Player::getPosY() int Player::getPosY() const
{ {
return posY; return posY;
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
int Player::getWidth() int Player::getWidth() const
{ {
return width; return width;
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
int Player::getHeight() int Player::getHeight() const
{ {
return height; return height;
} }
// Indica si el jugador puede disparar // Indica si el jugador puede disparar
bool Player::canFire() bool Player::canFire() const
{ {
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador // Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
return cooldown > 0 ? false : true; return cooldown > 0 ? false : true;
@@ -331,7 +323,7 @@ void Player::updateCooldown()
} }
else else
{ {
setFiringStatus(PLAYER_STATUS_FIRING_NO); setFiringStatus(playerStatus::FIRING_NO);
} }
} }
@@ -348,7 +340,7 @@ void Player::update()
} }
// Obtiene la puntuación del jugador // Obtiene la puntuación del jugador
int Player::getScore() int Player::getScore() const
{ {
return score; return score;
} }
@@ -369,73 +361,89 @@ void Player::addScore(int score)
} }
// Indica si el jugador está jugando // Indica si el jugador está jugando
bool Player::isPlaying() bool Player::isPlaying() const
{ {
return statusPlaying == PLAYER_STATUS_PLAYING; return statusPlaying == playerStatus::PLAYING;
} }
// Indica si el jugador está continuando // Indica si el jugador está continuando
bool Player::isContinue() bool Player::isContinue() const
{ {
return statusPlaying == PLAYER_STATUS_CONTINUE; return statusPlaying == playerStatus::CONTINUE;
} }
// Indica si el jugador está esperando // Indica si el jugador está esperando
bool Player::isWaiting() bool Player::isWaiting() const
{ {
return statusPlaying == PLAYER_STATUS_WAITING; return statusPlaying == playerStatus::WAITING;
} }
// Indica si el jugador está introduciendo su nombre // Indica si el jugador está introduciendo su nombre
bool Player::isEnteringName() bool Player::isEnteringName() const
{ {
return statusPlaying == PLAYER_STATUS_ENTERING_NAME; return statusPlaying == playerStatus::ENTERING_NAME;
} }
// Indica si el jugador está muriendose // Indica si el jugador está muriendose
bool Player::isDying() bool Player::isDying() const
{ {
return statusPlaying == PLAYER_STATUS_DYING; return statusPlaying == playerStatus::DYING;
} }
// Indica si el jugador ha terminado de morir // Indica si el jugador ha terminado de morir
bool Player::hasDied() bool Player::hasDied() const
{ {
return statusPlaying == PLAYER_STATUS_DIED; return statusPlaying == playerStatus::DIED;
}
// Indica si el jugador ya ha terminado de jugar
bool Player::isGameOver() const
{
return statusPlaying == playerStatus::GAME_OVER;
} }
// Establece el estado del jugador en el juego // Establece el estado del jugador en el juego
void Player::setStatusPlaying(int value) void Player::setStatusPlaying(playerStatus value)
{ {
statusPlaying = value; statusPlaying = value;
switch (statusPlaying) switch (statusPlaying)
{ {
case PLAYER_STATUS_PLAYING: case playerStatus::PLAYING:
statusPlaying = PLAYER_STATUS_PLAYING; {
statusPlaying = playerStatus::PLAYING;
init(); init();
break; break;
}
case PLAYER_STATUS_CONTINUE: case playerStatus::CONTINUE:
{
// Inicializa el contador de continuar // Inicializa el contador de continuar
continueTicks = SDL_GetTicks(); continueTicks = SDL_GetTicks();
continueCounter = 9; continueCounter = 9;
enterName->init();
break;
}
case playerStatus::WAITING:
break; break;
case PLAYER_STATUS_WAITING: case playerStatus::ENTERING_NAME:
break; break;
case PLAYER_STATUS_ENTERING_NAME: case playerStatus::DYING:
break; {
case PLAYER_STATUS_DYING:
// Activa la animación de morir // Activa la animación de morir
playerSprite->setAccelY(0.2f); playerSprite->setAccelY(0.2f);
playerSprite->setVelY(-6.6f); playerSprite->setVelY(-6.6f);
rand() % 2 == 0 ? playerSprite->setVelX(3.3f) : playerSprite->setVelX(-3.3f); rand() % 2 == 0 ? playerSprite->setVelX(3.3f) : playerSprite->setVelX(-3.3f);
break; break;
}
case PLAYER_STATUS_DIED: case playerStatus::DIED:
break;
case playerStatus::GAME_OVER:
break; break;
default: default:
@@ -444,13 +452,13 @@ void Player::setStatusPlaying(int value)
} }
// Obtiene el estado del jugador en el juego // Obtiene el estado del jugador en el juego
int Player::getStatusPlaying() playerStatus Player::getStatusPlaying() const
{ {
return statusPlaying; return statusPlaying;
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
float Player::getScoreMultiplier() float Player::getScoreMultiplier() const
{ {
return scoreMultiplier; return scoreMultiplier;
} }
@@ -476,7 +484,7 @@ void Player::decScoreMultiplier()
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
bool Player::isInvulnerable() bool Player::isInvulnerable() const
{ {
return invulnerable; return invulnerable;
} }
@@ -489,7 +497,7 @@ void Player::setInvulnerable(bool value)
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
int Player::getInvulnerableCounter() int Player::getInvulnerableCounter() const
{ {
return invulnerableCounter; return invulnerableCounter;
} }
@@ -519,7 +527,7 @@ void Player::updateInvulnerable()
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
bool Player::isPowerUp() bool Player::isPowerUp() const
{ {
return powerUp; return powerUp;
} }
@@ -532,7 +540,7 @@ void Player::setPowerUp()
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
int Player::getPowerUpCounter() int Player::getPowerUpCounter() const
{ {
return powerUpCounter; return powerUpCounter;
} }
@@ -558,7 +566,7 @@ void Player::updatePowerUpCounter()
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
bool Player::hasExtraHit() bool Player::hasExtraHit() const
{ {
return extraHit; return extraHit;
} }
@@ -600,7 +608,7 @@ void Player::disableInput()
} }
// Devuelve el número de cafes actuales // Devuelve el número de cafes actuales
int Player::getCoffees() int Player::getCoffees() const
{ {
return coffees; return coffees;
} }
@@ -626,7 +634,7 @@ void Player::setPlayerTextures(std::vector<Texture *> texture)
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
int Player::getContinueCounter() int Player::getContinueCounter() const
{ {
return continueCounter; return continueCounter;
} }
@@ -634,7 +642,7 @@ int Player::getContinueCounter()
// Actualiza el contador de continue // Actualiza el contador de continue
void Player::updateContinueCounter() void Player::updateContinueCounter()
{ {
if (statusPlaying == PLAYER_STATUS_CONTINUE) if (statusPlaying == playerStatus::CONTINUE)
{ {
const Uint32 ticksSpeed = 1000; const Uint32 ticksSpeed = 1000;
@@ -652,7 +660,7 @@ void Player::setScoreBoardPanel(int panel)
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
int Player::getScoreBoardPanel() int Player::getScoreBoardPanel() const
{ {
return scoreBoardPanel; return scoreBoardPanel;
} }
@@ -664,7 +672,7 @@ void Player::decContinueCounter()
continueCounter--; continueCounter--;
if (continueCounter < 0) if (continueCounter < 0)
{ {
setStatusPlaying(PLAYER_STATUS_WAITING); setStatusPlaying(playerStatus::WAITING);
} }
} }
@@ -681,19 +689,19 @@ void Player::setRecordName(std::string recordName)
} }
// Obtiene el nombre del jugador // Obtiene el nombre del jugador
std::string Player::getName() std::string Player::getName() const
{ {
return name; return name;
} }
// Obtiene el nombre del jugador para la tabla de mejores puntuaciones // Obtiene el nombre del jugador para la tabla de mejores puntuaciones
std::string Player::getRecordName() std::string Player::getRecordName() const
{ {
return recordName; return recordName;
} }
// Obtiene la posici´´on que se está editando del nombre del jugador para la tabla de mejores puntuaciones // Obtiene la posici´´on que se está editando del nombre del jugador para la tabla de mejores puntuaciones
int Player::getRecordNamePos() int Player::getRecordNamePos() const
{ {
if (enterName) if (enterName)
{ {
@@ -710,13 +718,19 @@ void Player::setController(int index)
} }
// Obtiene el mando que usa para ser controlado // Obtiene el mando que usa para ser controlado
int Player::getController() int Player::getController() const
{ {
return controllerIndex; return controllerIndex;
} }
// Obtiene el "id" del jugador // Obtiene el "id" del jugador
int Player::getId() int Player::getId() const
{ {
return id; return id;
} }
// Indica si el jugador se puede dibujar
bool Player::isRenderable() const
{
return isPlaying() || isDying();
}

View File

@@ -5,40 +5,45 @@
#include <string> // for string, basic_string #include <string> // for string, basic_string
#include <vector> // for vector #include <vector> // for vector
#include "utils.h" // for circle_t #include "utils.h" // for circle_t
#include "enter_name.h"
#include <memory>
class AnimatedSprite; class AnimatedSprite;
class EnterName;
class Texture; class Texture;
// Estados del jugador // Estados del jugador
#define PLAYER_STATUS_WALKING_LEFT 0 enum class playerStatus
#define PLAYER_STATUS_WALKING_RIGHT 1 {
#define PLAYER_STATUS_WALKING_STOP 2 WALKING_LEFT,
WALKING_RIGHT,
WALKING_STOP,
#define PLAYER_STATUS_FIRING_UP 0 FIRING_UP,
#define PLAYER_STATUS_FIRING_LEFT 1 FIRING_LEFT,
#define PLAYER_STATUS_FIRING_RIGHT 2 FIRING_RIGHT,
#define PLAYER_STATUS_FIRING_NO 3 FIRING_NO,
#define PLAYER_STATUS_PLAYING 0 PLAYING,
#define PLAYER_STATUS_CONTINUE 1 CONTINUE,
#define PLAYER_STATUS_WAITING 2 WAITING,
#define PLAYER_STATUS_ENTERING_NAME 3 ENTERING_NAME,
#define PLAYER_STATUS_DYING 4 DYING,
#define PLAYER_STATUS_DIED 5 DIED,
GAME_OVER,
};
// Variables del jugador // Variables del jugador
#define PLAYER_INVULNERABLE_COUNTER 200 constexpr int PLAYER_INVULNERABLE_COUNTER = 200;
#define PLAYER_POWERUP_COUNTER 1500 constexpr int PLAYER_POWERUP_COUNTER = 1500;
// Clase Player // Clase Player
class Player class Player
{ {
private: private:
// Objetos y punteros // Objetos y punteros
AnimatedSprite *playerSprite; // Sprite para dibujar el jugador std::unique_ptr<AnimatedSprite> playerSprite; // Sprite para dibujar el jugador
AnimatedSprite *powerSprite; // Sprite para dibujar el aura del jugador con el poder a tope std::unique_ptr<AnimatedSprite> powerSprite; // Sprite para dibujar el aura del jugador con el poder a tope
std::unique_ptr<EnterName> enterName; // Clase utilizada para introducir el nombre
SDL_Rect *playArea; // Rectangulo con la zona de juego SDL_Rect *playArea; // Rectangulo con la zona de juego
EnterName *enterName;
// Variables // Variables
int id; // Numero de identificación para el jugador int id; // Numero de identificación para el jugador
@@ -54,9 +59,9 @@ private:
int cooldown; // Contador durante el cual no puede disparar int cooldown; // Contador durante el cual no puede disparar
int score; // Puntos del jugador int score; // Puntos del jugador
float scoreMultiplier; // Multiplicador de puntos float scoreMultiplier; // Multiplicador de puntos
int statusWalking; // Estado del jugador al moverse playerStatus statusWalking; // Estado del jugador al moverse
int statusFiring; // Estado del jugador al disparar playerStatus statusFiring; // Estado del jugador al disparar
int statusPlaying; // Estado del jugador en el juego playerStatus statusPlaying; // Estado del jugador en el juego
bool invulnerable; // Indica si el jugador es invulnerable bool invulnerable; // Indica si el jugador es invulnerable
int invulnerableCounter; // Contador para la invulnerabilidad int invulnerableCounter; // Contador para la invulnerabilidad
bool extraHit; // Indica si el jugador tiene un toque extra bool extraHit; // Indica si el jugador tiene un toque extra
@@ -82,12 +87,15 @@ private:
// Actualiza el contador de continue // Actualiza el contador de continue
void updateContinueCounter(); void updateContinueCounter();
// Indica si el jugador se puede dibujar
bool isRenderable() const;
public: public:
// Constructor // 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, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations);
// Destructor // Destructor
~Player(); ~Player() = default;
// Iniciador // Iniciador
void init(); void init();
@@ -114,28 +122,28 @@ public:
void move(); void move();
// Establece el estado del jugador // Establece el estado del jugador
void setWalkingStatus(int status); void setWalkingStatus(playerStatus status);
// Establece el estado del jugador // Establece el estado del jugador
void setFiringStatus(int status); void setFiringStatus(playerStatus status);
// Establece la animación correspondiente al estado // Establece la animación correspondiente al estado
void setAnimation(); void setAnimation();
// Obtiene el valor de la variable // Obtiene el valor de la variable
int getPosX(); int getPosX() const;
// Obtiene el valor de la variable // Obtiene el valor de la variable
int getPosY(); int getPosY() const;
// Obtiene el valor de la variable // Obtiene el valor de la variable
int getWidth(); int getWidth() const;
// Obtiene el valor de la variable // Obtiene el valor de la variable
int getHeight(); int getHeight() const;
// Indica si el jugador puede disparar // Indica si el jugador puede disparar
bool canFire(); bool canFire() const;
// Establece el valor de la variable // Establece el valor de la variable
void setFireCooldown(int time); void setFireCooldown(int time);
@@ -144,7 +152,7 @@ public:
void updateCooldown(); void updateCooldown();
// Obtiene la puntuación del jugador // Obtiene la puntuación del jugador
int getScore(); int getScore() const;
// Asigna un valor a la puntuación del jugador // Asigna un valor a la puntuación del jugador
void setScore(int score); void setScore(int score);
@@ -153,31 +161,34 @@ public:
void addScore(int score); void addScore(int score);
// Indica si el jugador está jugando // Indica si el jugador está jugando
bool isPlaying(); bool isPlaying() const;
// Indica si el jugador está continuando // Indica si el jugador está continuando
bool isContinue(); bool isContinue() const;
// Indica si el jugador está esperando // Indica si el jugador está esperando
bool isWaiting(); bool isWaiting() const;
// Indica si el jugador está introduciendo su nombre // Indica si el jugador está introduciendo su nombre
bool isEnteringName(); bool isEnteringName() const;
// Indica si el jugador está muriendose // Indica si el jugador está muriendose
bool isDying(); bool isDying() const;
// Indica si el jugador ha terminado de morir // Indica si el jugador ha terminado de morir
bool hasDied(); bool hasDied() const;
// Indica si el jugador ya ha terminado de jugar
bool isGameOver() const;
// Establece el estado del jugador en el juego // Establece el estado del jugador en el juego
void setStatusPlaying(int value); void setStatusPlaying(playerStatus value);
// Obtiene el estado del jugador en el juego // Obtiene el estado del jugador en el juego
int getStatusPlaying(); playerStatus getStatusPlaying() const;
// Obtiene el valor de la variable // Obtiene el valor de la variable
float getScoreMultiplier(); float getScoreMultiplier() const;
// Establece el valor de la variable // Establece el valor de la variable
void setScoreMultiplier(float value); void setScoreMultiplier(float value);
@@ -189,25 +200,25 @@ public:
void decScoreMultiplier(); void decScoreMultiplier();
// Obtiene el valor de la variable // Obtiene el valor de la variable
bool isInvulnerable(); bool isInvulnerable() const;
// Establece el valor del estado // Establece el valor del estado
void setInvulnerable(bool value); void setInvulnerable(bool value);
// Obtiene el valor de la variable // Obtiene el valor de la variable
int getInvulnerableCounter(); int getInvulnerableCounter() const;
// Establece el valor de la variable // Establece el valor de la variable
void setInvulnerableCounter(int value); void setInvulnerableCounter(int value);
// Obtiene el valor de la variable // Obtiene el valor de la variable
bool isPowerUp(); bool isPowerUp() const;
// Establece el valor de la variable a verdadero // Establece el valor de la variable a verdadero
void setPowerUp(); void setPowerUp();
// Obtiene el valor de la variable // Obtiene el valor de la variable
int getPowerUpCounter(); int getPowerUpCounter() const;
// Establece el valor de la variable // Establece el valor de la variable
void setPowerUpCounter(int value); void setPowerUpCounter(int value);
@@ -216,7 +227,7 @@ public:
void updatePowerUpCounter(); void updatePowerUpCounter();
// Obtiene el valor de la variable // Obtiene el valor de la variable
bool hasExtraHit(); bool hasExtraHit() const;
// Concede un toque extra al jugador // Concede un toque extra al jugador
void giveExtraHit(); void giveExtraHit();
@@ -231,19 +242,19 @@ public:
void disableInput(); void disableInput();
// Devuelve el número de cafes actuales // Devuelve el número de cafes actuales
int getCoffees(); int getCoffees() const;
// Obtiene el circulo de colisión // Obtiene el circulo de colisión
circle_t &getCollider(); circle_t &getCollider();
// Obtiene el valor de la variable // Obtiene el valor de la variable
int getContinueCounter(); int getContinueCounter() const;
// Le asigna un panel en el marcador al jugador // Le asigna un panel en el marcador al jugador
void setScoreBoardPanel(int panel); void setScoreBoardPanel(int panel);
// Obtiene el valor de la variable // Obtiene el valor de la variable
int getScoreBoardPanel(); int getScoreBoardPanel() const;
// Decrementa el contador de continuar // Decrementa el contador de continuar
void decContinueCounter(); void decContinueCounter();
@@ -255,20 +266,20 @@ public:
void setRecordName(std::string recordName); void setRecordName(std::string recordName);
// Obtiene el nombre del jugador // Obtiene el nombre del jugador
std::string getName(); std::string getName() const;
// Obtiene el nombre del jugador para la tabla de mejores puntuaciones // Obtiene el nombre del jugador para la tabla de mejores puntuaciones
std::string getRecordName(); std::string getRecordName() const;
// Obtiene la posici´´on que se está editando del nombre del jugador para la tabla de mejores puntuaciones // Obtiene la posici´´on que se está editando del nombre del jugador para la tabla de mejores puntuaciones
int getRecordNamePos(); int getRecordNamePos() const;
// Establece el mando que usará para ser controlado // Establece el mando que usará para ser controlado
void setController(int index); void setController(int index);
// Obtiene el mando que usa para ser controlado // Obtiene el mando que usa para ser controlado
int getController(); int getController() const;
// Obtiene el "id" del jugador // Obtiene el "id" del jugador
int getId(); int getId() const;
}; };

View File

@@ -37,9 +37,9 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer)
hiScoreName = ""; hiScoreName = "";
color = {0, 0, 0}; color = {0, 0, 0};
rect = {0, 0, 320, 40}; rect = {0, 0, 320, 40};
panel[SCOREBOARD_LEFT_PANEL].mode = SCOREBOARD_MODE_SCORE; panel[SCOREBOARD_LEFT_PANEL].mode = scoreboardMode::SCORE;
panel[SCOREBOARD_RIGHT_PANEL].mode = SCOREBOARD_MODE_SCORE; panel[SCOREBOARD_RIGHT_PANEL].mode = scoreboardMode::SCORE;
panel[SCOREBOARD_CENTER_PANEL].mode = SCOREBOARD_MODE_STAGE_INFO; panel[SCOREBOARD_CENTER_PANEL].mode = scoreboardMode::STAGE_INFO;
ticks = SDL_GetTicks(); ticks = SDL_GetTicks();
counter = 0; counter = 0;
@@ -248,7 +248,8 @@ void Scoreboard::fillPanelTextures()
switch (panel[i].mode) switch (panel[i].mode)
{ {
case SCOREBOARD_MODE_SCORE: case scoreboardMode::SCORE:
{
// SCORE // SCORE
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[i]); textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[i]);
textScoreBoard->writeCentered(slot4_2.x, slot4_2.y, updateScoreText(score[i])); textScoreBoard->writeCentered(slot4_2.x, slot4_2.y, updateScoreText(score[i]));
@@ -257,26 +258,45 @@ void Scoreboard::fillPanelTextures()
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(55)); textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(55));
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(mult[i]).substr(0, 3)); textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(mult[i]).substr(0, 3));
break; break;
}
case SCOREBOARD_MODE_DEMO: case scoreboardMode::DEMO:
{
// DEMO MODE
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(101)); textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(101));
// PRESS START TO PLAY
if (counter % 10 < 8) if (counter % 10 < 8)
{ {
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y - 2, lang::getText(103)); textScoreBoard->writeCentered(slot4_3.x, slot4_3.y - 2, lang::getText(103));
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y - 2, lang::getText(104)); textScoreBoard->writeCentered(slot4_4.x, slot4_4.y - 2, lang::getText(104));
} }
break; break;
}
case SCOREBOARD_MODE_GAME_OVER: case scoreboardMode::WAITING:
{
// GAME OVER
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(102)); textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(102));
// PRESS START TO PLAY
if (counter % 10 < 8) if (counter % 10 < 8)
{ {
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y - 2, lang::getText(103)); textScoreBoard->writeCentered(slot4_3.x, slot4_3.y - 2, lang::getText(103));
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y - 2, lang::getText(104)); textScoreBoard->writeCentered(slot4_4.x, slot4_4.y - 2, lang::getText(104));
} }
break; break;
}
case SCOREBOARD_MODE_STAGE_INFO: case scoreboardMode::GAME_OVER:
{
// GAME OVER
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(102));
break;
}
case scoreboardMode::STAGE_INFO:
{
// STAGE // STAGE
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, lang::getText(57) + std::to_string(stage)); textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, lang::getText(57) + std::to_string(stage));
@@ -290,8 +310,10 @@ void Scoreboard::fillPanelTextures()
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(56)); textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(56));
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, hiScoreName + " - " + updateScoreText(hiScore)); textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, hiScoreName + " - " + updateScoreText(hiScore));
break; break;
}
case SCOREBOARD_MODE_CONTINUE: case scoreboardMode::CONTINUE:
{
// SCORE // SCORE
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[i]); textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[i]);
textScoreBoard->writeCentered(slot4_2.x, slot4_2.y, updateScoreText(score[i])); textScoreBoard->writeCentered(slot4_2.x, slot4_2.y, updateScoreText(score[i]));
@@ -300,8 +322,9 @@ void Scoreboard::fillPanelTextures()
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(105)); textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(105));
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(continueCounter[i])); textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(continueCounter[i]));
break; break;
}
case SCOREBOARD_MODE_ENTER_NAME: case scoreboardMode::ENTER_NAME:
{ {
// SCORE // SCORE
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[i]); textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[i]);
@@ -413,7 +436,7 @@ void Scoreboard::recalculateAnchors()
} }
// Establece el modo del marcador // Establece el modo del marcador
void Scoreboard::setMode(int index, scoreboard_modes_e mode) void Scoreboard::setMode(int index, scoreboardMode mode)
{ {
panel[index].mode = mode; panel[index].mode = mode;
} }

View File

@@ -12,29 +12,29 @@ class Text;
class Texture; class Texture;
// Defines // Defines
#define SCOREBOARD_LEFT_PANEL 0 constexpr int SCOREBOARD_LEFT_PANEL = 0;
#define SCOREBOARD_CENTER_PANEL 1 constexpr int SCOREBOARD_CENTER_PANEL = 1;
#define SCOREBOARD_RIGHT_PANEL 2 constexpr int SCOREBOARD_RIGHT_PANEL = 2;
#define SCOREBOARD_MAX_PANELS 3 constexpr int SCOREBOARD_MAX_PANELS = 3;
constexpr int SCOREBOARD_TICK_SPEED = 100;
#define SCOREBOARD_TICK_SPEED 100
// Enums // Enums
enum scoreboard_modes_e enum class scoreboardMode
{ {
SCOREBOARD_MODE_SCORE, SCORE,
SCOREBOARD_MODE_STAGE_INFO, STAGE_INFO,
SCOREBOARD_MODE_CONTINUE, CONTINUE,
SCOREBOARD_MODE_GAME_OVER, WAITING,
SCOREBOARD_MODE_DEMO, GAME_OVER,
SCOREBOARD_MODE_ENTER_NAME, DEMO,
SCOREBOARD_MODE_NUM_MODES, ENTER_NAME,
NUM_MODES,
}; };
// Structs // Structs
struct panel_t struct panel_t
{ {
scoreboard_modes_e mode; // Modo en el que se encuentra el panel scoreboardMode mode; // Modo en el que se encuentra el panel
SDL_Rect pos; // Posición donde dibujar el panel dentro del marcador SDL_Rect pos; // Posición donde dibujar el panel dentro del marcador
}; };
@@ -146,5 +146,5 @@ public:
void setPos(SDL_Rect rect); void setPos(SDL_Rect rect);
// Establece el modo del marcador // Establece el modo del marcador
void setMode(int index, scoreboard_modes_e mode); void setMode(int index, scoreboardMode mode);
}; };

View File

@@ -378,7 +378,6 @@ void Title::swapControllers()
for (int i = 0; i < MAX_CONTROLLERS; ++i) for (int i = 0; i < MAX_CONTROLLERS; ++i)
{ {
const int index = playerControllerIndex[i]; const int index = playerControllerIndex[i];
//if (options.controller[index].name != "NO NAME")
if (options.controller[index].plugged) if (options.controller[index].plugged)
{ {
text[i] = "Jugador " + std::to_string(i + 1) + ": " + options.controller[index].name; text[i] = "Jugador " + std::to_string(i + 1) + ": " + options.controller[index].name;