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

View File

@@ -36,7 +36,10 @@ public:
EnterName();
// Destructor
~EnterName();
~EnterName() = default;
// Inicializa el objeto
void init();
// Incrementa la posición
void incPos();
@@ -51,8 +54,8 @@ public:
void decIndex();
// Obtiene el nombre
std::string getName();
std::string getName() const;
// 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:
{
cleanBackbuffer(0, 0, 0, 0);
rect1 = {0, 0, param.game.width, 0};
square.clear();
a = 255;

View File

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

View File

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

View File

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

View File

@@ -5,73 +5,78 @@
#include <string> // for string, basic_string
#include <vector> // for vector
#include "utils.h" // for circle_t
#include "enter_name.h"
#include <memory>
class AnimatedSprite;
class EnterName;
class Texture;
// Estados del jugador
#define PLAYER_STATUS_WALKING_LEFT 0
#define PLAYER_STATUS_WALKING_RIGHT 1
#define PLAYER_STATUS_WALKING_STOP 2
enum class playerStatus
{
WALKING_LEFT,
WALKING_RIGHT,
WALKING_STOP,
#define PLAYER_STATUS_FIRING_UP 0
#define PLAYER_STATUS_FIRING_LEFT 1
#define PLAYER_STATUS_FIRING_RIGHT 2
#define PLAYER_STATUS_FIRING_NO 3
FIRING_UP,
FIRING_LEFT,
FIRING_RIGHT,
FIRING_NO,
#define PLAYER_STATUS_PLAYING 0
#define PLAYER_STATUS_CONTINUE 1
#define PLAYER_STATUS_WAITING 2
#define PLAYER_STATUS_ENTERING_NAME 3
#define PLAYER_STATUS_DYING 4
#define PLAYER_STATUS_DIED 5
PLAYING,
CONTINUE,
WAITING,
ENTERING_NAME,
DYING,
DIED,
GAME_OVER,
};
// Variables del jugador
#define PLAYER_INVULNERABLE_COUNTER 200
#define PLAYER_POWERUP_COUNTER 1500
constexpr int PLAYER_INVULNERABLE_COUNTER = 200;
constexpr int PLAYER_POWERUP_COUNTER = 1500;
// Clase Player
class Player
{
private:
// Objetos y punteros
AnimatedSprite *playerSprite; // Sprite para dibujar el jugador
AnimatedSprite *powerSprite; // Sprite para dibujar el aura del jugador con el poder a tope
SDL_Rect *playArea; // Rectangulo con la zona de juego
EnterName *enterName;
std::unique_ptr<AnimatedSprite> playerSprite; // Sprite para dibujar el jugador
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
// Variables
int id; // Numero de identificación para el jugador
float posX; // Posicion en el eje X
int posY; // Posicion en el eje Y
float defaultPosX; // Posición inicial para el jugador
int defaultPosY; // Posición inicial para el jugador
int width; // Anchura
int height; // Altura
float velX; // Cantidad de pixeles a desplazarse en el eje X
int velY; // Cantidad de pixeles a desplazarse en el eje Y
float baseSpeed; // Velocidad base del jugador
int cooldown; // Contador durante el cual no puede disparar
int score; // Puntos del jugador
float scoreMultiplier; // Multiplicador de puntos
int statusWalking; // Estado del jugador al moverse
int statusFiring; // Estado del jugador al disparar
int statusPlaying; // Estado del jugador en el juego
bool invulnerable; // Indica si el jugador es invulnerable
int invulnerableCounter; // Contador para la invulnerabilidad
bool extraHit; // Indica si el jugador tiene un toque extra
int coffees; // Indica cuantos cafes lleva acumulados
bool powerUp; // Indica si el jugador tiene activo el modo PowerUp
int powerUpCounter; // Temporizador para el modo PowerUp
int powerUpDespX; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
bool input; // Indica si puede recibir ordenes de entrada
circle_t collider; // Circulo de colisión del jugador
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
std::string recordName; // Nombre del jugador para l atabla de mejores puntuaciones
int controllerIndex; // Indice del array de mandos que utilizará para moverse
int id; // Numero de identificación para el jugador
float posX; // Posicion en el eje X
int posY; // Posicion en el eje Y
float defaultPosX; // Posición inicial para el jugador
int defaultPosY; // Posición inicial para el jugador
int width; // Anchura
int height; // Altura
float velX; // Cantidad de pixeles a desplazarse en el eje X
int velY; // Cantidad de pixeles a desplazarse en el eje Y
float baseSpeed; // Velocidad base del jugador
int cooldown; // Contador durante el cual no puede disparar
int score; // Puntos del jugador
float scoreMultiplier; // Multiplicador de puntos
playerStatus statusWalking; // Estado del jugador al moverse
playerStatus statusFiring; // Estado del jugador al disparar
playerStatus statusPlaying; // Estado del jugador en el juego
bool invulnerable; // Indica si el jugador es invulnerable
int invulnerableCounter; // Contador para la invulnerabilidad
bool extraHit; // Indica si el jugador tiene un toque extra
int coffees; // Indica cuantos cafes lleva acumulados
bool powerUp; // Indica si el jugador tiene activo el modo PowerUp
int powerUpCounter; // Temporizador para el modo PowerUp
int powerUpDespX; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
bool input; // Indica si puede recibir ordenes de entrada
circle_t collider; // Circulo de colisión del jugador
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
std::string recordName; // Nombre del jugador para l atabla de mejores puntuaciones
int controllerIndex; // Indice del array de mandos que utilizará para moverse
// Actualiza el circulo de colisión a la posición del jugador
void shiftColliders();
@@ -82,12 +87,15 @@ private:
// Actualiza el contador de continue
void updateContinueCounter();
// Indica si el jugador se puede dibujar
bool isRenderable() const;
public:
// Constructor
Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations);
// Destructor
~Player();
~Player() = default;
// Iniciador
void init();
@@ -114,28 +122,28 @@ public:
void move();
// Establece el estado del jugador
void setWalkingStatus(int status);
void setWalkingStatus(playerStatus status);
// Establece el estado del jugador
void setFiringStatus(int status);
void setFiringStatus(playerStatus status);
// Establece la animación correspondiente al estado
void setAnimation();
// Obtiene el valor de la variable
int getPosX();
int getPosX() const;
// Obtiene el valor de la variable
int getPosY();
int getPosY() const;
// Obtiene el valor de la variable
int getWidth();
int getWidth() const;
// Obtiene el valor de la variable
int getHeight();
int getHeight() const;
// Indica si el jugador puede disparar
bool canFire();
bool canFire() const;
// Establece el valor de la variable
void setFireCooldown(int time);
@@ -144,7 +152,7 @@ public:
void updateCooldown();
// Obtiene la puntuación del jugador
int getScore();
int getScore() const;
// Asigna un valor a la puntuación del jugador
void setScore(int score);
@@ -153,31 +161,34 @@ public:
void addScore(int score);
// Indica si el jugador está jugando
bool isPlaying();
bool isPlaying() const;
// Indica si el jugador está continuando
bool isContinue();
bool isContinue() const;
// Indica si el jugador está esperando
bool isWaiting();
bool isWaiting() const;
// Indica si el jugador está introduciendo su nombre
bool isEnteringName();
bool isEnteringName() const;
// Indica si el jugador está muriendose
bool isDying();
bool isDying() const;
// 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
void setStatusPlaying(int value);
void setStatusPlaying(playerStatus value);
// Obtiene el estado del jugador en el juego
int getStatusPlaying();
playerStatus getStatusPlaying() const;
// Obtiene el valor de la variable
float getScoreMultiplier();
float getScoreMultiplier() const;
// Establece el valor de la variable
void setScoreMultiplier(float value);
@@ -189,25 +200,25 @@ public:
void decScoreMultiplier();
// Obtiene el valor de la variable
bool isInvulnerable();
bool isInvulnerable() const;
// Establece el valor del estado
void setInvulnerable(bool value);
// Obtiene el valor de la variable
int getInvulnerableCounter();
int getInvulnerableCounter() const;
// Establece el valor de la variable
void setInvulnerableCounter(int value);
// Obtiene el valor de la variable
bool isPowerUp();
bool isPowerUp() const;
// Establece el valor de la variable a verdadero
void setPowerUp();
// Obtiene el valor de la variable
int getPowerUpCounter();
int getPowerUpCounter() const;
// Establece el valor de la variable
void setPowerUpCounter(int value);
@@ -216,7 +227,7 @@ public:
void updatePowerUpCounter();
// Obtiene el valor de la variable
bool hasExtraHit();
bool hasExtraHit() const;
// Concede un toque extra al jugador
void giveExtraHit();
@@ -231,19 +242,19 @@ public:
void disableInput();
// Devuelve el número de cafes actuales
int getCoffees();
int getCoffees() const;
// Obtiene el circulo de colisión
circle_t &getCollider();
// Obtiene el valor de la variable
int getContinueCounter();
int getContinueCounter() const;
// Le asigna un panel en el marcador al jugador
void setScoreBoardPanel(int panel);
// Obtiene el valor de la variable
int getScoreBoardPanel();
int getScoreBoardPanel() const;
// Decrementa el contador de continuar
void decContinueCounter();
@@ -255,20 +266,20 @@ public:
void setRecordName(std::string recordName);
// Obtiene el nombre del jugador
std::string getName();
std::string getName() const;
// 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
int getRecordNamePos();
int getRecordNamePos() const;
// Establece el mando que usará para ser controlado
void setController(int index);
// Obtiene el mando que usa para ser controlado
int getController();
int getController() const;
// Obtiene el "id" del jugador
int getId();
int getId() const;
};

