forked from jaildesigner-jailgames/jaildoctors_dilemma
Añadida Tu peor pesadilla a la pantalla de Game Over
This commit is contained in:
@@ -81,6 +81,14 @@ struct online_t
|
|||||||
int score; // Puntuación almacenada online
|
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
|
// Estructura con todas las opciones de configuración del programa
|
||||||
struct options_t
|
struct options_t
|
||||||
{
|
{
|
||||||
@@ -97,8 +105,7 @@ struct options_t
|
|||||||
palette_e palette; // Paleta de colores a usar en el juego
|
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
|
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||||
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
||||||
int rooms; // Cantidad de habitaciones visitadas
|
op_stats_t stats; // Datos con las estadisticas de juego
|
||||||
int items; // Cantidad de items obtenidos
|
|
||||||
online_t online; // Datos del servicio online
|
online_t online; // Datos del servicio online
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -156,8 +156,8 @@ void Director::initOptions()
|
|||||||
options->cheat.invincible = false;
|
options->cheat.invincible = false;
|
||||||
options->cheat.jailEnabled = false;
|
options->cheat.jailEnabled = false;
|
||||||
options->cheat.altSkin = false;
|
options->cheat.altSkin = false;
|
||||||
options->rooms = 0;
|
options->stats.rooms = 0;
|
||||||
options->items = 0;
|
options->stats.items = 0;
|
||||||
|
|
||||||
// Online
|
// Online
|
||||||
options->online.enabled = false;
|
options->online.enabled = false;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
// Inicializa el resto de variables
|
// Inicializa el resto de variables
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
board.lives = 9;
|
board.lives = 0;
|
||||||
board.items = 0;
|
board.items = 0;
|
||||||
board.rooms = 1;
|
board.rooms = 1;
|
||||||
board.music = true;
|
board.music = true;
|
||||||
@@ -348,7 +348,7 @@ bool Game::changeRoom(std::string file)
|
|||||||
{
|
{
|
||||||
// Incrementa el contador de habitaciones visitadas
|
// Incrementa el contador de habitaciones visitadas
|
||||||
board.rooms++;
|
board.rooms++;
|
||||||
options->rooms = board.rooms;
|
options->stats.rooms = board.rooms;
|
||||||
|
|
||||||
// Actualiza las estadisticas
|
// Actualiza las estadisticas
|
||||||
stats->addVisit(room->getName());
|
stats->addVisit(room->getName());
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
|
|||||||
iniFade = 310;
|
iniFade = 310;
|
||||||
fadeLenght = 20;
|
fadeLenght = 20;
|
||||||
playerSprite->setPosX(GAMECANVAS_CENTER_X + 10);
|
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->setPosX(GAMECANVAS_CENTER_X - tvSprite->getAnimationClip(0, 0).w - 10);
|
||||||
tvSprite->setPosY(GAMECANVAS_CENTER_Y - 10);
|
tvSprite->setPosY(30);
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
// Inicializa el vector de colores
|
||||||
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
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
|
// Dibuja el final en pantalla
|
||||||
void GameOver::render()
|
void GameOver::render()
|
||||||
{
|
{
|
||||||
|
const int y = 32;
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
screen->start();
|
||||||
|
|
||||||
@@ -89,16 +91,22 @@ void GameOver::render()
|
|||||||
screen->clean();
|
screen->clean();
|
||||||
|
|
||||||
// Escribe el texto de GAME OVER
|
// 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
|
// Dibuja los sprites
|
||||||
|
playerSprite->setPosY(y + 30);
|
||||||
|
tvSprite->setPosY(y + 30);
|
||||||
renderSprites();
|
renderSprites();
|
||||||
|
|
||||||
// Escribe el texto con las habitaciones y los items
|
// 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 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->rooms / 100) + std::to_string((options->rooms % 100) / 10) + std::to_string(options->rooms % 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, GAMECANVAS_CENTER_Y + 40, "ITEMS: " + itemsTxt, 1, color);
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 80, "ITEMS: " + itemsTxt, 1, color);
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y + 55, "ROOMS: " + roomsTxt, 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
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
screen->blit();
|
||||||
|
|||||||
@@ -824,7 +824,7 @@ bool Room::itemCollision(SDL_Rect &rect)
|
|||||||
items.erase(items.begin() + i);
|
items.erase(items.begin() + i);
|
||||||
JA_PlaySound(itemSound);
|
JA_PlaySound(itemSound);
|
||||||
*itemsPicked = *itemsPicked + 1;
|
*itemsPicked = *itemsPicked + 1;
|
||||||
options->items = *itemsPicked;
|
options->stats.items = *itemsPicked;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ Stats::Stats(std::string file, options_t *options)
|
|||||||
// Destructor
|
// Destructor
|
||||||
Stats::~Stats()
|
Stats::~Stats()
|
||||||
{
|
{
|
||||||
|
checkWorstNightmare();
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
saveToFile();
|
saveToFile();
|
||||||
#endif
|
#endif
|
||||||
@@ -135,7 +136,7 @@ bool Stats::loadFromFile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga las estadisticas desde un servidor
|
// Carga las estadisticas desde un servidor
|
||||||
bool Stats::loadFromServer()
|
void Stats::loadFromServer()
|
||||||
{
|
{
|
||||||
if (options->online.enabled)
|
if (options->online.enabled)
|
||||||
{
|
{
|
||||||
@@ -180,4 +181,18 @@ void Stats::saveToServer()
|
|||||||
jscore::setUserData(options->online.gameID, options->online.jailerID, data);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,10 +19,10 @@ class Stats
|
|||||||
private:
|
private:
|
||||||
// Punteros y objetos
|
// Punteros y objetos
|
||||||
options_t *options;
|
options_t *options;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<stats_t> list; // Lista con las estadisticas por habitación
|
std::vector<stats_t> list; // Lista con las estadisticas por habitación
|
||||||
std::string filePath; // Fichero con las estadísticas
|
std::string filePath; // Fichero con las estadísticas
|
||||||
|
|
||||||
// Busca una entrada en la lista por nombre
|
// Busca una entrada en la lista por nombre
|
||||||
int findByName(std::string name);
|
int findByName(std::string name);
|
||||||
@@ -31,7 +31,7 @@ private:
|
|||||||
bool loadFromFile();
|
bool loadFromFile();
|
||||||
|
|
||||||
// Carga las estadisticas desde un servidor
|
// Carga las estadisticas desde un servidor
|
||||||
bool loadFromServer();
|
void loadFromServer();
|
||||||
|
|
||||||
// Guarda las estadisticas en un fichero
|
// Guarda las estadisticas en un fichero
|
||||||
void saveToFile();
|
void saveToFile();
|
||||||
@@ -39,6 +39,9 @@ private:
|
|||||||
// Guarda las estadisticas en un servidor
|
// Guarda las estadisticas en un servidor
|
||||||
void saveToServer();
|
void saveToServer();
|
||||||
|
|
||||||
|
// Calcula cual es la habitación con más muertes
|
||||||
|
void checkWorstNightmare();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Stats(std::string file, options_t *options);
|
Stats(std::string file, options_t *options);
|
||||||
|
|||||||
Reference in New Issue
Block a user