Acomodats els estats del jugador

El compte enrrere per a continuar ara ix al acabar la animació de morir
Afegit el estat "entering_name"
This commit is contained in:
2024-09-29 10:40:35 +02:00
parent 945eaa68e7
commit 8ce09d1355
9 changed files with 193 additions and 68 deletions

View File

@@ -1,34 +1,34 @@
#include "game.h"
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_keycode.h> // for SDLK_1, SDLK_2, SDLK_3, SDLK_h
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_R...
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_FOCUS_GAINED, SDL_...
#include <stdlib.h> // for rand
#include <algorithm> // for min
#include <fstream> // for basic_ifstream
#include <iostream> // for char_traits, basic_istream, ifstream
#include "asset.h" // for Asset
#include "background.h" // for Background
#include "balloon.h" // for Balloon, BALLOON_SPEED_1, BALLOON_...
#include "bullet.h" // for Bullet, BULLET_LEFT, BULLET_RIGHT
#include "enemy_formations.h" // for stage_t, EnemyFormations, enemyIni...
#include "explosions.h" // for Explosions
#include "fade.h" // for Fade, FADE_RANDOM_SQUARE, FADE_VEN...
#include "input.h" // for inputs_e, Input, INPUT_DO_NOT_ALLO...
#include "item.h" // for Item, ITEM_COFFEE_MACHINE, ITEM_CLOCK
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_L...
#include "lang.h" // for getText
#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 "scoreboard.h" // for Scoreboard, scoreboard_modes_e
#include "screen.h" // for Screen
#include "smart_sprite.h" // for SmartSprite
#include "text.h" // for Text, TXT_CENTER
#include "texture.h" // for Texture
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_keycode.h> // for SDLK_1, SDLK_2, SDLK_3, SDLK_h
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_R...
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_FOCUS_GAINED, SDL_...
#include <stdlib.h> // for rand
#include <algorithm> // for min
#include <fstream> // for basic_ifstream
#include <iostream> // for char_traits, basic_istream, ifstream
#include "asset.h" // for Asset
#include "background.h" // for Background
#include "balloon.h" // for Balloon, BALLOON_SPEED_1, BALLOON_...
#include "bullet.h" // for Bullet, BULLET_LEFT, BULLET_RIGHT
#include "enemy_formations.h" // for stage_t, EnemyFormations, enemyIni...
#include "explosions.h" // for Explosions
#include "fade.h" // for Fade, FADE_RANDOM_SQUARE, FADE_VEN...
#include "input.h" // for inputs_e, Input, INPUT_DO_NOT_ALLO...
#include "item.h" // for Item, ITEM_COFFEE_MACHINE, ITEM_CLOCK
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_L...
#include "lang.h" // for getText
#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 "scoreboard.h" // for Scoreboard, scoreboard_modes_e
#include "screen.h" // for Screen
#include "smart_sprite.h" // for SmartSprite
#include "text.h" // for Text, TXT_CENTER
#include "texture.h" // for Texture
struct JA_Music_t;
struct JA_Sound_t;
@@ -1744,11 +1744,10 @@ void Game::killPlayer(Player *player)
JA_PlaySound(playerCollisionSound);
screen->shake();
JA_PlaySound(coffeeOutSound);
demo.enabled ? player->setStatusPlaying(PLAYER_STATUS_WAITING) : player->setStatusPlaying(PLAYER_STATUS_CONTINUE);
player->setStatusPlaying(PLAYER_STATUS_DYING);
if (!demo.enabled)
{ // En el modo DEMO ni se para la musica ni se añade la puntuación a la tabla
allPlayersAreWaiting() ? JA_StopMusic() : JA_ResumeMusic();
addScoreToScoreBoard(player->getName(), player->getScore());
allPlayersAreNotPlaying() ? JA_StopMusic() : JA_ResumeMusic();
}
}
}
@@ -2584,6 +2583,18 @@ bool Game::allPlayersAreWaiting()
return success;
}
// Comprueba si todos los jugadores han terminado de jugar
bool Game::allPlayersAreNotPlaying()
{
bool success = true;
for (auto player : players)
{
success &= !player->isPlaying();
}
return success;
}
// Comprueba los eventos que hay en cola
void Game::checkEvents()
{
@@ -2809,12 +2820,33 @@ void Game::checkPlayersStatusPlaying()
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_GAME_OVER);
break;
case PLAYER_STATUS_ENTERING_NAME:
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_ENTER_NAME);
break;
case PLAYER_STATUS_DYING:
break;
case PLAYER_STATUS_DIED:
{
const int nextPlayerStatus = IsEligibleForHighScore(player->getScore()) ? PLAYER_STATUS_ENTERING_NAME : PLAYER_STATUS_CONTINUE;
demo.enabled ? player->setStatusPlaying(PLAYER_STATUS_WAITING) : player->setStatusPlaying(nextPlayerStatus);
// addScoreToScoreBoard(player->getName(), player->getScore());
break;
}
default:
break;
}
}
}
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
bool Game::IsEligibleForHighScore(int score)
{
return score > options.game.hiScoreTable.back().score;
}
// Obtiene un jugador a partir de su "id"
Player *Game::getPlayer(int id)
{