View File

@@ -37,9 +37,9 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer)
hiScoreName = "";
color = {0, 0, 0};
rect = {0, 0, 320, 40};
panel[SCOREBOARD_LEFT_PANEL].mode = SCOREBOARD_MODE_SCORE;
panel[SCOREBOARD_RIGHT_PANEL].mode = SCOREBOARD_MODE_SCORE;
panel[SCOREBOARD_CENTER_PANEL].mode = SCOREBOARD_MODE_STAGE_INFO;
panel[SCOREBOARD_LEFT_PANEL].mode = scoreboardMode::SCORE;
panel[SCOREBOARD_RIGHT_PANEL].mode = scoreboardMode::SCORE;
panel[SCOREBOARD_CENTER_PANEL].mode = scoreboardMode::STAGE_INFO;
ticks = SDL_GetTicks();
counter = 0;
@@ -248,7 +248,8 @@ void Scoreboard::fillPanelTextures()
switch (panel[i].mode)
{
case SCOREBOARD_MODE_SCORE:
case scoreboardMode::SCORE:
{
// SCORE
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[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_4.x, slot4_4.y, std::to_string(mult[i]).substr(0, 3));
break;
}
case SCOREBOARD_MODE_DEMO:
case scoreboardMode::DEMO:
{
// DEMO MODE
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(101));
// PRESS START TO PLAY
if (counter % 10 < 8)
{
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y - 2, lang::getText(103));
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y - 2, lang::getText(104));
}
break;
}
case SCOREBOARD_MODE_GAME_OVER:
case scoreboardMode::WAITING:
{
// GAME OVER
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, lang::getText(102));
// PRESS START TO PLAY
if (counter % 10 < 8)
{
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y - 2, lang::getText(103));
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y - 2, lang::getText(104));
}
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
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_4.x, slot4_4.y, hiScoreName + " - " + updateScoreText(hiScore));
break;
}
case SCOREBOARD_MODE_CONTINUE:
case scoreboardMode::CONTINUE:
{
// SCORE
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[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_4.x, slot4_4.y, std::to_string(continueCounter[i]));
break;
}
case SCOREBOARD_MODE_ENTER_NAME:
case scoreboardMode::ENTER_NAME:
{
// SCORE
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[i]);
@@ -314,7 +337,7 @@ void Scoreboard::fillPanelTextures()
for (int j = 0; j < (int)recordName[i].size(); ++j)
{
if (j == selectorPos[i])
{// La letra seleccionada se pinta de forma intermitente
{ // La letra seleccionada se pinta de forma intermitente
if (counter % 3 > 0)
{
SDL_RenderDrawLine(renderer, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
@@ -413,7 +436,7 @@ void Scoreboard::recalculateAnchors()
}
// 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;
}

View File

@@ -12,29 +12,29 @@ class Text;
class Texture;
// Defines
#define SCOREBOARD_LEFT_PANEL 0
#define SCOREBOARD_CENTER_PANEL 1
#define SCOREBOARD_RIGHT_PANEL 2
#define SCOREBOARD_MAX_PANELS 3
#define SCOREBOARD_TICK_SPEED 100
constexpr int SCOREBOARD_LEFT_PANEL = 0;
constexpr int SCOREBOARD_CENTER_PANEL = 1;
constexpr int SCOREBOARD_RIGHT_PANEL = 2;
constexpr int SCOREBOARD_MAX_PANELS = 3;
constexpr int SCOREBOARD_TICK_SPEED = 100;
// Enums
enum scoreboard_modes_e
enum class scoreboardMode
{
SCOREBOARD_MODE_SCORE,
SCOREBOARD_MODE_STAGE_INFO,
SCOREBOARD_MODE_CONTINUE,
SCOREBOARD_MODE_GAME_OVER,
SCOREBOARD_MODE_DEMO,
SCOREBOARD_MODE_ENTER_NAME,
SCOREBOARD_MODE_NUM_MODES,
SCORE,
STAGE_INFO,
CONTINUE,
WAITING,
GAME_OVER,
DEMO,
ENTER_NAME,
NUM_MODES,
};
// Structs
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
};
@@ -146,5 +146,5 @@ public:
void setPos(SDL_Rect rect);
// 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)
{
const int index = playerControllerIndex[i];
//if (options.controller[index].name != "NO NAME")
if (options.controller[index].plugged)
{
text[i] = "Jugador " + std::to_string(i + 1) + ": " + options.controller[index].name;