Añadida Tu peor pesadilla a la pantalla de Game Over

This commit is contained in:
2022-11-18 16:07:33 +01:00
parent c35be7d21c
commit 2665b93b70
7 changed files with 52 additions and 19 deletions

View File

@@ -81,6 +81,14 @@ struct online_t
int score; // Puntuación almacenada online
};
// Estructura para almacenar estadísticas
struct op_stats_t
{
int rooms; // Cantidad de habitaciones visitadas
int items; // Cantidad de items obtenidos
std::string worstNightmare; // Habitación con más muertes acumuladas
};
// Estructura con todas las opciones de configuración del programa
struct options_t
{
@@ -97,8 +105,7 @@ struct options_t
palette_e palette; // Paleta de colores a usar en el juego
bool console; // Indica si ha de mostrar información por la consola de texto
cheat_t cheat; // Contiene trucos y ventajas para el juego
int rooms; // Cantidad de habitaciones visitadas
int items; // Cantidad de items obtenidos
op_stats_t stats; // Datos con las estadisticas de juego
online_t online; // Datos del servicio online
};

View File

@@ -156,8 +156,8 @@ void Director::initOptions()
options->cheat.invincible = false;
options->cheat.jailEnabled = false;
options->cheat.altSkin = false;
options->rooms = 0;
options->items = 0;
options->stats.rooms = 0;
options->stats.items = 0;
// Online
options->online.enabled = false;

View File

@@ -46,7 +46,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
// Inicializa el resto de variables
ticks = 0;
ticksSpeed = 15;
board.lives = 9;
board.lives = 0;
board.items = 0;
board.rooms = 1;
board.music = true;
@@ -348,7 +348,7 @@ bool Game::changeRoom(std::string file)
{
// Incrementa el contador de habitaciones visitadas
board.rooms++;
options->rooms = board.rooms;
options->stats.rooms = board.rooms;
// Actualiza las estadisticas
stats->addVisit(room->getName());

View File

@@ -28,9 +28,9 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
iniFade = 310;
fadeLenght = 20;
playerSprite->setPosX(GAMECANVAS_CENTER_X + 10);
playerSprite->setPosY(GAMECANVAS_CENTER_Y - 10);
playerSprite->setPosY(30);
tvSprite->setPosX(GAMECANVAS_CENTER_X - tvSprite->getAnimationClip(0, 0).w - 10);
tvSprite->setPosY(GAMECANVAS_CENTER_Y - 10);
tvSprite->setPosY(30);
// Inicializa el vector de colores
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
@@ -82,6 +82,8 @@ void GameOver::update()
// Dibuja el final en pantalla
void GameOver::render()
{
const int y = 32;
// Prepara para empezar a dibujar en la textura de juego
screen->start();
@@ -89,16 +91,22 @@ void GameOver::render()
screen->clean();
// Escribe el texto de GAME OVER
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y - 40, "G A M E O V E R", 1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y, "G A M E O V E R", 1, color);
// Dibuja los sprites
playerSprite->setPosY(y + 30);
tvSprite->setPosY(y + 30);
renderSprites();
// Escribe el texto con las habitaciones y los items
const std::string itemsTxt = std::to_string(options->items / 100) + std::to_string((options->items % 100) / 10) + std::to_string(options->items % 10);
const std::string roomsTxt = std::to_string(options->rooms / 100) + std::to_string((options->rooms % 100) / 10) + std::to_string(options->rooms % 10);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y + 40, "ITEMS: " + itemsTxt, 1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y + 55, "ROOMS: " + roomsTxt, 1, color);
const std::string itemsTxt = std::to_string(options->stats.items / 100) + std::to_string((options->stats.items % 100) / 10) + std::to_string(options->stats.items % 10);
const std::string roomsTxt = std::to_string(options->stats.rooms / 100) + std::to_string((options->stats.rooms % 100) / 10) + std::to_string(options->stats.rooms % 10);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 80, "ITEMS: " + itemsTxt, 1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 90, "ROOMS: " + roomsTxt, 1, color);
// Escribe el texto con "Tu peor pesadilla"
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 110, "YOUR WORST NIGHTMARE IS", 1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 120, options->stats.worstNightmare, 1, color);
// Vuelca el contenido del renderizador en pantalla
screen->blit();

View File

@@ -824,7 +824,7 @@ bool Room::itemCollision(SDL_Rect &rect)
items.erase(items.begin() + i);
JA_PlaySound(itemSound);
*itemsPicked = *itemsPicked + 1;
options->items = *itemsPicked;
options->stats.items = *itemsPicked;
return true;
}
}

View File

@@ -16,6 +16,7 @@ Stats::Stats(std::string file, options_t *options)
// Destructor
Stats::~Stats()
{
checkWorstNightmare();
#ifndef DEBUG
saveToFile();
#endif
@@ -135,7 +136,7 @@ bool Stats::loadFromFile()
}
// Carga las estadisticas desde un servidor
bool Stats::loadFromServer()
void Stats::loadFromServer()
{
if (options->online.enabled)
{
@@ -180,4 +181,18 @@ void Stats::saveToServer()
jscore::setUserData(options->online.gameID, options->online.jailerID, data);
}
}
}
// Calcula cual es la habitación con más muertes
void Stats::checkWorstNightmare()
{
int deaths = 0;
for (auto item : list)
{
if (item.died > deaths)
{
deaths = item.died;
options->stats.worstNightmare = item.name;
}
}
}

View File

@@ -19,10 +19,10 @@ class Stats
private:
// Punteros y objetos
options_t *options;
// Variables
std::vector<stats_t> list; // Lista con las estadisticas por habitación
std::string filePath; // Fichero con las estadísticas
std::vector<stats_t> list; // Lista con las estadisticas por habitación
std::string filePath; // Fichero con las estadísticas
// Busca una entrada en la lista por nombre
int findByName(std::string name);
@@ -31,7 +31,7 @@ private:
bool loadFromFile();
// Carga las estadisticas desde un servidor
bool loadFromServer();
void loadFromServer();
// Guarda las estadisticas en un fichero
void saveToFile();
@@ -39,6 +39,9 @@ private:
// Guarda las estadisticas en un servidor
void saveToServer();
// Calcula cual es la habitación con más muertes
void checkWorstNightmare();
public:
// Constructor
Stats(std::string file, options_t *options);