Colocados los disparadores de los logros en su sitio

This commit is contained in:
2022-12-29 14:08:42 +01:00
parent f590101047
commit c0d4eddde7
7 changed files with 117 additions and 9 deletions

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -84,6 +84,9 @@ public:
// Quita el modo pausa del marcador
void resume();
// Devuelve la cantidad de minutos de juego transcurridos
int getMinutes();
};
#endif