From 2665b93b70834e7a1801110012a4b507dd9ad05d Mon Sep 17 00:00:00 2001 From: Sergio Valor Martinez Date: Fri, 18 Nov 2022 16:07:33 +0100 Subject: [PATCH] =?UTF-8?q?A=C3=B1adida=20Tu=20peor=20pesadilla=20a=20la?= =?UTF-8?q?=20pantalla=20de=20Game=20Over?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/common/utils.h | 11 +++++++++-- source/director.cpp | 4 ++-- source/game.cpp | 4 ++-- source/game_over.cpp | 22 +++++++++++++++------- source/room.cpp | 2 +- source/stats.cpp | 17 ++++++++++++++++- source/stats.h | 11 +++++++---- 7 files changed, 52 insertions(+), 19 deletions(-) diff --git a/source/common/utils.h b/source/common/utils.h index f9d7aea..097a4d7 100644 --- a/source/common/utils.h +++ b/source/common/utils.h @@ -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 }; diff --git a/source/director.cpp b/source/director.cpp index c07e348..31f42cf 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -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; diff --git a/source/game.cpp b/source/game.cpp index 0c2d89e..deae981 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -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()); diff --git a/source/game_over.cpp b/source/game_over.cpp index 8d47bf8..9c5b2f2 100644 --- a/source/game_over.cpp +++ b/source/game_over.cpp @@ -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 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(); diff --git a/source/room.cpp b/source/room.cpp index 99ecb49..8e98824 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -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; } } diff --git a/source/stats.cpp b/source/stats.cpp index 2ec6fba..4b4eb31 100644 --- a/source/stats.cpp +++ b/source/stats.cpp @@ -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; + } + } } \ No newline at end of file diff --git a/source/stats.h b/source/stats.h index 035b568..495a52b 100644 --- a/source/stats.h +++ b/source/stats.h @@ -19,10 +19,10 @@ class Stats private: // Punteros y objetos options_t *options; - + // Variables - std::vector list; // Lista con las estadisticas por habitación - std::string filePath; // Fichero con las estadísticas + std::vector 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);