enmig del berenjenal d'afegir estats nous al jugador

This commit is contained in:
2024-08-14 11:59:16 +02:00
parent c246472098
commit 90706d5d0c
4 changed files with 129 additions and 98 deletions

View File

@@ -112,8 +112,8 @@ void Game::init(int playerID)
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[1], playerAnimations);
players.push_back(player2);
// Habilita el jugador seleccionado
players[playerID]->enable(true);
// Cambia el estado del jugador seleccionado
players[playerID]->setStatusPlaying(PLAYER_STATUS_PLAYING);
// Como es el principio del juego, empieza sin inmunidad
players[playerID]->setInvulnerable(false);
@@ -148,11 +148,11 @@ void Game::init(int playerID)
// Variables para el marcador
scoreboard->setPos({param->scoreboard.x, param->scoreboard.y, param->scoreboard.w, param->scoreboard.h});
if (!players[0]->isEnabled())
if (players[0]->isWaiting())
{
scoreboard->setMode(SCOREBOARD_LEFT_PANEL, SCOREBOARD_MODE_GAME_OVER);
}
if (!players[1]->isEnabled())
if (!players[1]->isWaiting())
{
scoreboard->setMode(SCOREBOARD_RIGHT_PANEL, SCOREBOARD_MODE_GAME_OVER);
}
@@ -169,7 +169,7 @@ void Game::init(int playerID)
menaceThreshold = 0;
hiScoreAchieved = false;
stageBitmapCounter = STAGE_COUNTER;
deathCounter = DEATH_COUNTER;
gameOverCounter = DEATH_COUNTER;
timeStopped = false;
timeStoppedCounter = 0;
counter = 0;
@@ -210,7 +210,7 @@ void Game::init(int playerID)
if (rand() % 2 == 0)
{
const int otherPlayer = playerID == 1 ? 1 : 0;
players[otherPlayer]->enable(true);
players[otherPlayer]->setStatusPlaying(PLAYER_STATUS_PLAYING);
}
for (auto player : players)
@@ -931,18 +931,18 @@ void Game::updatePlayers()
{
for (auto player : players)
{
if (player->isEnabled())
if (player->isPlaying())
{
player->update();
// Comprueba la colisión entre el jugador y los globos
if (checkPlayerBalloonCollision(player))
{
if (player->isAlive())
if (player->isPlaying())
{
killPlayer(player);
if (demo.enabled && allPlayersAreDead())
if (demo.enabled && allPlayersAreWaiting())
{
fade->setType(FADE_RANDOM_SQUARE);
fade->activate();
@@ -961,7 +961,7 @@ void Game::renderPlayers()
{
for (auto player : players)
{
if (player->isEnabled())
if (!player->isWaiting())
{
player->render();
#ifdef DEBUG
@@ -991,7 +991,7 @@ void Game::updateStage()
menaceCurrent = 255; // Sube el nivel de amenaza para que no cree mas globos
for (auto player : players)
{ // Añade un millon de puntos a los jugadores que queden vivos
if (player->isAlive())
if (player->isPlaying())
{
player->addScore(1000000);
}
@@ -1023,17 +1023,17 @@ void Game::updateStage()
}
}
// Actualiza el estado de muerte
void Game::updateDeath()
// Actualiza el estado de fin de la partida
void Game::updateGameOver()
{
// Comprueba si todos los jugadores estan muertos
if (allPlayersAreDead())
if (allPlayersAreWaiting())
{
if (deathCounter > 0)
if (gameOverCounter > 0)
{
deathCounter--;
gameOverCounter--;
if ((deathCounter == 250) || (deathCounter == 200) || (deathCounter == 180) || (deathCounter == 120) || (deathCounter == 60))
if ((gameOverCounter == 250) || (gameOverCounter == 200) || (gameOverCounter == 180) || (gameOverCounter == 120) || (gameOverCounter == 60))
{
// Hace sonar aleatoriamente uno de los 4 sonidos de burbujas
const int index = rand() % 4;
@@ -1041,7 +1041,7 @@ void Game::updateDeath()
JA_PlaySound(sound[index], 0);
}
if (deathCounter == 150)
if (gameOverCounter == 150)
{
fade->activate();
}
@@ -1049,7 +1049,6 @@ void Game::updateDeath()
if (fade->hasEnded())
{
// section->subsection = SUBSECTION_GAME_GAMEOVER;
section->name = SECTION_PROG_HI_SCORE_TABLE;
}
}
@@ -1430,7 +1429,7 @@ bool Game::checkPlayerBalloonCollision(Player *player)
// Comprueba la colisión entre el jugador y los items
void Game::checkPlayerItemCollision(Player *player)
{
if (!player->isAlive())
if (!player->isPlaying())
{
return;
}
@@ -1797,8 +1796,8 @@ void Game::renderSmartSprites()
// Acciones a realizar cuando el jugador muere
void Game::killPlayer(Player *player)
{
if (!player->isEnabled() || player->isInvulnerable())
{ // Si no está habilitado o tiene inmunidad, no hace nada
if (!player->isPlaying() || player->isInvulnerable())
{ // Si no está jugando o tiene inmunidad, no hace nada
return;
}
@@ -1820,10 +1819,10 @@ void Game::killPlayer(Player *player)
JA_PlaySound(playerCollisionSound);
screen->shake();
JA_PlaySound(coffeeOutSound);
player->setAlive(false);
demo.enabled ? player->setStatusPlaying(PLAYER_STATUS_WAITING) : player->setStatusPlaying(PLAYER_STATUS_CONTINUE);
if (!demo.enabled)
{ // En el modo DEMO ni se para la musica ni se añade la puntuación a la tabla
allPlayersAreDead() ? JA_StopMusic() : JA_ResumeMusic();
allPlayersAreWaiting() ? JA_StopMusic() : JA_ResumeMusic();
addScoreToScoreBoard("Sergio", player->getScore());
}
}
@@ -1990,7 +1989,7 @@ void Game::update()
updateStage();
// Actualiza el estado de muerte
updateDeath();
updateGameOver();
// Actualiza los SmartSprites
updateSmartSprites();
@@ -2104,7 +2103,7 @@ void Game::render()
#ifdef DEBUG
//text->write(0, 0, "P1 ALIVE: " + boolToString(players[0]->isAlive()));
//text->write(0, 10, "P2 ALIVE: " + boolToString(players[1]->isAlive()));
//text->write(0, 20, "ALL DEAD: " + boolToString(allPlayersAreDead()));
//text->write(0, 20, "ALL DEAD: " + boolToString(allPlayersAreWaiting()));
#endif
// Dibuja el fade
@@ -2180,7 +2179,7 @@ void Game::checkInput()
int i = 0;
for (auto player : players)
{
if (player->isAlive() && player->isEnabled())
if (player->isPlaying())
{
// Comprueba direcciones
if (demo.dataFile[i][demo.counter].left == 1)
@@ -2256,7 +2255,7 @@ void Game::checkInput()
for (auto player : players)
{
const bool autofire = player->isPowerUp() || options->game.autofire;
if (player->isAlive() && player->isEnabled())
if (player->isPlaying())
{
// Input a la izquierda
if (input->checkInput(input_left, ALLOW_REPEAT, options->controller[i].deviceType, options->controller[i].index))
@@ -2350,7 +2349,7 @@ void Game::checkInput()
{
if (input->checkInput(input_start, ALLOW_REPEAT, options->controller[i].deviceType, options->controller[i].index))
{
player->enable(true);
player->setStatusPlaying(PLAYER_STATUS_PLAYING);
}
i++;
}
@@ -2454,8 +2453,8 @@ void Game::checkMusicStatus()
// Si la música no está sonando
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
// Si se ha completado el juego o los jugadores estan mujertos, detiene la música
gameCompleted || allPlayersAreDead() ? JA_StopMusic() : JA_PlayMusic(music);
// Si se ha completado el juego o los jugadores han terminado, detiene la música
gameCompleted || allPlayersAreWaiting() ? JA_StopMusic() : JA_PlayMusic(music);
}
}
@@ -2629,14 +2628,13 @@ void Game::updateHelper()
}
}
// Comprueba si todos los jugadores han muerto
bool Game::allPlayersAreDead()
// Comprueba si todos los jugadores han terminado de jugar
bool Game::allPlayersAreWaiting()
{
bool success = true;
bool success = false;
for (auto player : players)
{
// success &= (!player->isAlive() || !player->isEnabled());
success &= !player->isAlive();
success |= player->isWaiting();
}
return success;