primera implementació dels estats nous del jugador: playing, continue, waiting
This commit is contained in:
@@ -107,9 +107,11 @@ void Game::init(int playerID)
|
|||||||
|
|
||||||
// Crea los dos jugadores
|
// Crea los dos jugadores
|
||||||
Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[0], playerAnimations);
|
Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[0], playerAnimations);
|
||||||
|
player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL);
|
||||||
players.push_back(player1);
|
players.push_back(player1);
|
||||||
|
|
||||||
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[1], playerAnimations);
|
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[1], playerAnimations);
|
||||||
|
player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL);
|
||||||
players.push_back(player2);
|
players.push_back(player2);
|
||||||
|
|
||||||
// Cambia el estado del jugador seleccionado
|
// Cambia el estado del jugador seleccionado
|
||||||
@@ -931,22 +933,18 @@ void Game::updatePlayers()
|
|||||||
{
|
{
|
||||||
for (auto player : players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
if (player->isPlaying())
|
player->update();
|
||||||
{
|
|
||||||
player->update();
|
|
||||||
|
|
||||||
// Comprueba la colisión entre el jugador y los globos
|
if (player->isPlaying())
|
||||||
|
{ // Comprueba la colisión entre el jugador y los globos
|
||||||
if (checkPlayerBalloonCollision(player))
|
if (checkPlayerBalloonCollision(player))
|
||||||
{
|
{
|
||||||
if (player->isPlaying())
|
killPlayer(player);
|
||||||
{
|
|
||||||
killPlayer(player);
|
|
||||||
|
|
||||||
if (demo.enabled && allPlayersAreWaiting())
|
if (demo.enabled && allPlayersAreWaiting())
|
||||||
{
|
{
|
||||||
fade->setType(FADE_RANDOM_SQUARE);
|
fade->setType(FADE_RANDOM_SQUARE);
|
||||||
fade->activate();
|
fade->activate();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1968,6 +1966,7 @@ void Game::update()
|
|||||||
updatePlayers();
|
updatePlayers();
|
||||||
|
|
||||||
// Actualiza el marcador
|
// Actualiza el marcador
|
||||||
|
checkPlayersStatus();
|
||||||
updateScoreboard();
|
updateScoreboard();
|
||||||
|
|
||||||
// Actualiza el fondo
|
// Actualiza el fondo
|
||||||
@@ -2101,9 +2100,9 @@ void Game::render()
|
|||||||
renderSeparator();
|
renderSeparator();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
//text->write(0, 0, "P1 ALIVE: " + boolToString(players[0]->isAlive()));
|
// text->write(0, 0, "P1 ALIVE: " + boolToString(players[0]->isAlive()));
|
||||||
//text->write(0, 10, "P2 ALIVE: " + boolToString(players[1]->isAlive()));
|
// text->write(0, 10, "P2 ALIVE: " + boolToString(players[1]->isAlive()));
|
||||||
//text->write(0, 20, "ALL DEAD: " + boolToString(allPlayersAreWaiting()));
|
// text->write(0, 20, "ALL DEAD: " + boolToString(allPlayersAreWaiting()));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Dibuja el fade
|
// Dibuja el fade
|
||||||
@@ -2631,10 +2630,10 @@ void Game::updateHelper()
|
|||||||
// Comprueba si todos los jugadores han terminado de jugar
|
// Comprueba si todos los jugadores han terminado de jugar
|
||||||
bool Game::allPlayersAreWaiting()
|
bool Game::allPlayersAreWaiting()
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = true;
|
||||||
for (auto player : players)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
success |= player->isWaiting();
|
success &= player->isWaiting();
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
@@ -2841,3 +2840,29 @@ void Game::addScoreToScoreBoard(std::string name, int score)
|
|||||||
m->add(entry);
|
m->add(entry);
|
||||||
delete m;
|
delete m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba el estado de los jugadores
|
||||||
|
void Game::checkPlayersStatus()
|
||||||
|
{
|
||||||
|
for (auto player : players)
|
||||||
|
{
|
||||||
|
switch (player->getStatusPlaying())
|
||||||
|
{
|
||||||
|
case PLAYER_STATUS_PLAYING:
|
||||||
|
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_SCORE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_CONTINUE:
|
||||||
|
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_CONTINUE);
|
||||||
|
scoreboard->setContinue1(player->getContinueCounter());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_WAITING:
|
||||||
|
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_GAME_OVER);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -446,6 +446,9 @@ private:
|
|||||||
// Añade una puntuación a la tabla de records
|
// Añade una puntuación a la tabla de records
|
||||||
void addScoreToScoreBoard(std::string name, int score);
|
void addScoreToScoreBoard(std::string name, int score);
|
||||||
|
|
||||||
|
// Comprueba el estado de los jugadores
|
||||||
|
void checkPlayersStatus();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(int playerID, int currentStage, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section, JA_Music_t *music);
|
Game(int playerID, int currentStage, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, param_t *param, options_t *options, section_t *section, JA_Music_t *music);
|
||||||
|
|||||||
@@ -345,6 +345,12 @@ void Player::setStatusPlaying(int value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtiene el estado del jugador en el juego
|
||||||
|
int Player::getStatusPlaying()
|
||||||
|
{
|
||||||
|
return statusPlaying;
|
||||||
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
float Player::getScoreMultiplier()
|
float Player::getScoreMultiplier()
|
||||||
{
|
{
|
||||||
@@ -514,12 +520,6 @@ void Player::shiftColliders()
|
|||||||
collider.y = int(posY + (height / 2));
|
collider.y = int(posY + (height / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el puntero a la textura con los gráficos de la animación de morir
|
|
||||||
Texture *Player::getDeadTexture()
|
|
||||||
{
|
|
||||||
return playerSprite->getTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pone las texturas del jugador
|
// Pone las texturas del jugador
|
||||||
void Player::setPlayerTextures(std::vector<Texture *> texture)
|
void Player::setPlayerTextures(std::vector<Texture *> texture)
|
||||||
{
|
{
|
||||||
@@ -547,6 +547,23 @@ void Player::updateContinueCounter()
|
|||||||
|
|
||||||
// Decrementa el contador
|
// Decrementa el contador
|
||||||
continueCounter--;
|
continueCounter--;
|
||||||
|
|
||||||
|
if (continueCounter < 0)
|
||||||
|
{
|
||||||
|
setStatusPlaying(PLAYER_STATUS_WAITING);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Le asigna un panel en el marcador al jugador
|
||||||
|
void Player::setScoreBoardPanel(int panel)
|
||||||
|
{
|
||||||
|
scoreBoardPanel = panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int Player::getScoreBoardPanel()
|
||||||
|
{
|
||||||
|
return scoreBoardPanel;
|
||||||
|
}
|
||||||
@@ -67,6 +67,7 @@ private:
|
|||||||
circle_t collider; // Circulo de colisión del jugador
|
circle_t collider; // Circulo de colisión del jugador
|
||||||
int continueCounter; // Contador para poder continuar
|
int continueCounter; // Contador para poder continuar
|
||||||
Uint32 continueTicks; // Variable para poder cambiar el contador de continue en función del tiempo
|
Uint32 continueTicks; // Variable para poder cambiar el contador de continue en función del tiempo
|
||||||
|
int scoreBoardPanel; // Panel del marcador asociado al jugador
|
||||||
|
|
||||||
// Actualiza el circulo de colisión a la posición del jugador
|
// Actualiza el circulo de colisión a la posición del jugador
|
||||||
void shiftColliders();
|
void shiftColliders();
|
||||||
@@ -153,6 +154,9 @@ public:
|
|||||||
// Establece el estado del jugador en el juego
|
// Establece el estado del jugador en el juego
|
||||||
void setStatusPlaying(int value);
|
void setStatusPlaying(int value);
|
||||||
|
|
||||||
|
// Obtiene el estado del jugador en el juego
|
||||||
|
int getStatusPlaying();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
float getScoreMultiplier();
|
float getScoreMultiplier();
|
||||||
|
|
||||||
@@ -213,9 +217,12 @@ public:
|
|||||||
// Obtiene el circulo de colisión
|
// Obtiene el circulo de colisión
|
||||||
circle_t &getCollider();
|
circle_t &getCollider();
|
||||||
|
|
||||||
// Obtiene el puntero a la textura con los gráficos de la animación de morir
|
|
||||||
Texture *getDeadTexture();
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getContinueCounter();
|
int getContinueCounter();
|
||||||
|
|
||||||
|
// Le asigna un panel en el marcador al jugador
|
||||||
|
void setScoreBoardPanel(int panel);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int getScoreBoardPanel();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lan
|
|||||||
score2 = 0;
|
score2 = 0;
|
||||||
mult1 = 1;
|
mult1 = 1;
|
||||||
mult2 = 1;
|
mult2 = 1;
|
||||||
|
continue1 = 0;
|
||||||
|
continue2 = 0;
|
||||||
hiScore = 0;
|
hiScore = 0;
|
||||||
power = 0;
|
power = 0;
|
||||||
hiScoreName = "";
|
hiScoreName = "";
|
||||||
@@ -159,6 +161,18 @@ void Scoreboard::setMult2(float mult)
|
|||||||
mult2 = mult;
|
mult2 = mult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Scoreboard::setContinue1(int value)
|
||||||
|
{
|
||||||
|
continue1 = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Scoreboard::setContinue2(int value)
|
||||||
|
{
|
||||||
|
continue2 = value;
|
||||||
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setStage(int stage)
|
void Scoreboard::setStage(int stage)
|
||||||
{
|
{
|
||||||
@@ -269,6 +283,16 @@ void Scoreboard::fillPanelTextures()
|
|||||||
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:
|
||||||
|
// SCORE
|
||||||
|
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, lang->getText(53));
|
||||||
|
textScoreBoard->writeCentered(slot4_2.x, slot4_2.y, updateScoreText(score1));
|
||||||
|
|
||||||
|
// CONTINUE
|
||||||
|
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, "Continuar?");
|
||||||
|
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(continue1));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ private:
|
|||||||
int score2; // Puntuación del jugador 2
|
int score2; // Puntuación del jugador 2
|
||||||
float mult1; // Multiplicador del jugador 1
|
float mult1; // Multiplicador del jugador 1
|
||||||
float mult2; // Multiplicador del jugador 2
|
float mult2; // Multiplicador del jugador 2
|
||||||
|
int continue1; // Tiempo para continuar del jugador 1
|
||||||
|
int continue2; // Tiempo para continuar del jugador 2
|
||||||
int hiScore; // Máxima puntuación
|
int hiScore; // Máxima puntuación
|
||||||
float power; // Poder actual de la fase
|
float power; // Poder actual de la fase
|
||||||
std::string hiScoreName; // Nombre del jugador con la máxima puntuación
|
std::string hiScoreName; // Nombre del jugador con la máxima puntuación
|
||||||
@@ -117,6 +119,12 @@ public:
|
|||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setMult2(float mult);
|
void setMult2(float mult);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setContinue1(int score);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setContinue2(int score);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setStage(int stage);
|
void setStage(int stage);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user