eliminades referencies antigues

This commit is contained in:
2026-04-07 10:06:42 +02:00
parent 158affe1f9
commit 39170a086e
13 changed files with 28 additions and 1302 deletions

View File

@@ -19,7 +19,6 @@
#include "core/system/global_events.hpp" // Para check
#include "game/defaults.hpp" // Para Defaults::Game
#include "game/game_control.hpp" // Para GameControl
#include "game/gameplay/cheevos.hpp" // Para Cheevos
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker
#include "game/gameplay/room.hpp" // Para Room, RoomData
#include "game/gameplay/room_tracker.hpp" // Para RoomTracker
@@ -39,7 +38,7 @@
// Constructor
Game::Game(Mode mode)
: scoreboard_data_(std::make_shared<Scoreboard::Data>(0, 9, 0, true, 0, SDL_GetTicks(), Options::cheats.jail_is_open == Options::Cheat::State::ENABLED)),
: scoreboard_data_(std::make_shared<Scoreboard::Data>(0, 9, 0, true, 0, SDL_GetTicks())),
scoreboard_(std::make_shared<Scoreboard>(scoreboard_data_)),
room_tracker_(std::make_shared<RoomTracker>()),
mode_(mode),
@@ -69,13 +68,9 @@ Game::Game(Mode mode)
demoInit();
room_ = std::make_shared<Room>(current_room_, scoreboard_data_);
initPlayer(spawn_data_, room_);
total_items_ = getTotalItems();
game_backbuffer_surface_ = std::make_shared<Surface>(Options::game.width, Options::game.height);
changeRoom(current_room_);
Cheevos::get()->enable(!Options::cheats.enabled()); // Deshabilita los logros si hay trucos activados
Cheevos::get()->clearUnobtainableState();
#ifdef _DEBUG
Console::get()->setScope("debug");
@@ -335,8 +330,7 @@ void Game::updatePlaying(float delta_time) {
checkPlayerAndItems();
checkPlayerAndEnemies();
checkIfPlayerIsAlive();
checkEndGame();
checkSomeCheevos();
// Avanzar transición
if (transitioning_) {
@@ -884,9 +878,6 @@ void Game::killPlayer() {
--scoreboard_data_->lives;
}
// Invalida el logro de pasarse el juego sin morir
Cheevos::get()->setUnobtainable(11);
// Sonido
Audio::get()->playSound("death.wav", Audio::Group::GAME);
@@ -906,41 +897,6 @@ void Game::setScoreBoardColor() { // NOLINT(readability-convert-member-function
scoreboard_data_->color = IS_BLACK || IS_BRIGHT_BLACK ? 14 : BORDER_COLOR;
}
// Comprueba si ha finalizado el juego
auto Game::checkEndGame() -> bool {
const bool IS_ON_THE_ROOM = room_->getNumber() == Defaults::Game::Room::END_ROOM; // Estar en la habitación que toca
const bool HAVE_THE_ITEMS =
scoreboard_data_->items >= int(total_items_ * Defaults::Game::Items::PERCENT_TO_OPEN_THE_JAIL) ||
Options::cheats.jail_is_open == Options::Cheat::State::ENABLED; // Con mas del 90% de los items recogidos
const bool IS_ON_THE_DOOR = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
scoreboard_data_->jail_is_open = HAVE_THE_ITEMS;
if (HAVE_THE_ITEMS && IS_ON_THE_ROOM && IS_ON_THE_DOOR) {
// Comprueba los logros de completar el juego
checkEndGameCheevos();
// Iniciar transición de fade en vez de cambio inmediato de escena
transitionToState(State::FADE_TO_ENDING);
Audio::get()->fadeOutMusic(1000); // Fade out de música en 1 segundo
return true;
}
return false;
}
// Obtiene la cantidad total de items que hay en el mapeado del juego
auto Game::getTotalItems() -> int {
int items = 0;
auto rooms = Resource::Cache::get()->getRooms();
for (const auto& room : rooms) {
items += room.room->items.size();
}
return items;
}
// Pone el juego en pausa
void Game::togglePause() {
paused_ = !paused_;
@@ -950,63 +906,6 @@ void Game::togglePause() {
scoreboard_->setPaused(paused_);
}
// Comprueba algunos logros
void Game::checkSomeCheevos() { // NOLINT(readability-convert-member-functions-to-static)
auto* cheevos = Cheevos::get();
// Logros sobre la cantidad de items
if (scoreboard_data_->items == total_items_) {
cheevos->unlock(4);
cheevos->unlock(3);
cheevos->unlock(2);
cheevos->unlock(1);
} else if (scoreboard_data_->items >= total_items_ * 0.75F) {
cheevos->unlock(3);
cheevos->unlock(2);
cheevos->unlock(1);
} else if (scoreboard_data_->items >= total_items_ * 0.5F) {
cheevos->unlock(2);
cheevos->unlock(1);
} else if (scoreboard_data_->items >= total_items_ * 0.25F) {
cheevos->unlock(1);
}
// Logros sobre las habitaciones visitadas
if (scoreboard_data_->rooms >= 60) {
cheevos->unlock(7);
cheevos->unlock(6);
cheevos->unlock(5);
} else if (scoreboard_data_->rooms >= 40) {
cheevos->unlock(6);
cheevos->unlock(5);
} else if (scoreboard_data_->rooms >= 20) {
cheevos->unlock(5);
}
}
// Comprueba los logros de completar el juego
void Game::checkEndGameCheevos() { // NOLINT(readability-convert-member-functions-to-static)
auto* cheevos = Cheevos::get();
// "Complete the game"
cheevos->unlock(8);
// "Complete the game without entering the jail"
cheevos->unlock(9);
// "Complete the game with all items"
if (scoreboard_data_->items == total_items_) {
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);
}
}
// Inicializa al jugador
void Game::initPlayer(const Player::SpawnData& spawn_point, std::shared_ptr<Room> room) { // NOLINT(readability-convert-member-functions-to-static)

View File

@@ -75,11 +75,7 @@ class Game {
void checkIfPlayerIsAlive(); // Comprueba si el jugador esta vivo
void killPlayer(); // Mata al jugador
void setScoreBoardColor(); // Pone el color del marcador en función del color del borde de la habitación
auto checkEndGame() -> bool; // Comprueba si ha finalizado el juego
static auto getTotalItems() -> int; // Obtiene la cantidad total de items que hay en el mapeado del juego
void togglePause(); // Pone el juego en pausa
void checkSomeCheevos(); // Comprueba algunos logros
void checkEndGameCheevos(); // Comprueba los logros de completar el juego
void initPlayer(const Player::SpawnData& spawn_point, std::shared_ptr<Room> room); // Inicializa al jugador
void endTransition(); // Finaliza la transición entre pantallas
void keepMusicPlaying(); // Hace sonar la música
@@ -106,7 +102,6 @@ class Game {
DeltaTimer delta_timer_; // Timer para calcular delta time
std::string current_room_; // Fichero de la habitación actual
Player::SpawnData spawn_data_; // Lugar de la habitación donde aparece el jugador
int total_items_; // Cantidad total de items que hay en el mapeado del juego
bool paused_{false}; // Indica si el juego se encuentra en pausa
float state_time_{0.0F}; // Tiempo acumulado en el estado actual
float fade_accumulator_{0.0F}; // Acumulador de tiempo para el fade

View File

@@ -16,7 +16,6 @@
#include "core/resources/resource_list.hpp" // Para Asset
#include "core/system/event_buffer.hpp" // Para EventBuffer
#include "core/system/global_events.hpp" // Para check
#include "game/gameplay/cheevos.hpp" // Para Cheevos, Achievement
#include "game/options.hpp" // Para Options, options, SectionState, Section
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/ui/console.hpp" // Para Console
@@ -42,7 +41,6 @@ Title::Title()
SceneManager::options = SceneManager::Options::NONE;
// Acciones iniciales
createCheevosTexture(); // Crea y rellena la textura para mostrar los logros
Screen::get()->setBorderColor(0); // Cambia el color del borde
Audio::get()->playMusic("574071_EA_DTV.ogg"); // Inicia la musica
}
@@ -111,11 +109,6 @@ void Title::handleMainMenuKeyPress(SDL_Keycode key) {
// Si no hay gamepad, simplemente no hacer nada
break;
case SDLK_4:
// PROJECTS
transitionToState(State::CHEEVOS_MENU);
break;
default:
break;
}
@@ -139,19 +132,6 @@ void Title::handleInput(float delta_time) {
return;
}
switch (state_) {
case State::CHEEVOS_MENU:
if (Input::get()->checkAction(InputAction::ACCEPT, Input::DO_NOT_ALLOW_REPEAT) ||
Input::get()->checkAction(InputAction::CANCEL, Input::DO_NOT_ALLOW_REPEAT)) {
resetCheevosScroll();
transitionToState(State::MAIN_MENU);
}
break;
default:
break;
}
GlobalInputs::handle();
}
@@ -175,10 +155,6 @@ void Title::updateState(float delta_time) {
updateMainMenu(delta_time);
break;
case State::CHEEVOS_MENU:
updateCheevosMenu(delta_time);
break;
case State::FADE_MENU:
updateFadeMenu(delta_time);
break;
@@ -231,49 +207,6 @@ void Title::updateMainMenu(float delta_time) {
}
}
// Actualiza el estado CHEEVOS_MENU
void Title::updateCheevosMenu(float delta_time) {
// Determina la velocidad objetivo basada en el input
float target_velocity = 0.0F;
if (Input::get()->checkAction(InputAction::RIGHT, Input::ALLOW_REPEAT)) {
target_velocity = CHEEVOS_SCROLL_MAX_SPEED; // Scroll hacia abajo
} else if (Input::get()->checkAction(InputAction::LEFT, Input::ALLOW_REPEAT)) {
target_velocity = -CHEEVOS_SCROLL_MAX_SPEED; // Scroll hacia arriba
}
// Interpola suavemente la velocidad actual hacia la velocidad objetivo
if (target_velocity != 0.0F) {
// Acelerando hacia la velocidad objetivo
const float ACCELERATION_STEP = CHEEVOS_SCROLL_ACCELERATION * delta_time;
if (cheevos_scroll_velocity_ < target_velocity) {
cheevos_scroll_velocity_ = std::min(cheevos_scroll_velocity_ + ACCELERATION_STEP, target_velocity);
} else if (cheevos_scroll_velocity_ > target_velocity) {
cheevos_scroll_velocity_ = std::max(cheevos_scroll_velocity_ - ACCELERATION_STEP, target_velocity);
}
} else {
// Desacelerando hacia 0
const float DECELERATION_STEP = CHEEVOS_SCROLL_DECELERATION * delta_time;
if (cheevos_scroll_velocity_ > 0.0F) {
cheevos_scroll_velocity_ = std::max(cheevos_scroll_velocity_ - DECELERATION_STEP, 0.0F);
} else if (cheevos_scroll_velocity_ < 0.0F) {
cheevos_scroll_velocity_ = std::min(cheevos_scroll_velocity_ + DECELERATION_STEP, 0.0F);
}
}
// Aplica la velocidad actual al scroll position
if (cheevos_scroll_velocity_ != 0.0F) {
cheevos_surface_view_.y += cheevos_scroll_velocity_ * delta_time;
// Ajusta los límites
const float BOTTOM = cheevos_surface_->getHeight() - cheevos_surface_view_.h;
cheevos_surface_view_.y = std::clamp(cheevos_surface_view_.y, 0.0F, BOTTOM);
cheevos_sprite_->setClip(cheevos_surface_view_);
}
// No incrementar state_time_ (no timeout en este estado)
}
// Actualiza el estado FADE_MENU
void Title::updateFadeMenu(float delta_time) {
fade_accumulator_ += delta_time;
@@ -310,68 +243,6 @@ void Title::render() {
Screen::get()->render();
}
// Crea y rellena la textura para mostrar los logros
void Title::createCheevosTexture() { // NOLINT(readability-convert-member-functions-to-static)
// Define la zona central del menu (entre el logo y la marquesina)
constexpr int MENU_ZONE_Y = 73; // Top of menu zone
constexpr int MENU_ZONE_HEIGHT = 102; // Height of menu zone
// Crea la textura con el listado de logros
const auto CHEEVOS_LIST = Cheevos::get()->list();
const auto TEXT = Resource::Cache::get()->getText("subatomic");
constexpr int CHEEVOS_TEXTURE_WIDTH = 200;
constexpr int CHEEVOS_TEXTURE_VIEW_HEIGHT = MENU_ZONE_HEIGHT;
constexpr int CHEEVOS_PADDING = 10;
const int CHEEVO_HEIGHT = CHEEVOS_PADDING + (TEXT->getCharacterSize() * 2) + 1;
const int CHEEVOS_TEXTURE_HEIGHT = (CHEEVO_HEIGHT * CHEEVOS_LIST.size()) + 2 + TEXT->getCharacterSize() + 8;
cheevos_surface_ = std::make_shared<Surface>(CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT);
// Prepara para dibujar sobre la textura
auto previuos_renderer = Screen::get()->getRendererSurface();
Screen::get()->setRendererSurface(cheevos_surface_);
// Rellena la textura con color sólido
const auto CHEEVOS_BG_COLOR = 0;
cheevos_surface_->clear(CHEEVOS_BG_COLOR);
// Escribe la lista de logros en la textura
const std::string CHEEVOS_OWNER = Locale::get()->get("title.projects"); // NOLINT(readability-static-accessed-through-instance)
const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->getTotalUnlockedAchievements()) + " / " + std::to_string(Cheevos::get()->size()) + ")";
int pos = 2;
TEXT->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, cheevos_surface_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, 9);
pos += TEXT->getCharacterSize();
const Uint8 CHEEVO_LOCKED_COLOR = 14;
const Uint8 CHEEVO_UNLOCKED_COLOR = 9;
constexpr int LINE_X1 = (CHEEVOS_TEXTURE_WIDTH / 7) * 3;
constexpr int LINE_X2 = LINE_X1 + ((CHEEVOS_TEXTURE_WIDTH / 7) * 1);
for (const auto& cheevo : CHEEVOS_LIST) {
const Uint8 CHEEVO_COLOR = cheevo.completed ? CHEEVO_UNLOCKED_COLOR : CHEEVO_LOCKED_COLOR;
pos += CHEEVOS_PADDING;
constexpr int HALF = CHEEVOS_PADDING / 2;
cheevos_surface_->drawLine(LINE_X1, pos - HALF - 1, LINE_X2, pos - HALF - 1, CHEEVO_COLOR);
TEXT->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.caption, 1, CHEEVO_COLOR);
pos += TEXT->getCharacterSize() + 1;
TEXT->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.description, 1, CHEEVO_COLOR);
pos += TEXT->getCharacterSize();
}
// Restablece el RenderSurface
Screen::get()->setRendererSurface(previuos_renderer);
// Crea el sprite para el listado de logros (usa la zona del menu)
cheevos_sprite_ = std::make_unique<Sprite>(cheevos_surface_, (GameCanvas::WIDTH - cheevos_surface_->getWidth()) / 2, MENU_ZONE_Y, cheevos_surface_->getWidth(), cheevos_surface_->getHeight());
cheevos_surface_view_ = {.x = 0, .y = 0, .w = cheevos_surface_->getWidth(), .h = CHEEVOS_TEXTURE_VIEW_HEIGHT};
cheevos_sprite_->setClip(cheevos_surface_view_);
}
// Resetea el scroll de la lista de logros
void Title::resetCheevosScroll() {
cheevos_surface_view_.y = 0;
cheevos_scroll_velocity_ = 0.0F;
cheevos_sprite_->setClip(cheevos_surface_view_);
}
// Dibuja el logo con el titulo del juego
void Title::renderGameLogo() {
game_logo_sprite_->render();
@@ -389,30 +260,24 @@ void Title::renderMainMenu() {
return;
}
// Zona central del menu (debe coincidir con la textura de cheevos)
// Zona central del menu
constexpr int MENU_ZONE_Y = 73;
constexpr int MENU_ZONE_HEIGHT = 102;
// Menú principal normal con 4 opciones centradas verticalmente en la zona
// Menú principal normal con 3 opciones centradas verticalmente en la zona
const Uint8 COLOR = 8;
const int TEXT_SIZE = menu_text_->getCharacterSize();
const int MENU_CENTER_Y = MENU_ZONE_Y + (MENU_ZONE_HEIGHT / 2);
const int SPACING = 2 * TEXT_SIZE; // Espaciado entre opciones
// Calcula posiciones centradas verticalmente (4 items con espaciado)
const int TOTAL_HEIGHT = 3 * SPACING; // 3 espacios entre 4 items
// Calcula posiciones centradas verticalmente (3 items con espaciado)
const int TOTAL_HEIGHT = 2 * SPACING; // 2 espacios entre 3 items
const int START_Y = MENU_CENTER_Y - (TOTAL_HEIGHT / 2);
auto* loc = Locale::get();
menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y, loc->get("title.menu.play"), 1, COLOR);
menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y + SPACING, loc->get("title.menu.keyboard"), 1, COLOR);
menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y + (2 * SPACING), loc->get("title.menu.joystick"), 1, COLOR);
menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y + (3 * SPACING), loc->get("title.menu.projects"), 1, COLOR);
}
// Dibuja el menu de logros
void Title::renderCheevosMenu() {
cheevos_sprite_->render();
}
// Dibuja los elementos en la surface
@@ -432,12 +297,6 @@ void Title::fillTitleSurface() {
break;
case State::CHEEVOS_MENU:
renderGameLogo();
renderCheevosMenu();
break;
default:
break;
}
@@ -534,7 +393,7 @@ void Title::applyKeyboardRemap() { // NOLINT(readability-convert-member-functio
// Dibuja la pantalla de redefinir teclado
void Title::renderKeyboardRemap() const {
// Zona central del menu (debe coincidir con la textura de cheevos)
// Zona central del menu
constexpr int MENU_ZONE_Y = 73;
constexpr int MENU_ZONE_HEIGHT = 102;
@@ -582,7 +441,7 @@ void Title::renderKeyboardRemap() const {
// Dibuja la pantalla de redefinir joystick
void Title::renderJoystickRemap() const {
// Zona central del menu (debe coincidir con la textura de cheevos)
// Zona central del menu
constexpr int MENU_ZONE_Y = 73;
constexpr int MENU_ZONE_HEIGHT = 102;

View File

@@ -26,7 +26,6 @@ class Title {
// --- Estructuras y enumeraciones ---
enum class State {
MAIN_MENU,
CHEEVOS_MENU,
FADE_MENU,
POST_FADE_MENU,
};
@@ -35,10 +34,6 @@ class Title {
static constexpr float FADE_STEP_INTERVAL = 0.05F; // Intervalo entre pasos de fade (antes cada 4 frames)
static constexpr float POST_FADE_DELAY = 1.0F; // Delay después del fade (pantalla en negro)
static constexpr float KEYBOARD_REMAP_DISPLAY_DELAY = 2.0F; // Tiempo mostrando teclas definidas antes de guardar
static constexpr float CHEEVOS_SCROLL_MAX_SPEED = 180.0F; // Velocidad máxima de scroll de logros (pixels/segundo)
static constexpr float CHEEVOS_SCROLL_ACCELERATION = 600.0F; // Aceleración del scroll (pixels/segundo²)
static constexpr float CHEEVOS_SCROLL_DECELERATION = 800.0F; // Desaceleración del scroll (pixels/segundo²)
// --- Métodos ---
void handleEvents(); // Comprueba el manejador de eventos
void handleMainMenuKeyPress(SDL_Keycode key); // Maneja las teclas del menu principal
@@ -46,12 +41,10 @@ class Title {
void updateState(float delta_time); // Actualiza el estado actual
void transitionToState(State new_state); // Transiciona a un nuevo estado
void updateMainMenu(float delta_time); // Actualiza MAIN_MENU
void updateCheevosMenu(float delta_time); // Actualiza CHEEVOS_MENU
void updateFadeMenu(float delta_time); // Actualiza FADE_MENU
void updatePostFadeMenu(float delta_time); // Actualiza POST_FADE_MENU
void renderGameLogo(); // Dibuja el logo con el titulo del juego
void renderMainMenu(); // Dibuja el menu principal
void renderCheevosMenu(); // Dibuja el menu de logros
void renderKeyboardRemap() const; // Dibuja la pantalla de redefinir teclado
void renderJoystickRemap() const; // Dibuja la pantalla de redefinir joystick
void handleKeyboardRemap(const SDL_Event& event); // Maneja la captura de teclas
@@ -63,24 +56,16 @@ class Title {
void applyJoystickRemap(); // Aplica y guarda los botones del gamepad redefinidos
static auto getActionName(int step) -> std::string; // Retorna el nombre de la accion (LEFT/RIGHT/JUMP)
static auto getButtonName(int button) -> std::string; // Retorna el nombre amigable del boton del gamepad
void createCheevosTexture(); // Crea y rellena la surface para mostrar los logros
void resetCheevosScroll(); // Resetea el scroll de la lista de logros
void fillTitleSurface(); // Dibuja los elementos en la surface
// --- Variables miembro ---
// Objetos y punteros
std::shared_ptr<Surface> game_logo_surface_; // Textura con los graficos
std::unique_ptr<Sprite> game_logo_sprite_; // SSprite para manejar la surface
std::shared_ptr<Surface> cheevos_surface_; // Textura con la lista de logros
std::unique_ptr<Sprite> cheevos_sprite_; // SSprite para manejar la surface con la lista de logros
std::shared_ptr<Surface> title_surface_; // Surface donde se dibuja toda la clase
std::unique_ptr<DeltaTimer> delta_timer_; // Timer para delta time
std::shared_ptr<Text> menu_text_; // Texto para los menus
// Variables de estado del menú de logros
SDL_FRect cheevos_surface_view_; // Zona visible de la surface con el listado de logros
float cheevos_scroll_velocity_{0.0F}; // Velocidad actual del scroll de logros (pixels/segundo)
// Variables de estado general
State state_; // Estado en el que se encuentra el bucle principal
float state_time_{0.0F}; // Tiempo acumulado en el estado actual