forked from jaildesigner-jailgames/jaildoctors_dilemma
Solventat bug amb el punter a ScoreboardData
This commit is contained in:
@@ -36,32 +36,33 @@ Game::Game()
|
||||
cheevos_(Cheevos::get())
|
||||
{
|
||||
// Inicia algunas variables
|
||||
board_.ini_clock = SDL_GetTicks();
|
||||
board_ = std::make_shared<ScoreboardData>();
|
||||
board_->ini_clock = SDL_GetTicks();
|
||||
#ifdef DEBUG
|
||||
current_room_ = "03.room";
|
||||
const int x = 25;
|
||||
const int y = 13;
|
||||
spawn_point_ = PlayerSpawn(x * 8, y * 8, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL);
|
||||
constexpr int X = 25;
|
||||
constexpr int Y = 13;
|
||||
spawn_point_ = PlayerSpawn(X * 8, Y * 8, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL);
|
||||
debug_->setEnabled(false);
|
||||
#else
|
||||
current_room_ = "03.room";
|
||||
const int x = 25;
|
||||
const int y = 13;
|
||||
spawn_point_ = PlayerSpawn(x * 8, y * 8, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL);
|
||||
constexpr int X = 25;
|
||||
constexpr int Y = 13;
|
||||
spawn_point_ = PlayerSpawn(X * 8, Y * 8, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL);
|
||||
#endif
|
||||
|
||||
// Crea los objetos
|
||||
ItemTracker::init();
|
||||
scoreboard_ = std::make_shared<Scoreboard>(&board_);
|
||||
scoreboard_ = std::make_shared<Scoreboard>(board_);
|
||||
room_tracker_ = std::make_shared<RoomTracker>();
|
||||
room_ = std::make_shared<Room>(resource_->getRoom(current_room_), &board_.items, false);
|
||||
const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
|
||||
const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
||||
const PlayerData player(spawn_point_, playerPNG, playerANI, room_);
|
||||
room_ = std::make_shared<Room>(resource_->getRoom(current_room_), board_);
|
||||
std::string player_texture = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
|
||||
std::string player_animations = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
||||
const PlayerData player(spawn_point_, player_texture, player_animations, room_);
|
||||
player_ = std::make_shared<Player>(player);
|
||||
text_ = resource_->getText("smb2");
|
||||
music_ = resource_->getMusic("game.ogg");
|
||||
death_sound_ = JA_LoadSound(asset_->get("death.wav").c_str());
|
||||
death_sound_ = resource_->getSound("death.wav");
|
||||
stats_ = std::make_shared<Stats>(asset_->get("stats.csv"), asset_->get("stats_buffer.csv"));
|
||||
|
||||
// Crea la textura para poner el nombre de la habitación
|
||||
@@ -85,14 +86,14 @@ Game::Game()
|
||||
|
||||
// Inicializa el resto de variables
|
||||
ticks_ = 0;
|
||||
board_.lives = 9;
|
||||
board_->lives = 9;
|
||||
#ifdef DEBUG
|
||||
board_.lives = 9;
|
||||
board_->lives = 9;
|
||||
#endif
|
||||
board_.items = 0;
|
||||
board_.rooms = 1;
|
||||
board_.music = true;
|
||||
board_.jail_is_open = options.cheats.jail_is_open == Cheat::CheatState::ENABLED;
|
||||
board_->items = 0;
|
||||
board_->rooms = 1;
|
||||
board_->music = true;
|
||||
board_->jail_is_open = options.cheats.jail_is_open == Cheat::CheatState::ENABLED;
|
||||
setScoreBoardColor();
|
||||
room_tracker_->addRoom(current_room_);
|
||||
paused_ = false;
|
||||
@@ -129,8 +130,8 @@ void Game::checkEvents()
|
||||
case SDL_SCANCODE_G:
|
||||
debug_->switchEnabled();
|
||||
options.cheats.invincible = static_cast<Cheat::CheatState>(debug_->getEnabled());
|
||||
board_.music = !debug_->getEnabled();
|
||||
board_.music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
board_->music = !debug_->getEnabled();
|
||||
board_->music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_R:
|
||||
@@ -181,8 +182,8 @@ void Game::checkInput()
|
||||
{
|
||||
if (input_->checkInput(input_toggle_music, REPEAT_FALSE))
|
||||
{
|
||||
board_.music = !board_.music;
|
||||
board_.music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
board_->music = !board_->music;
|
||||
board_->music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
}
|
||||
|
||||
else if (input_->checkInput(input_pause, REPEAT_FALSE))
|
||||
@@ -197,7 +198,7 @@ void Game::checkInput()
|
||||
void Game::run()
|
||||
{
|
||||
JA_PlayMusic(music_);
|
||||
if (!board_.music)
|
||||
if (!board_->music)
|
||||
{
|
||||
JA_PauseMusic();
|
||||
}
|
||||
@@ -335,7 +336,7 @@ bool Game::changeRoom(std::string file)
|
||||
if (asset_->get(file) != "")
|
||||
{
|
||||
// Crea un objeto habitación nuevo a partir del fichero
|
||||
room_ = std::make_shared<Room>(resource_->getRoom(file), &board_.items, board_.jail_is_open);
|
||||
room_ = std::make_shared<Room>(resource_->getRoom(file), board_);
|
||||
|
||||
// Pone el nombre de la habitación en la textura
|
||||
fillRoomNameTexture();
|
||||
@@ -346,8 +347,8 @@ bool Game::changeRoom(std::string file)
|
||||
if (room_tracker_->addRoom(file))
|
||||
{
|
||||
// Incrementa el contador de habitaciones visitadas
|
||||
board_.rooms++;
|
||||
options.stats.rooms = board_.rooms;
|
||||
board_->rooms++;
|
||||
options.stats.rooms = board_->rooms;
|
||||
|
||||
// Actualiza las estadisticas
|
||||
stats_->addVisit(room_->getName());
|
||||
@@ -406,7 +407,7 @@ void Game::checkIfPlayerIsAlive()
|
||||
// Comprueba si ha terminado la partida
|
||||
void Game::checkGameOver()
|
||||
{
|
||||
if (board_.lives < 0 && black_screen_counter_ > 17)
|
||||
if (board_->lives < 0 && black_screen_counter_ > 17)
|
||||
{
|
||||
options.section.section = Section::GAME_OVER;
|
||||
}
|
||||
@@ -423,7 +424,7 @@ void Game::killPlayer()
|
||||
// Resta una vida al jugador
|
||||
if (options.cheats.infinite_lives == Cheat::CheatState::DISABLED)
|
||||
{
|
||||
--board_.lives;
|
||||
--board_->lives;
|
||||
}
|
||||
|
||||
// Actualiza las estadisticas
|
||||
@@ -439,10 +440,10 @@ void Game::killPlayer()
|
||||
setBlackScreen();
|
||||
|
||||
// Crea la nueva habitación y el nuevo jugador
|
||||
room_ = std::make_shared<Room>(resource_->getRoom(current_room_), &board_.items, board_.jail_is_open);
|
||||
const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
|
||||
const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
||||
const PlayerData player(spawn_point_, playerPNG, playerANI, room_);
|
||||
room_ = std::make_shared<Room>(resource_->getRoom(current_room_), board_);
|
||||
std::string player_texture = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
|
||||
std::string player_animations = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
||||
const PlayerData player(spawn_point_, player_texture, player_animations, room_);
|
||||
player_ = std::make_shared<Player>(player);
|
||||
|
||||
// Pone los objetos en pausa mientras esta la habitación en negro
|
||||
@@ -507,19 +508,19 @@ void Game::setScoreBoardColor()
|
||||
const bool isBrightBlack = colorAreEqual(colorBorder, stringToColor(options.video.palette, "bright_black"));
|
||||
|
||||
// Si el color del borde es negro o negro brillante cambia el texto del marcador a blanco
|
||||
board_.color = isBlack || isBrightBlack ? stringToColor(options.video.palette, "white") : colorBorder;
|
||||
board_->color = isBlack || isBrightBlack ? stringToColor(options.video.palette, "white") : colorBorder;
|
||||
}
|
||||
|
||||
// Comprueba si ha finalizado el juego
|
||||
bool Game::checkEndGame()
|
||||
{
|
||||
const bool isOnTheRoom = room_->getName() == "THE JAIL"; // Estar en la habitación que toca
|
||||
const bool haveTheItems = board_.items >= int(total_items_ * 0.9f) || options.cheats.jail_is_open == Cheat::CheatState::ENABLED; // Con mas del 90% de los items recogidos
|
||||
const bool haveTheItems = board_->items >= int(total_items_ * 0.9f) || options.cheats.jail_is_open == Cheat::CheatState::ENABLED; // Con mas del 90% de los items recogidos
|
||||
const bool isOnTheDoor = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
|
||||
|
||||
if (haveTheItems)
|
||||
{
|
||||
board_.jail_is_open = true;
|
||||
board_->jail_is_open = true;
|
||||
}
|
||||
|
||||
if (haveTheItems && isOnTheRoom && isOnTheDoor)
|
||||
@@ -580,7 +581,7 @@ void Game::switchPause()
|
||||
// Da vidas al jugador cuando está en la Jail
|
||||
void Game::checkRestoringJail()
|
||||
{
|
||||
if (room_->getName() != "THE JAIL" || board_.lives == 9)
|
||||
if (room_->getName() != "THE JAIL" || board_->lives == 9)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -596,11 +597,11 @@ void Game::checkRestoringJail()
|
||||
if (counter == 100)
|
||||
{
|
||||
counter = 0;
|
||||
board_.lives++;
|
||||
board_->lives++;
|
||||
JA_PlaySound(death_sound_);
|
||||
|
||||
// Invalida el logro de completar el juego sin entrar a la jail
|
||||
const bool haveTheItems = board_.items >= int(total_items_ * 0.9f);
|
||||
const bool haveTheItems = board_->items >= int(total_items_ * 0.9f);
|
||||
if (!haveTheItems)
|
||||
{
|
||||
cheevos_->invalidate(9);
|
||||
@@ -643,42 +644,42 @@ void Game::fillRoomNameTexture()
|
||||
void Game::checkSomeCheevos()
|
||||
{
|
||||
// Logros sobre la cantidad de items
|
||||
if (board_.items == total_items_)
|
||||
if (board_->items == total_items_)
|
||||
{
|
||||
cheevos_->unlock(4);
|
||||
cheevos_->unlock(3);
|
||||
cheevos_->unlock(2);
|
||||
cheevos_->unlock(1);
|
||||
}
|
||||
else if (board_.items >= total_items_ * 0.75f)
|
||||
else if (board_->items >= total_items_ * 0.75f)
|
||||
{
|
||||
cheevos_->unlock(3);
|
||||
cheevos_->unlock(2);
|
||||
cheevos_->unlock(1);
|
||||
}
|
||||
else if (board_.items >= total_items_ * 0.5f)
|
||||
else if (board_->items >= total_items_ * 0.5f)
|
||||
{
|
||||
cheevos_->unlock(2);
|
||||
cheevos_->unlock(1);
|
||||
}
|
||||
else if (board_.items >= total_items_ * 0.25f)
|
||||
else if (board_->items >= total_items_ * 0.25f)
|
||||
{
|
||||
cheevos_->unlock(1);
|
||||
}
|
||||
|
||||
// Logros sobre las habitaciones visitadas
|
||||
if (board_.rooms >= 60)
|
||||
if (board_->rooms >= 60)
|
||||
{
|
||||
cheevos_->unlock(7);
|
||||
cheevos_->unlock(6);
|
||||
cheevos_->unlock(5);
|
||||
}
|
||||
else if (board_.rooms >= 40)
|
||||
else if (board_->rooms >= 40)
|
||||
{
|
||||
cheevos_->unlock(6);
|
||||
cheevos_->unlock(5);
|
||||
}
|
||||
else if (board_.rooms >= 20)
|
||||
else if (board_->rooms >= 20)
|
||||
{
|
||||
cheevos_->unlock(5);
|
||||
}
|
||||
@@ -694,7 +695,7 @@ void Game::checkEndGameCheevos()
|
||||
cheevos_->unlock(9);
|
||||
|
||||
// "Complete the game with all items"
|
||||
if (board_.items == total_items_)
|
||||
if (board_->items == total_items_)
|
||||
{
|
||||
cheevos_->unlock(10);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user