From c0d4eddde7293767600a89d977a869d1783335d8 Mon Sep 17 00:00:00 2001 From: Sergio Valor Martinez Date: Thu, 29 Dec 2022 14:08:42 +0100 Subject: [PATCH] Colocados los disparadores de los logros en su sitio --- source/cheevos.cpp | 25 +++++++++++--- source/cheevos.h | 8 +++-- source/director.cpp | 2 +- source/game.cpp | 79 +++++++++++++++++++++++++++++++++++++++++-- source/game.h | 3 ++ source/scoreboard.cpp | 6 ++++ source/scoreboard.h | 3 ++ 7 files changed, 117 insertions(+), 9 deletions(-) diff --git a/source/cheevos.cpp b/source/cheevos.cpp index fa864cf..3937201 100644 --- a/source/cheevos.cpp +++ b/source/cheevos.cpp @@ -23,6 +23,7 @@ void Cheevos::init() cheevos_t c; c.completed = false; c.valid = true; + c.icon = 2; c.id = 1; c.caption = "SHINY THINGS"; @@ -86,7 +87,7 @@ void Cheevos::init() } // Busca un logro por id y devuelve el indice -int Cheevos::findCheevo(int id) +int Cheevos::find(int id) { for (int i = 0; i < (int)cheevos.size(); ++i) { @@ -100,18 +101,34 @@ int Cheevos::findCheevo(int id) } // Desbloquea un logro -void Cheevos::unlockCheevo(int id) +void Cheevos::unlock(int id) { - const int index = findCheevo(id); + const int index = find(id); if (index == -1) { return; } + if (!cheevos[index].valid) + { + return; + } + if (!cheevos[index].completed) { cheevos[index].completed = true; - screen->showNotification("ACHIEVEMENT UNLOCKED!", cheevos[index].caption); + screen->showNotification("ACHIEVEMENT UNLOCKED!", cheevos[index].caption, cheevos[index].icon); } +} + +// Invalida un logro +void Cheevos::invalidate(int id) +{ + const int index = find(id); + if (index == -1) + { + return; + } + cheevos[index].valid = false; } \ No newline at end of file diff --git a/source/cheevos.h b/source/cheevos.h index b42f48e..e25a88b 100644 --- a/source/cheevos.h +++ b/source/cheevos.h @@ -13,6 +13,7 @@ struct cheevos_t int id; // Identificador del logro std::string caption; // Texto con el nombre del logro std::string description; // Texto que describe el logro + int icon; // Indice del icono a utilizar en la notificación bool completed; // Indica si se ha obtenido el logro bool valid; // Indica si se puede obtener el logro }; @@ -31,7 +32,7 @@ private: void init(); // Busca un logro por id y devuelve el indice - int findCheevo(int id); + int find(int id); public: // Constructor @@ -41,7 +42,10 @@ public: ~Cheevos(); // Desbloquea un logro - void unlockCheevo(int id); + void unlock(int id); + + // Invalida un logro + void invalidate(int id); }; #endif diff --git a/source/director.cpp b/source/director.cpp index 810ea63..fe29979 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -19,7 +19,7 @@ Director::Director(int argc, char *argv[]) section->subsection = SUBSECTION_LOGO_TO_INTRO; #ifdef DEBUG - section->name = SECTION_PROG_LOGO; + section->name = SECTION_PROG_GAME; #endif // Crea e inicializa las opciones del programa diff --git a/source/game.cpp b/source/game.cpp index 10eb5f5..1bc3770 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -467,6 +467,9 @@ void Game::killPlayer() // Actualiza las estadisticas stats->addDeath(room->getName()); + // Invalida el logro de pasarse el juego sin morir + cheevos->invalidate(11); + // Destruye la habitacion y el jugador delete room; delete this->player; @@ -583,6 +586,9 @@ bool Game::checkEndGame() if (haveTheItems && isOnTheRoom && isOnTheDoor) { + // Comprueba los logros de completar el juego + checkEndGameCheevos(); + section->name = SECTION_PROG_ENDING; return true; } @@ -655,6 +661,14 @@ void Game::checkRestoringJail() board.lives++; JA_PlaySound(deathSound); } + + // Invalida el logro de completar el juego sin entrar a la jail + const bool haveTheItems = board.items >= int(totalItems * 0.9f) || options->cheat.jailEnabled; // Con mas del 90% de los items recogidos + if (!haveTheItems) + { + cheevos->invalidate(9); + } + } // Inicializa el diccionario de las estadísticas @@ -692,8 +706,69 @@ void Game::fillRoomNameTexture() // Comprueba algunos logros void Game::checkSomeCheevos() { - if (board.items == 1) + // Logros sobre la cantidad de items + if (board.items == totalItems) { - cheevos->unlockCheevo(2); + cheevos->unlock(4); + cheevos->unlock(3); + cheevos->unlock(2); + cheevos->unlock(1); + } + else if (board.items >= totalItems * 0.75f) + { + cheevos->unlock(3); + cheevos->unlock(2); + cheevos->unlock(1); + } + else if (board.items >= totalItems * 0.5f) + { + cheevos->unlock(2); + cheevos->unlock(1); + } + else if (board.items >= totalItems * 0.25f) + { + cheevos->unlock(1); + } + + // Logros sobre las habitaciones visitadas + if (board.rooms >= 60) + { + cheevos->unlock(7); + cheevos->unlock(6); + cheevos->unlock(5); + } + else if (board.rooms >= 40) + { + cheevos->unlock(6); + cheevos->unlock(5); + } + else if (board.rooms >= 20) + { + cheevos->unlock(5); + } +} + +// Comprueba los logros de completar el juego +void Game::checkEndGameCheevos() +{ + // "Complete the game" + cheevos->unlock(8); + + // "Complete the game without entering the jail" + cheevos->unlock(9); + + // "Complete the game with all items" + if (board.items == totalItems) + { + cheevos->unlock(10); + } + + // "Complete the game without dying" + cheevos->unlock(11); + + // "Complete the game in under 30 minutes" + if (scoreboard->getMinutes() < 30) + { + cheevos->unlock(12); } } \ No newline at end of file diff --git a/source/game.h b/source/game.h index 33cfa49..8a6058e 100644 --- a/source/game.h +++ b/source/game.h @@ -143,6 +143,9 @@ private: // Comprueba algunos logros void checkSomeCheevos(); + // Comprueba los logros de completar el juego + void checkEndGameCheevos(); + public: // Constructor Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, section_t *section, Debug *debug); diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 043d5b5..4af9d99 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -169,4 +169,10 @@ void ScoreBoard::updateItemsColor() { itemsColor = stringToColor(options->palette, "magenta"); } +} + +// Devuelve la cantidad de minutos de juego transcurridos +int ScoreBoard::getMinutes() +{ + return getTime().minutes; } \ No newline at end of file diff --git a/source/scoreboard.h b/source/scoreboard.h index 7e34c48..742d028 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -84,6 +84,9 @@ public: // Quita el modo pausa del marcador void resume(); + + // Devuelve la cantidad de minutos de juego transcurridos + int getMinutes(); }; #endif