From 6bf26f747027e540ae6a36e9addff44c3e591f9c Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 21 Nov 2025 09:30:33 +0100 Subject: [PATCH] posat orden en defaults i defines --- source/core/resources/resource_cache.cpp | 2 +- source/game/defaults.hpp | 119 ++++++++++++---------- source/game/entities/player.cpp | 16 +-- source/game/entities/player.hpp | 46 ++++----- source/game/gameplay/cheevos.cpp | 2 +- source/game/gameplay/room_loader.cpp | 26 ++--- source/game/gameplay/scoreboard.cpp | 20 ++-- source/game/gameplay/tilemap_renderer.cpp | 4 +- source/game/gameplay/tilemap_renderer.hpp | 43 ++++---- source/game/options.cpp | 60 +++++------ source/game/options.hpp | 68 ++++++------- source/game/scenes/credits.cpp | 6 +- source/game/scenes/ending2.cpp | 10 +- source/game/scenes/ending2.hpp | 28 ++--- source/game/scenes/game.cpp | 20 ++-- source/game/scenes/game_over.cpp | 16 +-- source/game/scenes/title.cpp | 36 +++---- source/utils/defines.hpp | 82 +++++++-------- 18 files changed, 307 insertions(+), 297 deletions(-) diff --git a/source/core/resources/resource_cache.cpp b/source/core/resources/resource_cache.cpp index 2febb44..aacbb03 100644 --- a/source/core/resources/resource_cache.cpp +++ b/source/core/resources/resource_cache.cpp @@ -13,7 +13,7 @@ #include "core/rendering/text.hpp" // Para Text, loadTextFile #include "core/resources/resource_helper.hpp" // Para Helper #include "core/resources/resource_list.hpp" // Para List, List::Type -#include "game/defaults.hpp" // Para GameDefaults::VERSION +#include "game/defaults.hpp" // Para Defaults namespace #include "game/gameplay/room.hpp" // Para RoomData, loadRoomFile, loadRoomTileFile #include "game/options.hpp" // Para Options, OptionsGame, options #include "utils/defines.hpp" // Para WINDOW_CAPTION diff --git a/source/game/defaults.hpp b/source/game/defaults.hpp index c2ff5f7..70012ca 100644 --- a/source/game/defaults.hpp +++ b/source/game/defaults.hpp @@ -3,6 +3,7 @@ #include #include "core/rendering/screen.hpp" // Para Screen::Filter +#include "utils/defines.hpp" // Para GameCanvas #include "utils/utils.hpp" // Para PaletteColor // Forward declarations from Options namespace @@ -11,68 +12,80 @@ namespace Options { enum class NotificationPosition; } // namespace Options -namespace GameDefaults { +namespace Defaults { -// GAME -constexpr int GAME_WIDTH = 256; // Ancho de la ventana por defecto -constexpr int GAME_HEIGHT = 192; // Alto de la ventana por defecto +// --- CANVAS --- +// Dimensiones del canvas del juego (usa GameCanvas como fuente única) +namespace Canvas { +constexpr int WIDTH = GameCanvas::WIDTH; // Ancho del canvas del juego (256) +constexpr int HEIGHT = GameCanvas::HEIGHT; // Alto del canvas del juego (192) +} // namespace Canvas -// WINDOW -constexpr int WINDOW_ZOOM = 2; // Zoom de la ventana por defecto +// --- WINDOW --- +namespace Window { +constexpr int ZOOM = 2; // Zoom de la ventana por defecto +} // namespace Window -// VIDEO -constexpr bool VIDEO_FULLSCREEN = false; // Modo de pantalla completa por defecto (false = ventana) -constexpr Screen::Filter VIDEO_FILTER = Screen::Filter::NEAREST; // Filtro por defecto -constexpr bool VIDEO_VERTICAL_SYNC = true; // Vsync activado por defecto -constexpr bool VIDEO_SHADERS = false; // Shaders desactivados por defecto -constexpr bool VIDEO_INTEGER_SCALE = true; // Escalado entero activado por defecto -constexpr bool VIDEO_KEEP_ASPECT = true; // Mantener aspecto activado por defecto -constexpr const char* PALETTE_NAME = "zx-spectrum"; // Paleta por defecto +// --- VIDEO --- +namespace Video { +constexpr bool FULLSCREEN = false; // Modo de pantalla completa por defecto (false = ventana) +constexpr Screen::Filter FILTER = Screen::Filter::NEAREST; // Filtro por defecto +constexpr bool VERTICAL_SYNC = true; // Vsync activado por defecto +constexpr bool SHADERS = false; // Shaders desactivados por defecto +constexpr bool INTEGER_SCALE = true; // Escalado entero activado por defecto +constexpr bool KEEP_ASPECT = true; // Mantener aspecto activado por defecto +constexpr const char* PALETTE_NAME = "zx-spectrum"; // Paleta por defecto +} // namespace Video -// BORDER -constexpr bool BORDER_ENABLED = true; // Borde activado por defecto -constexpr int BORDER_WIDTH = 32; // Ancho del borde por defecto -constexpr int BORDER_HEIGHT = 24; // Alto del borde por defecto +// --- BORDER --- +namespace Border { +constexpr bool ENABLED = true; // Borde activado por defecto +constexpr int WIDTH = 32; // Ancho del borde por defecto +constexpr int HEIGHT = 24; // Alto del borde por defecto +} // namespace Border -// AUDIO -constexpr float AUDIO_VOLUME = 1.0F; // Volumen por defecto -constexpr bool AUDIO_ENABLED = true; // Audio por defecto +// --- AUDIO --- +namespace Audio { +constexpr float VOLUME = 1.0F; // Volumen por defecto +constexpr bool ENABLED = true; // Audio por defecto +} // namespace Audio -// MUSIC -constexpr float MUSIC_VOLUME = 0.8F; // Volumen por defecto de la musica -constexpr bool MUSIC_ENABLED = true; // Musica habilitada por defecto +// --- MUSIC --- +namespace Music { +constexpr float VOLUME = 0.8F; // Volumen por defecto de la musica +constexpr bool ENABLED = true; // Musica habilitada por defecto +} // namespace Music -// SOUND -constexpr float SOUND_VOLUME = 1.0F; // Volumen por defecto de los efectos de sonido -constexpr bool SOUND_ENABLED = true; // Sonido habilitado por defecto +// --- SOUND --- +namespace Sound { +constexpr float VOLUME = 1.0F; // Volumen por defecto de los efectos de sonido +constexpr bool ENABLED = true; // Sonido habilitado por defecto +} // namespace Sound -// NOTIFICATIONS -constexpr bool NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto -const Uint8 NOTIFICATION_COLOR = static_cast(PaletteColor::BLUE); // Color de las notificaciones por defecto +// --- CHEATS --- +namespace Cheat { +constexpr bool INFINITE_LIVES = false; // Vidas infinitas desactivadas por defecto +constexpr bool INVINCIBLE = true; // Invencibilidad desactivada por defecto +constexpr bool JAIL_IS_OPEN = false; // Jail abierta desactivada por defecto +constexpr bool ALTERNATE_SKIN = false; // Skin alternativa desactivada por defecto +} // namespace Cheat -// CHEATS -constexpr bool CHEAT_INFINITE_LIVES = false; // Vidas infinitas desactivadas por defecto -constexpr bool CHEAT_INVINCIBLE = true; // Invencibilidad desactivada por defecto -constexpr bool CHEAT_JAIL_IS_OPEN = false; // Jail abierta desactivada por defecto -constexpr bool CHEAT_ALTERNATE_SKIN = false; // Skin alternativa desactivada por defecto +// --- STATS --- +namespace Stats { +constexpr int ROOMS = 0; // Habitaciones visitadas por defecto +constexpr int ITEMS = 0; // Items obtenidos por defecto +constexpr const char* WORST_NIGHTMARE = ""; // Habitación con más muertes por defecto +} // namespace Stats -// STATS -constexpr int STATS_ROOMS = 0; // Habitaciones visitadas por defecto -constexpr int STATS_ITEMS = 0; // Items obtenidos por defecto -constexpr const char* STATS_WORST_NIGHTMARE = ""; // Habitación con más muertes por defecto +// --- CONTROLS --- +namespace Controls { +constexpr SDL_Scancode KEY_LEFT = SDL_SCANCODE_LEFT; // Tecla izquierda por defecto +constexpr SDL_Scancode KEY_RIGHT = SDL_SCANCODE_RIGHT; // Tecla derecha por defecto +constexpr SDL_Scancode KEY_JUMP = SDL_SCANCODE_UP; // Tecla salto por defecto -// CONTROLS -constexpr SDL_Scancode CONTROL_KEY_LEFT = SDL_SCANCODE_LEFT; // Tecla izquierda por defecto -constexpr SDL_Scancode CONTROL_KEY_RIGHT = SDL_SCANCODE_RIGHT; // Tecla derecha por defecto -constexpr SDL_Scancode CONTROL_KEY_JUMP = SDL_SCANCODE_UP; // Tecla salto por defecto +constexpr int GAMEPAD_BUTTON_LEFT = SDL_GAMEPAD_BUTTON_DPAD_LEFT; // Botón izquierda por defecto +constexpr int GAMEPAD_BUTTON_RIGHT = SDL_GAMEPAD_BUTTON_DPAD_RIGHT; // Botón derecha por defecto +constexpr int GAMEPAD_BUTTON_JUMP = SDL_GAMEPAD_BUTTON_WEST; // Botón salto por defecto +} // namespace Controls -// GAMEPAD CONTROLS -const int GAMEPAD_BUTTON_LEFT = SDL_GAMEPAD_BUTTON_DPAD_LEFT; // Botón izquierda por defecto -const int GAMEPAD_BUTTON_RIGHT = SDL_GAMEPAD_BUTTON_DPAD_RIGHT; // Botón derecha por defecto -const int GAMEPAD_BUTTON_JUMP = SDL_GAMEPAD_BUTTON_WEST; // Botón salto por defecto - -// OTHER -constexpr bool CONSOLE = false; // Consola desactivada por defecto -constexpr const char* VERSION = "1.10"; // Versión por defecto - -} // namespace GameDefaults +} // namespace Defaults diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 724b76f..ca7d68d 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -364,22 +364,22 @@ void Player::moveFalling(float delta_time) { // Comprueba si está situado en alguno de los cuatro bordes de la habitación void Player::handleBorders() { - if (x_ < PLAY_AREA_LEFT) { + if (x_ < PlayArea::LEFT) { border_ = Room::Border::LEFT; is_on_border_ = true; } - else if (x_ + WIDTH > PLAY_AREA_RIGHT) { + else if (x_ + WIDTH > PlayArea::RIGHT) { border_ = Room::Border::RIGHT; is_on_border_ = true; } - else if (y_ < PLAY_AREA_TOP) { + else if (y_ < PlayArea::TOP) { border_ = Room::Border::TOP; is_on_border_ = true; } - else if (y_ + HEIGHT > PLAY_AREA_BOTTOM) { + else if (y_ + HEIGHT > PlayArea::BOTTOM) { border_ = Room::Border::BOTTOM; is_on_border_ = true; } @@ -393,25 +393,25 @@ void Player::handleBorders() { void Player::switchBorders() { switch (border_) { case Room::Border::TOP: - y_ = PLAY_AREA_BOTTOM - HEIGHT - TILE_SIZE; + y_ = PlayArea::BOTTOM - HEIGHT - Tile::SIZE; // CRÍTICO: Resetear last_grounded_position_ para evitar muerte falsa por diferencia de Y entre pantallas last_grounded_position_ = static_cast(y_); transitionToState(State::ON_GROUND); // TODO: Detectar si debe ser ON_SLOPE break; case Room::Border::BOTTOM: - y_ = PLAY_AREA_TOP; + y_ = PlayArea::TOP; // CRÍTICO: Resetear last_grounded_position_ para evitar muerte falsa por diferencia de Y entre pantallas last_grounded_position_ = static_cast(y_); transitionToState(State::ON_GROUND); // TODO: Detectar si debe ser ON_SLOPE break; case Room::Border::RIGHT: - x_ = PLAY_AREA_LEFT; + x_ = PlayArea::LEFT; break; case Room::Border::LEFT: - x_ = PLAY_AREA_RIGHT - WIDTH; + x_ = PlayArea::RIGHT - WIDTH; break; default: diff --git a/source/game/entities/player.hpp b/source/game/entities/player.hpp index d628582..7c9db3a 100644 --- a/source/game/entities/player.hpp +++ b/source/game/entities/player.hpp @@ -65,8 +65,8 @@ class Player { float elapsed_time = 0.0F; // Tiempo transcurrido durante el salto bool active = false; // Indica si el controlador está activo - void start(); // Inicia el controlador - void reset(); // Resetea el controlador + void start(); // Inicia el controlador + void reset(); // Resetea el controlador auto shouldPlay(float delta_time, size_t& out_index) -> bool; // Comprueba si debe reproducir un sonido }; @@ -80,8 +80,8 @@ class Player { float last_y = 0.0F; // Última posición Y registrada bool active = false; // Indica si el controlador está activo - void start(float start_y); // Inicia el controlador - void reset(); // Resetea el controlador + void start(float start_y); // Inicia el controlador + void reset(); // Resetea el controlador auto shouldPlay(float delta_time, float current_y, size_t& out_index) -> bool; // Comprueba si debe reproducir un sonido }; @@ -90,24 +90,24 @@ class Player { ~Player() = default; // --- Funciones --- - void render(); // Pinta el enemigo en pantalla - void update(float delta_time); // Actualiza las variables del objeto - [[nodiscard]] auto isOnBorder() const -> bool { return is_on_border_; } // Indica si el jugador esta en uno de los cuatro bordes de la pantalla - [[nodiscard]] auto getBorder() const -> Room::Border { return border_; } // Indica en cual de los cuatro bordes se encuentra - void switchBorders(); // Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla - auto getRect() -> SDL_FRect { return {x_, y_, WIDTH, HEIGHT}; } // Obtiene el rectangulo que delimita al jugador - auto getCollider() -> SDL_FRect& { return collider_box_; } // Obtiene el rectangulo de colision del jugador + void render(); // Pinta el enemigo en pantalla + void update(float delta_time); // Actualiza las variables del objeto + [[nodiscard]] auto isOnBorder() const -> bool { return is_on_border_; } // Indica si el jugador esta en uno de los cuatro bordes de la pantalla + [[nodiscard]] auto getBorder() const -> Room::Border { return border_; } // Indica en cual de los cuatro bordes se encuentra + void switchBorders(); // Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla + auto getRect() -> SDL_FRect { return {x_, y_, WIDTH, HEIGHT}; } // Obtiene el rectangulo que delimita al jugador + auto getCollider() -> SDL_FRect& { return collider_box_; } // Obtiene el rectangulo de colision del jugador auto getSpawnParams() -> SpawnData { return {.x = x_, .y = y_, .vx = vx_, .vy = vy_, .last_grounded_position = last_grounded_position_, .state = state_, .flip = sprite_->getFlip()}; } // Obtiene el estado de reaparición del jugador - void setColor(); // Establece el color del jugador - void setRoom(std::shared_ptr room) { room_ = std::move(room); } // Establece la habitación en la que se encuentra el jugador - [[nodiscard]] auto isAlive() const -> bool { return is_alive_; } // Comprueba si el jugador esta vivo - void setPaused(bool value) { is_paused_ = value; } // Pone el jugador en modo pausa + void setColor(); // Establece el color del jugador + void setRoom(std::shared_ptr room) { room_ = std::move(room); } // Establece la habitación en la que se encuentra el jugador + [[nodiscard]] auto isAlive() const -> bool { return is_alive_; } // Comprueba si el jugador esta vivo + void setPaused(bool value) { is_paused_ = value; } // Pone el jugador en modo pausa private: // --- Constantes --- - static constexpr int WIDTH = 8; // Ancho del jugador - static constexpr int HEIGHT = 16; // ALto del jugador - static constexpr int MAX_FALLING_HEIGHT = TILE_SIZE * 4; // Altura maxima permitida de caída en pixels + static constexpr int WIDTH = 8; // Ancho del jugador + static constexpr int HEIGHT = 16; // ALto del jugador + static constexpr int MAX_FALLING_HEIGHT = Tile::SIZE * 4; // Altura maxima permitida de caída en pixels // --- Objetos y punteros --- std::shared_ptr room_; // Objeto encargado de gestionar cada habitación del juego @@ -181,11 +181,11 @@ class Player { void applyGravity(float delta_time); // Aplica gravedad al jugador // --- Funciones de movimiento y colisión --- - void move(float delta_time); // Orquesta el movimiento del jugador - auto getProjection(Direction direction, float displacement) -> SDL_FRect; // Devuelve el rectangulo de proyeccion - void applyHorizontalMovement(float delta_time); // Aplica movimiento horizontal con colisión de muros - auto handleLandingFromAir(float displacement, const SDL_FRect& projection) -> bool; // Detecta aterrizaje en superficies y rampas - void resetSoundControllersOnLanding(); // Resetea los controladores de sonido al aterrizar + void move(float delta_time); // Orquesta el movimiento del jugador + auto getProjection(Direction direction, float displacement) -> SDL_FRect; // Devuelve el rectangulo de proyeccion + void applyHorizontalMovement(float delta_time); // Aplica movimiento horizontal con colisión de muros + auto handleLandingFromAir(float displacement, const SDL_FRect& projection) -> bool; // Detecta aterrizaje en superficies y rampas + void resetSoundControllersOnLanding(); // Resetea los controladores de sonido al aterrizar // --- Funciones de detección de superficies --- auto isOnFloor() -> bool; // Comprueba si el jugador tiene suelo debajo de los pies diff --git a/source/game/gameplay/cheevos.cpp b/source/game/gameplay/cheevos.cpp index a62241b..773c063 100644 --- a/source/game/gameplay/cheevos.cpp +++ b/source/game/gameplay/cheevos.cpp @@ -82,7 +82,7 @@ void Cheevos::unlock(int id) { cheevos_list_.at(INDEX).completed = true; // Mostrar notificación en la pantalla - Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", cheevos_list_.at(INDEX).caption}, Notifier::Style::CHEEVO /*, cheevos_list_.at(INDEX).icon*/); + Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", cheevos_list_.at(INDEX).caption}, Notifier::Style::CHEEVO, -1, false); // Guardar el estado de los logros saveToFile(); diff --git a/source/game/gameplay/room_loader.cpp b/source/game/gameplay/room_loader.cpp index 910458f..4830268 100644 --- a/source/game/gameplay/room_loader.cpp +++ b/source/game/gameplay/room_loader.cpp @@ -5,7 +5,7 @@ #include "external/fkyaml_node.hpp" // Para fkyaml::node #include "core/resources/resource_helper.hpp" // Para Resource::Helper -#include "utils/defines.hpp" // Para TILE_SIZE +#include "utils/defines.hpp" // Para Tile::SIZE #include "utils/utils.hpp" // Para stringToColor // Convierte room connection de YAML a formato interno @@ -153,34 +153,34 @@ void RoomLoader::parseEnemyBoundaries(const fkyaml::node& bounds_node, Enemy::Da if (bounds_node.contains("position1")) { const auto& pos1 = bounds_node["position1"]; if (pos1.contains("x")) { - enemy.x1 = pos1["x"].get_value() * TILE_SIZE; + enemy.x1 = pos1["x"].get_value() * Tile::SIZE; } if (pos1.contains("y")) { - enemy.y1 = pos1["y"].get_value() * TILE_SIZE; + enemy.y1 = pos1["y"].get_value() * Tile::SIZE; } } if (bounds_node.contains("position2")) { const auto& pos2 = bounds_node["position2"]; if (pos2.contains("x")) { - enemy.x2 = pos2["x"].get_value() * TILE_SIZE; + enemy.x2 = pos2["x"].get_value() * Tile::SIZE; } if (pos2.contains("y")) { - enemy.y2 = pos2["y"].get_value() * TILE_SIZE; + enemy.y2 = pos2["y"].get_value() * Tile::SIZE; } } // Formato antiguo: x1/y1/x2/y2 (compatibilidad) if (bounds_node.contains("x1")) { - enemy.x1 = bounds_node["x1"].get_value() * TILE_SIZE; + enemy.x1 = bounds_node["x1"].get_value() * Tile::SIZE; } if (bounds_node.contains("y1")) { - enemy.y1 = bounds_node["y1"].get_value() * TILE_SIZE; + enemy.y1 = bounds_node["y1"].get_value() * Tile::SIZE; } if (bounds_node.contains("x2")) { - enemy.x2 = bounds_node["x2"].get_value() * TILE_SIZE; + enemy.x2 = bounds_node["x2"].get_value() * Tile::SIZE; } if (bounds_node.contains("y2")) { - enemy.y2 = bounds_node["y2"].get_value() * TILE_SIZE; + enemy.y2 = bounds_node["y2"].get_value() * Tile::SIZE; } } @@ -197,10 +197,10 @@ auto RoomLoader::parseEnemyData(const fkyaml::node& enemy_node) -> Enemy::Data { if (enemy_node.contains("position")) { const auto& pos = enemy_node["position"]; if (pos.contains("x")) { - enemy.x = pos["x"].get_value() * TILE_SIZE; + enemy.x = pos["x"].get_value() * Tile::SIZE; } if (pos.contains("y")) { - enemy.y = pos["y"].get_value() * TILE_SIZE; + enemy.y = pos["y"].get_value() * Tile::SIZE; } } @@ -276,10 +276,10 @@ auto RoomLoader::parseItemData(const fkyaml::node& item_node, const Room::Data& if (item_node.contains("position")) { const auto& pos = item_node["position"]; if (pos.contains("x")) { - item.x = pos["x"].get_value() * TILE_SIZE; + item.x = pos["x"].get_value() * Tile::SIZE; } if (pos.contains("y")) { - item.y = pos["y"].get_value() * TILE_SIZE; + item.y = pos["y"].get_value() * Tile::SIZE; } } diff --git a/source/game/gameplay/scoreboard.cpp b/source/game/gameplay/scoreboard.cpp index bfc2a18..6b10e0c 100644 --- a/source/game/gameplay/scoreboard.cpp +++ b/source/game/gameplay/scoreboard.cpp @@ -18,7 +18,7 @@ Scoreboard::Scoreboard(std::shared_ptr data) : item_surface_(Resource::Cache::get()->getSurface("items.gif")), data_(std::move(std::move(data))) { const float SURFACE_WIDTH = Options::game.width; - constexpr float SURFACE_HEIGHT = 6.0F * TILE_SIZE; + constexpr float SURFACE_HEIGHT = 6.0F * Tile::SIZE; // Reserva memoria para los objetos const auto& player_animation_data = Resource::Cache::get()->getAnimationData(Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.yaml" : "player.yaml"); @@ -130,8 +130,8 @@ void Scoreboard::fillTexture() { surface_->clear(stringToColor("black")); // Anclas - constexpr int LINE1 = TILE_SIZE; - constexpr int LINE2 = 3 * TILE_SIZE; + constexpr int LINE1 = Tile::SIZE; + constexpr int LINE2 = 3 * Tile::SIZE; // Dibuja las vidas // Calcular desplazamiento basado en tiempo @@ -149,21 +149,21 @@ void Scoreboard::fillTexture() { if (data_->music) { const Uint8 C = data_->color; SDL_FRect clip = {0, 8, 8, 8}; - item_surface_->renderWithColorReplace(20 * TILE_SIZE, LINE2, 1, C, &clip); + item_surface_->renderWithColorReplace(20 * Tile::SIZE, LINE2, 1, C, &clip); } // Escribe los textos auto text = Resource::Cache::get()->getText("smb2"); const std::string TIME_TEXT = std::to_string((clock_.minutes % 100) / 10) + std::to_string(clock_.minutes % 10) + clock_.separator + std::to_string((clock_.seconds % 60) / 10) + std::to_string(clock_.seconds % 10); const std::string ITEMS_TEXT = std::to_string(data_->items / 100) + std::to_string((data_->items % 100) / 10) + std::to_string(data_->items % 10); - text->writeColored(TILE_SIZE, LINE1, "Items collected ", data_->color); - text->writeColored(17 * TILE_SIZE, LINE1, ITEMS_TEXT, items_color_); - text->writeColored(20 * TILE_SIZE, LINE1, " Time ", data_->color); - text->writeColored(26 * TILE_SIZE, LINE1, TIME_TEXT, stringToColor("white")); + text->writeColored(Tile::SIZE, LINE1, "Items collected ", data_->color); + text->writeColored(17 * Tile::SIZE, LINE1, ITEMS_TEXT, items_color_); + text->writeColored(20 * Tile::SIZE, LINE1, " Time ", data_->color); + text->writeColored(26 * Tile::SIZE, LINE1, TIME_TEXT, stringToColor("white")); const std::string ROOMS_TEXT = std::to_string(data_->rooms / 100) + std::to_string((data_->rooms % 100) / 10) + std::to_string(data_->rooms % 10); - text->writeColored(22 * TILE_SIZE, LINE2, "Rooms", stringToColor("white")); - text->writeColored(28 * TILE_SIZE, LINE2, ROOMS_TEXT, stringToColor("white")); + text->writeColored(22 * Tile::SIZE, LINE2, "Rooms", stringToColor("white")); + text->writeColored(28 * Tile::SIZE, LINE2, ROOMS_TEXT, stringToColor("white")); // Deja el renderizador como estaba Screen::get()->setRendererSurface(previuos_renderer); diff --git a/source/game/gameplay/tilemap_renderer.cpp b/source/game/gameplay/tilemap_renderer.cpp index c04f5d1..0436757 100644 --- a/source/game/gameplay/tilemap_renderer.cpp +++ b/source/game/gameplay/tilemap_renderer.cpp @@ -17,7 +17,7 @@ TilemapRenderer::TilemapRenderer(std::vector tile_map, int tile_set_width, bg_color_(std::move(bg_color)), conveyor_belt_direction_(conveyor_belt_direction) { // Crear la surface del mapa - map_surface_ = std::make_shared(PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT); + map_surface_ = std::make_shared(PlayArea::WIDTH, PlayArea::HEIGHT); } // Inicializa el renderizador @@ -42,7 +42,7 @@ void TilemapRenderer::update(float delta_time) { // Renderiza el mapa completo en pantalla void TilemapRenderer::render() { // Dibuja la textura con el mapa en pantalla - SDL_FRect dest = {0, 0, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT}; + SDL_FRect dest = {0, 0, PlayArea::WIDTH, PlayArea::HEIGHT}; map_surface_->render(nullptr, &dest); // Dibuja los tiles animados diff --git a/source/game/gameplay/tilemap_renderer.hpp b/source/game/gameplay/tilemap_renderer.hpp index 7494734..6e3af99 100644 --- a/source/game/gameplay/tilemap_renderer.hpp +++ b/source/game/gameplay/tilemap_renderer.hpp @@ -6,6 +6,8 @@ #include // Para string #include // Para vector +#include "utils/defines.hpp" + class Surface; class SurfaceSprite; class CollisionMap; @@ -29,8 +31,7 @@ class TilemapRenderer { * @param bg_color Color de fondo de la habitación (como string) * @param conveyor_belt_direction Dirección de las cintas transportadoras (-1, 0, +1) */ - TilemapRenderer(std::vector tile_map, int tile_set_width, std::shared_ptr tileset_surface, - std::string bg_color, int conveyor_belt_direction); + TilemapRenderer(std::vector tile_map, int tile_set_width, std::shared_ptr tileset_surface, std::string bg_color, int conveyor_belt_direction); ~TilemapRenderer() = default; // Prohibir copia y movimiento @@ -89,29 +90,29 @@ class TilemapRenderer { }; // === Constantes === - static constexpr int TILE_SIZE = 8; // Ancho del tile en pixels - static constexpr int MAP_WIDTH = 32; // Ancho del mapa en tiles - static constexpr int MAP_HEIGHT = 16; // Alto del mapa en tiles - static constexpr int PLAY_AREA_WIDTH = 256; // Ancho del área de juego en pixels - static constexpr int PLAY_AREA_HEIGHT = 128; // Alto del área de juego en pixels - static constexpr float CONVEYOR_FRAME_DURATION = 0.05F; // Duración de cada frame (3 frames @ 60fps) + static constexpr int TILE_SIZE = Tile::SIZE; // Ancho del tile en pixels + static constexpr int MAP_WIDTH = PlayArea::WIDTH / Tile::SIZE; // Ancho del mapa en tiles + static constexpr int MAP_HEIGHT = PlayArea::HEIGHT / Tile::SIZE; // Alto del mapa en tiles + static constexpr int PLAY_AREA_WIDTH = PlayArea::WIDTH; // Ancho del área de juego en pixels + static constexpr int PLAY_AREA_HEIGHT = PlayArea::HEIGHT; // Alto del área de juego en pixels + static constexpr float CONVEYOR_FRAME_DURATION = 0.05F; // Duración de cada frame (3 frames @ 60fps) // === Datos de la habitación === - std::vector tile_map_; // Índices de tiles de la habitación - int tile_set_width_; // Ancho del tileset en tiles - std::shared_ptr tileset_surface_; // Gráficos del tileset - std::string bg_color_; // Color de fondo - int conveyor_belt_direction_; // Dirección de conveyor belts + std::vector tile_map_; // Índices de tiles de la habitación + int tile_set_width_; // Ancho del tileset en tiles + std::shared_ptr tileset_surface_; // Gráficos del tileset + std::string bg_color_; // Color de fondo + int conveyor_belt_direction_; // Dirección de conveyor belts // === Renderizado === - std::shared_ptr map_surface_; // Textura para el mapa de la habitación - std::vector animated_tiles_; // Tiles animados (conveyor belts) - float time_accumulator_{0.0F}; // Acumulador de tiempo para animaciones - bool is_paused_{false}; // Indica si está en modo pausa + std::shared_ptr map_surface_; // Textura para el mapa de la habitación + std::vector animated_tiles_; // Tiles animados (conveyor belts) + float time_accumulator_{0.0F}; // Acumulador de tiempo para animaciones + bool is_paused_{false}; // Indica si está en modo pausa // === Métodos privados === - void fillMapTexture(const CollisionMap* collision_map); // Pinta el mapa estático y debug lines - void setAnimatedTiles(const CollisionMap* collision_map); // Localiza todos los tiles animados - void updateAnimatedTiles(); // Actualiza tiles animados - void renderAnimatedTiles(); // Renderiza tiles animados + void fillMapTexture(const CollisionMap* collision_map); // Pinta el mapa estático y debug lines + void setAnimatedTiles(const CollisionMap* collision_map); // Localiza todos los tiles animados + void updateAnimatedTiles(); // Actualiza tiles animados + void renderAnimatedTiles(); // Renderiza tiles animados }; diff --git a/source/game/options.cpp b/source/game/options.cpp index 0826cd8..d5f4fcc 100644 --- a/source/game/options.cpp +++ b/source/game/options.cpp @@ -208,7 +208,7 @@ auto stringToFilter(const std::string& str) -> Screen::Filter { if (it != STRING_TO_FILTER.end()) { return it->second; } - return GameDefaults::VIDEO_FILTER; + return Defaults::Video::FILTER; } auto scancodeToString(SDL_Scancode scancode) -> std::string { @@ -269,9 +269,9 @@ void loadWindowConfigFromYaml(const fkyaml::node& yaml) { if (win.contains("zoom")) { try { int val = win["zoom"].get_value(); - window.zoom = (val > 0) ? val : GameDefaults::WINDOW_ZOOM; + window.zoom = (val > 0) ? val : Defaults::Window::ZOOM; } catch (...) { - window.zoom = GameDefaults::WINDOW_ZOOM; + window.zoom = Defaults::Window::ZOOM; } } } @@ -283,25 +283,25 @@ void loadBorderConfigFromYaml(const fkyaml::node& border) { try { video.border.enabled = border["enabled"].get_value(); } catch (...) { - video.border.enabled = GameDefaults::BORDER_ENABLED; + video.border.enabled = Defaults::Border::ENABLED; } } if (border.contains("width")) { try { auto val = border["width"].get_value(); - video.border.width = (val > 0) ? val : GameDefaults::BORDER_WIDTH; + video.border.width = (val > 0) ? val : Defaults::Border::WIDTH; } catch (...) { - video.border.width = GameDefaults::BORDER_WIDTH; + video.border.width = Defaults::Border::WIDTH; } } if (border.contains("height")) { try { auto val = border["height"].get_value(); - video.border.height = (val > 0) ? val : GameDefaults::BORDER_HEIGHT; + video.border.height = (val > 0) ? val : Defaults::Border::HEIGHT; } catch (...) { - video.border.height = GameDefaults::BORDER_HEIGHT; + video.border.height = Defaults::Border::HEIGHT; } } } @@ -313,7 +313,7 @@ void loadBasicVideoFieldsFromYaml(const fkyaml::node& vid) { try { video.fullscreen = vid["fullscreen"].get_value(); } catch (...) { - video.fullscreen = GameDefaults::VIDEO_FULLSCREEN; + video.fullscreen = Defaults::Video::FULLSCREEN; } } @@ -323,7 +323,7 @@ void loadBasicVideoFieldsFromYaml(const fkyaml::node& vid) { auto filter_str = vid["filter"].get_value(); video.filter = stringToFilter(filter_str); } catch (...) { - video.filter = GameDefaults::VIDEO_FILTER; + video.filter = Defaults::Video::FILTER; } } @@ -331,7 +331,7 @@ void loadBasicVideoFieldsFromYaml(const fkyaml::node& vid) { try { video.shaders = vid["shaders"].get_value(); } catch (...) { - video.shaders = GameDefaults::VIDEO_SHADERS; + video.shaders = Defaults::Video::SHADERS; } } @@ -339,7 +339,7 @@ void loadBasicVideoFieldsFromYaml(const fkyaml::node& vid) { try { video.vertical_sync = vid["vertical_sync"].get_value(); } catch (...) { - video.vertical_sync = GameDefaults::VIDEO_VERTICAL_SYNC; + video.vertical_sync = Defaults::Video::VERTICAL_SYNC; } } @@ -347,7 +347,7 @@ void loadBasicVideoFieldsFromYaml(const fkyaml::node& vid) { try { video.integer_scale = vid["integer_scale"].get_value(); } catch (...) { - video.integer_scale = GameDefaults::VIDEO_INTEGER_SCALE; + video.integer_scale = Defaults::Video::INTEGER_SCALE; } } @@ -355,7 +355,7 @@ void loadBasicVideoFieldsFromYaml(const fkyaml::node& vid) { try { video.keep_aspect = vid["keep_aspect"].get_value(); } catch (...) { - video.keep_aspect = GameDefaults::VIDEO_KEEP_ASPECT; + video.keep_aspect = Defaults::Video::KEEP_ASPECT; } } @@ -365,10 +365,10 @@ void loadBasicVideoFieldsFromYaml(const fkyaml::node& vid) { if (isValidPalette(palette_str)) { video.palette = palette_str; } else { - video.palette = GameDefaults::PALETTE_NAME; + video.palette = Defaults::Video::PALETTE_NAME; } } catch (...) { - video.palette = GameDefaults::PALETTE_NAME; + video.palette = Defaults::Video::PALETTE_NAME; } } } @@ -394,27 +394,27 @@ void loadKeyboardControlsFromYaml(const fkyaml::node& yaml) { if (ctrl.contains("key_left")) { try { auto key_str = ctrl["key_left"].get_value(); - keyboard_controls.key_left = stringToScancode(key_str, GameDefaults::CONTROL_KEY_LEFT); + keyboard_controls.key_left = stringToScancode(key_str, Defaults::Controls::KEY_LEFT); } catch (...) { - keyboard_controls.key_left = GameDefaults::CONTROL_KEY_LEFT; + keyboard_controls.key_left = Defaults::Controls::KEY_LEFT; } } if (ctrl.contains("key_right")) { try { auto key_str = ctrl["key_right"].get_value(); - keyboard_controls.key_right = stringToScancode(key_str, GameDefaults::CONTROL_KEY_RIGHT); + keyboard_controls.key_right = stringToScancode(key_str, Defaults::Controls::KEY_RIGHT); } catch (...) { - keyboard_controls.key_right = GameDefaults::CONTROL_KEY_RIGHT; + keyboard_controls.key_right = Defaults::Controls::KEY_RIGHT; } } if (ctrl.contains("key_jump")) { try { auto key_str = ctrl["key_jump"].get_value(); - keyboard_controls.key_jump = stringToScancode(key_str, GameDefaults::CONTROL_KEY_JUMP); + keyboard_controls.key_jump = stringToScancode(key_str, Defaults::Controls::KEY_JUMP); } catch (...) { - keyboard_controls.key_jump = GameDefaults::CONTROL_KEY_JUMP; + keyboard_controls.key_jump = Defaults::Controls::KEY_JUMP; } } } @@ -428,27 +428,27 @@ void loadGamepadControlsFromYaml(const fkyaml::node& yaml) { if (gp.contains("button_left")) { try { auto button_str = gp["button_left"].get_value(); - gamepad_controls.button_left = stringToGamepadButton(button_str, GameDefaults::GAMEPAD_BUTTON_LEFT); + gamepad_controls.button_left = stringToGamepadButton(button_str, Defaults::Controls::GAMEPAD_BUTTON_LEFT); } catch (...) { - gamepad_controls.button_left = GameDefaults::GAMEPAD_BUTTON_LEFT; + gamepad_controls.button_left = Defaults::Controls::GAMEPAD_BUTTON_LEFT; } } if (gp.contains("button_right")) { try { auto button_str = gp["button_right"].get_value(); - gamepad_controls.button_right = stringToGamepadButton(button_str, GameDefaults::GAMEPAD_BUTTON_RIGHT); + gamepad_controls.button_right = stringToGamepadButton(button_str, Defaults::Controls::GAMEPAD_BUTTON_RIGHT); } catch (...) { - gamepad_controls.button_right = GameDefaults::GAMEPAD_BUTTON_RIGHT; + gamepad_controls.button_right = Defaults::Controls::GAMEPAD_BUTTON_RIGHT; } } if (gp.contains("button_jump")) { try { auto button_str = gp["button_jump"].get_value(); - gamepad_controls.button_jump = stringToGamepadButton(button_str, GameDefaults::GAMEPAD_BUTTON_JUMP); + gamepad_controls.button_jump = stringToGamepadButton(button_str, Defaults::Controls::GAMEPAD_BUTTON_JUMP); } catch (...) { - gamepad_controls.button_jump = GameDefaults::GAMEPAD_BUTTON_JUMP; + gamepad_controls.button_jump = Defaults::Controls::GAMEPAD_BUTTON_JUMP; } } } @@ -471,7 +471,7 @@ void setConfigFile(const std::string& path) { // Carga las opciones desde el fichero configurado auto loadFromFile() -> bool { // Versión esperada del fichero - const std::string CONFIG_VERSION = GameDefaults::VERSION; + const std::string CONFIG_VERSION = Texts::VERSION; version = ""; // Intenta abrir y leer el fichero @@ -558,7 +558,7 @@ auto saveToFile() -> bool { // VERSION file << "# VERSION \n"; - file << "version: \"" << GameDefaults::VERSION << "\"\n"; + file << "version: \"" << Texts::VERSION << "\"\n"; file << "\n"; // WINDOW diff --git a/source/game/options.hpp b/source/game/options.hpp index 4c188b0..a9d9a00 100644 --- a/source/game/options.hpp +++ b/source/game/options.hpp @@ -16,9 +16,9 @@ namespace Options { // Estructura para las opciones de control de teclado struct KeyboardControls { - SDL_Scancode key_left{GameDefaults::CONTROL_KEY_LEFT}; // Tecla para mover a la izquierda - SDL_Scancode key_right{GameDefaults::CONTROL_KEY_RIGHT}; // Tecla para mover a la derecha - SDL_Scancode key_jump{GameDefaults::CONTROL_KEY_JUMP}; // Tecla para saltar + SDL_Scancode key_left{Defaults::Controls::KEY_LEFT}; // Tecla para mover a la izquierda + SDL_Scancode key_right{Defaults::Controls::KEY_RIGHT}; // Tecla para mover a la derecha + SDL_Scancode key_jump{Defaults::Controls::KEY_JUMP}; // Tecla para saltar }; // Estructura para las opciones de control del gamepad/joystick @@ -29,9 +29,9 @@ struct KeyboardControls { // - 200: Left stick X axis (negativo = izquierda) // - 201: Left stick X axis (positivo = derecha) struct GamepadControls { - int button_left{GameDefaults::GAMEPAD_BUTTON_LEFT}; // Botón para mover a la izquierda (por defecto: DPAD_LEFT) - int button_right{GameDefaults::GAMEPAD_BUTTON_RIGHT}; // Botón para mover a la derecha (por defecto: DPAD_RIGHT) - int button_jump{GameDefaults::GAMEPAD_BUTTON_JUMP}; // Botón para saltar (por defecto: WEST/X button) + int button_left{Defaults::Controls::GAMEPAD_BUTTON_LEFT}; // Botón para mover a la izquierda (por defecto: DPAD_LEFT) + int button_right{Defaults::Controls::GAMEPAD_BUTTON_RIGHT}; // Botón para mover a la derecha (por defecto: DPAD_RIGHT) + int button_jump{Defaults::Controls::GAMEPAD_BUTTON_JUMP}; // Botón para saltar (por defecto: WEST/X button) }; // Estructura para albergar trucos @@ -41,10 +41,10 @@ struct Cheat { ENABLED = true }; - State infinite_lives{GameDefaults::CHEAT_INFINITE_LIVES ? State::ENABLED : State::DISABLED}; // Indica si el jugador dispone de vidas infinitas - State invincible{GameDefaults::CHEAT_INVINCIBLE ? State::ENABLED : State::DISABLED}; // Indica si el jugador puede morir - State jail_is_open{GameDefaults::CHEAT_JAIL_IS_OPEN ? State::ENABLED : State::DISABLED}; // Indica si la Jail está abierta - State alternate_skin{GameDefaults::CHEAT_ALTERNATE_SKIN ? State::ENABLED : State::DISABLED}; // Indica si se usa una skin diferente para el jugador + State infinite_lives{Defaults::Cheat::INFINITE_LIVES ? State::ENABLED : State::DISABLED}; // Indica si el jugador dispone de vidas infinitas + State invincible{Defaults::Cheat::INVINCIBLE ? State::ENABLED : State::DISABLED}; // Indica si el jugador puede morir + State jail_is_open{Defaults::Cheat::JAIL_IS_OPEN ? State::ENABLED : State::DISABLED}; // Indica si la Jail está abierta + State alternate_skin{Defaults::Cheat::ALTERNATE_SKIN ? State::ENABLED : State::DISABLED}; // Indica si se usa una skin diferente para el jugador // Método para comprobar si alguno de los tres primeros trucos está activo [[nodiscard]] auto enabled() const -> bool { @@ -56,62 +56,62 @@ struct Cheat { // Estructura para almacenar estadísticas struct Stats { - int rooms{GameDefaults::STATS_ROOMS}; // Cantidad de habitaciones visitadas - int items{GameDefaults::STATS_ITEMS}; // Cantidad de items obtenidos - std::string worst_nightmare{GameDefaults::STATS_WORST_NIGHTMARE}; // Habitación con más muertes acumuladas + int rooms{Defaults::Stats::ROOMS}; // Cantidad de habitaciones visitadas + int items{Defaults::Stats::ITEMS}; // Cantidad de items obtenidos + std::string worst_nightmare{Defaults::Stats::WORST_NIGHTMARE}; // Habitación con más muertes acumuladas }; // Estructura con opciones de la ventana struct Window { - std::string caption{WINDOW_CAPTION}; // Texto que aparece en la barra de título de la ventana - int zoom{GameDefaults::WINDOW_ZOOM}; // Zoom de la ventana - int max_zoom{GameDefaults::WINDOW_ZOOM}; // Máximo tamaño de zoom para la ventana + std::string caption{Texts::WINDOW_CAPTION}; // Texto que aparece en la barra de título de la ventana + int zoom{Defaults::Window::ZOOM}; // Zoom de la ventana + int max_zoom{Defaults::Window::ZOOM}; // Máximo tamaño de zoom para la ventana }; // Estructura para gestionar el borde de la pantalla struct Border { - bool enabled{GameDefaults::BORDER_ENABLED}; // Indica si se ha de mostrar el borde - float width{GameDefaults::BORDER_WIDTH}; // Ancho del borde - float height{GameDefaults::BORDER_HEIGHT}; // Alto del borde + bool enabled{Defaults::Border::ENABLED}; // Indica si se ha de mostrar el borde + float width{Defaults::Border::WIDTH}; // Ancho del borde + float height{Defaults::Border::HEIGHT}; // Alto del borde }; // Estructura para las opciones de video struct Video { - bool fullscreen{GameDefaults::VIDEO_FULLSCREEN}; // Contiene el valor del modo de pantalla completa - Screen::Filter filter{GameDefaults::VIDEO_FILTER}; // Filtro usado para el escalado de la imagen - bool vertical_sync{GameDefaults::VIDEO_VERTICAL_SYNC}; // Indica si se quiere usar vsync o no - bool shaders{GameDefaults::VIDEO_SHADERS}; // Indica si se van a usar shaders o no - bool integer_scale{GameDefaults::VIDEO_INTEGER_SCALE}; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa - bool keep_aspect{GameDefaults::VIDEO_KEEP_ASPECT}; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa + bool fullscreen{Defaults::Video::FULLSCREEN}; // Contiene el valor del modo de pantalla completa + Screen::Filter filter{Defaults::Video::FILTER}; // Filtro usado para el escalado de la imagen + bool vertical_sync{Defaults::Video::VERTICAL_SYNC}; // Indica si se quiere usar vsync o no + bool shaders{Defaults::Video::SHADERS}; // Indica si se van a usar shaders o no + bool integer_scale{Defaults::Video::INTEGER_SCALE}; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa + bool keep_aspect{Defaults::Video::KEEP_ASPECT}; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa Border border{}; // Borde de la pantalla - std::string palette{GameDefaults::PALETTE_NAME}; // Paleta de colores a usar en el juego + std::string palette{Defaults::Video::PALETTE_NAME}; // Paleta de colores a usar en el juego std::string info; // Información sobre el modo de vídeo }; // Estructura para las opciones de musica struct Music { - bool enabled{GameDefaults::MUSIC_ENABLED}; // Indica si la música suena o no - float volume{GameDefaults::MUSIC_VOLUME}; // Volumen al que suena la música + bool enabled{Defaults::Music::ENABLED}; // Indica si la música suena o no + float volume{Defaults::Music::VOLUME}; // Volumen al que suena la música }; // Estructura para las opciones de sonido struct Sound { - bool enabled{GameDefaults::SOUND_ENABLED}; // Indica si los sonidos suenan o no - float volume{GameDefaults::SOUND_VOLUME}; // Volumen al que suenan los sonidos (0 a 128 internamente) + bool enabled{Defaults::Sound::ENABLED}; // Indica si los sonidos suenan o no + float volume{Defaults::Sound::VOLUME}; // Volumen al que suenan los sonidos (0 a 128 internamente) }; // Estructura para las opciones de audio struct Audio { Music music{}; // Opciones para la música Sound sound{}; // Opciones para los efectos de sonido - bool enabled{GameDefaults::AUDIO_ENABLED}; // Indica si el audio está activo o no - float volume{GameDefaults::AUDIO_VOLUME}; // Volumen al que suenan el audio (0-128 internamente) + bool enabled{Defaults::Audio::ENABLED}; // Indica si el audio está activo o no + float volume{Defaults::Audio::VOLUME}; // Volumen al que suenan el audio (0-128 internamente) }; // Estructura para las opciones de juego struct Game { - float width{GameDefaults::GAME_WIDTH}; // Ancho de la resolucion del juego - float height{GameDefaults::GAME_HEIGHT}; // Alto de la resolucion del juego + float width{Defaults::Canvas::WIDTH}; // Ancho de la resolucion del juego + float height{Defaults::Canvas::HEIGHT}; // Alto de la resolucion del juego }; // --- Variables globales (inline C++17+) --- diff --git a/source/game/scenes/credits.cpp b/source/game/scenes/credits.cpp index 8c2d6a0..a47cba2 100644 --- a/source/game/scenes/credits.cpp +++ b/source/game/scenes/credits.cpp @@ -15,7 +15,7 @@ #include "core/system/global_events.hpp" // Para check #include "game/options.hpp" // Para Options, options, OptionsGame, Sectio... #include "game/scene_manager.hpp" // Para SceneManager -#include "utils/defines.hpp" // Para GAME_SPEED, PLAY_AREA_CENTER_X, PLAY_... +#include "utils/defines.hpp" // Para GAME_SPEED, PlayArea::CENTER_X, PLAY_... #include "utils/delta_timer.hpp" // Para DeltaTimer #include "utils/utils.hpp" // Para PaletteColor @@ -102,13 +102,13 @@ void Credits::fillTexture() { int pos_y = 0; for (const auto& t : texts_) { - text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, pos_y * SIZE, t.label, 1, t.color); + text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, pos_y * SIZE, t.label, 1, t.color); pos_y++; } // Escribe el corazón const int TEXT_LENGHT = text->length(texts_[22].label, 1) - text->length(" ", 1); // Se resta el ultimo caracter que es un espacio - const int POS_X = ((PLAY_AREA_WIDTH - TEXT_LENGHT) / 2) + TEXT_LENGHT; + const int POS_X = ((PlayArea::WIDTH - TEXT_LENGHT) / 2) + TEXT_LENGHT; text->writeColored(POS_X, 176, "}", static_cast(PaletteColor::BRIGHT_RED)); Screen::get()->setRendererSurface(previuos_renderer); diff --git a/source/game/scenes/ending2.cpp b/source/game/scenes/ending2.cpp index c1ddd75..99e2f73 100644 --- a/source/game/scenes/ending2.cpp +++ b/source/game/scenes/ending2.cpp @@ -16,7 +16,7 @@ #include "core/system/global_events.hpp" // Para check #include "game/options.hpp" // Para Options, options, OptionsGame, Sectio... #include "game/scene_manager.hpp" // Para SceneManager -#include "utils/defines.hpp" // Para GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y +#include "utils/defines.hpp" // Para GameCanvas::CENTER_X, GameCanvas::CENTER_Y #include "utils/delta_timer.hpp" // Para DeltaTimer #include "utils/utils.hpp" // Para PaletteColor, stringToColor @@ -153,7 +153,7 @@ void Ending2::updateState(float delta_time) { break; case EndingState::CREDITS: - if (texts_.back()->getPosY() <= GAMECANVAS_CENTER_Y) { + if (texts_.back()->getPosY() <= GameCanvas::CENTER_Y) { transitionToState(EndingState::POST_CREDITS); } break; @@ -394,7 +394,7 @@ void Ending2::createSpriteTexts() { // Determina la columna y la posición X del texto const float X = (i == sprite_list_.size() - 1) - ? (GAMECANVAS_CENTER_X - (W / 2)) + ? (GameCanvas::CENTER_X - (W / 2)) : ((i % 2 == 0 ? FIRST_COL : SECOND_COL) - (W / 2)); // Calcula la posición Y del texto en base a la posición y altura del sprite @@ -427,7 +427,7 @@ void Ending2::createTexts() { // Calcula constantes const float W = text->length(list[i], 1); const float H = text->getCharacterSize(); - const float X = GAMECANVAS_CENTER_X; + const float X = GameCanvas::CENTER_X; const float DX = -(W / 2); const float Y = Options::game.height + (text->getCharacterSize() * (i * TEXT_SPACING_MULTIPLIER)); @@ -456,7 +456,7 @@ void Ending2::createTexts() { // Calcula constantes const float W = text->length(list[i], 1); const float H = text->getCharacterSize(); - const float X = GAMECANVAS_CENTER_X; + const float X = GameCanvas::CENTER_X; const float DX = -(W / 2); const float Y = START + (text->getCharacterSize() * (i * TEXT_SPACING_MULTIPLIER)); diff --git a/source/game/scenes/ending2.hpp b/source/game/scenes/ending2.hpp index 429b613..1213503 100644 --- a/source/game/scenes/ending2.hpp +++ b/source/game/scenes/ending2.hpp @@ -6,7 +6,7 @@ #include // Para string #include // Para vector -#include "utils/defines.hpp" // Para GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR... +#include "utils/defines.hpp" // Para GameCanvas::WIDTH, GameCanvas::FIRST_QUAR... class SurfaceAnimatedSprite; // lines 9-9 class SurfaceMovingSprite; // lines 10-10 class DeltaTimer; @@ -36,13 +36,13 @@ class Ending2 { }; // --- Constantes --- - static constexpr int FIRST_COL = GAMECANVAS_FIRST_QUARTER_X + (GAMECANVAS_WIDTH / 16); // Primera columna por donde desfilan los sprites - static constexpr int SECOND_COL = GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16); // Segunda columna por donde desfilan los sprites - static constexpr int DIST_SPRITE_TEXT = 8; // Distancia entre el sprite y el texto que lo acompaña - static constexpr int DIST_SPRITE_SPRITE = 0; // Distancia entre dos sprites de la misma columna - static constexpr int INITIAL_Y_OFFSET = 40; // Offset inicial en Y para posicionar sprites - static constexpr int SCREEN_MESH_HEIGHT = 8; // Altura de la malla superior/inferior de la pantalla - static constexpr int TEXT_SPACING_MULTIPLIER = 2; // Multiplicador para espaciado entre líneas de texto + static constexpr int FIRST_COL = GameCanvas::FIRST_QUARTER_X + (GameCanvas::WIDTH / 16); // Primera columna por donde desfilan los sprites + static constexpr int SECOND_COL = GameCanvas::THIRD_QUARTER_X - (GameCanvas::WIDTH / 16); // Segunda columna por donde desfilan los sprites + static constexpr int DIST_SPRITE_TEXT = 8; // Distancia entre el sprite y el texto que lo acompaña + static constexpr int DIST_SPRITE_SPRITE = 0; // Distancia entre dos sprites de la misma columna + static constexpr int INITIAL_Y_OFFSET = 40; // Offset inicial en Y para posicionar sprites + static constexpr int SCREEN_MESH_HEIGHT = 8; // Altura de la malla superior/inferior de la pantalla + static constexpr int TEXT_SPACING_MULTIPLIER = 2; // Multiplicador para espaciado entre líneas de texto // Constantes de tiempo (basadas en tiempo real, no en frames) static constexpr float SPRITE_DESP_SPEED = -12.0F; // Velocidad de desplazamiento en pixels/segundo (era -0.2 px/frame @ 60fps) @@ -79,12 +79,12 @@ class Ending2 { std::unique_ptr delta_timer_; // Timer para time-based update // Variables de estado - State state_; // Controla el estado de la clase - float state_time_{0.0F}; // Tiempo acumulado en el estado actual + State state_; // Controla el estado de la clase + float state_time_{0.0F}; // Tiempo acumulado en el estado actual // Variables auxiliares - std::vector sprite_list_; // Lista con todos los sprites a dibujar - std::vector colors_; // Vector con los colores para el fade - float sprite_max_width_{0.0F}; // El valor de ancho del sprite más ancho - float sprite_max_height_{0.0F}; // El valor de alto del sprite más alto + std::vector sprite_list_; // Lista con todos los sprites a dibujar + std::vector colors_; // Vector con los colores para el fade + float sprite_max_width_{0.0F}; // El valor de ancho del sprite más ancho + float sprite_max_height_{0.0F}; // El valor de alto del sprite más alto }; diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index dfcfb4a..646fab0 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -23,7 +23,7 @@ #include "game/options.hpp" // Para Options, options, Cheat, SectionState #include "game/scene_manager.hpp" // Para SceneManager #include "game/ui/notifier.hpp" // Para Notifier, NotificationText, CHEEVO_NO... -#include "utils/defines.hpp" // Para TILE_SIZE, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM +#include "utils/defines.hpp" // Para Tile::SIZE, PlayArea::HEIGHT, RoomBorder::BOTTOM #include "utils/utils.hpp" // Para PaletteColor, stringToColor #ifdef _DEBUG @@ -39,10 +39,10 @@ Game::Game(Mode mode) mode_(mode), #ifdef _DEBUG current_room_("03.yaml"), - spawn_data_(Player::SpawnData(25 * TILE_SIZE, 13 * TILE_SIZE, 0, 0, 0, Player::State::ON_GROUND, SDL_FLIP_HORIZONTAL)) + spawn_data_(Player::SpawnData(25 * Tile::SIZE, 13 * Tile::SIZE, 0, 0, 0, Player::State::ON_GROUND, SDL_FLIP_HORIZONTAL)) #else current_room_("03.yaml"), - spawn_data_(Player::SpawnData(25 * TILE_SIZE, 13 * TILE_SIZE, 0, 0, 0, Player::State::ON_GROUND, SDL_FLIP_HORIZONTAL)) + spawn_data_(Player::SpawnData(25 * Tile::SIZE, 13 * Tile::SIZE, 0, 0, 0, Player::State::ON_GROUND, SDL_FLIP_HORIZONTAL)) #endif { // Crea objetos e inicializa variables @@ -197,19 +197,19 @@ void Game::renderDebugInfo() { auto surface = Screen::get()->getRendererSurface(); // Borra el marcador - SDL_FRect rect = {0, 18 * TILE_SIZE, PLAY_AREA_WIDTH, GAMECANVAS_HEIGHT - PLAY_AREA_HEIGHT}; + SDL_FRect rect = {0, 18 * Tile::SIZE, PlayArea::WIDTH, GameCanvas::HEIGHT - PlayArea::HEIGHT}; surface->fillRect(&rect, static_cast(PaletteColor::BLACK)); // Pinta la rejilla - /*for (int i = 0; i < PLAY_AREA_BOTTOM; i += 8) + /*for (int i = 0; i < PlayArea::BOTTOM; i += 8) { // Lineas horizontales - surface->drawLine(0, i, PLAY_AREA_RIGHT, i, static_cast(PaletteColor::BRIGHT_BLACK)); + surface->drawLine(0, i, PlayArea::RIGHT, i, static_cast(PaletteColor::BRIGHT_BLACK)); } - for (int i = 0; i < PLAY_AREA_RIGHT; i += 8) + for (int i = 0; i < PlayArea::RIGHT; i += 8) { // Lineas verticales - surface->drawLine(i, 0, i, PLAY_AREA_BOTTOM - 1, static_cast(PaletteColor::BRIGHT_BLACK)); + surface->drawLine(i, 0, i, PlayArea::BOTTOM - 1, static_cast(PaletteColor::BRIGHT_BLACK)); }*/ // Pinta el texto @@ -509,7 +509,7 @@ void Game::fillRoomNameTexture() { // Escribe el texto en la textura auto text = Resource::Cache::get()->getText("smb2"); - text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GAMECANVAS_CENTER_X, text->getCharacterSize() / 2, room_->getName(), 1, room_->getBGColor()); + text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GameCanvas::CENTER_X, text->getCharacterSize() / 2, room_->getName(), 1, room_->getBGColor()); // Deja el renderizador por defecto Screen::get()->setRendererSurface(previuos_renderer); @@ -586,7 +586,7 @@ void Game::createRoomNameTexture() { room_name_surface_ = std::make_shared(Options::game.width, text->getCharacterSize() * 2); // Establece el destino de la textura - room_name_rect_ = {.x = 0.0F, .y = PLAY_AREA_HEIGHT, .w = Options::game.width, .h = text->getCharacterSize() * 2.0F}; + room_name_rect_ = {.x = 0.0F, .y = PlayArea::HEIGHT, .w = Options::game.width, .h = text->getCharacterSize() * 2.0F}; } // Hace sonar la música diff --git a/source/game/scenes/game_over.cpp b/source/game/scenes/game_over.cpp index 83a6205..7fcc499 100644 --- a/source/game/scenes/game_over.cpp +++ b/source/game/scenes/game_over.cpp @@ -15,7 +15,7 @@ #include "core/system/global_events.hpp" // Para check #include "game/options.hpp" // Para Options, options, OptionsStats, Secti... #include "game/scene_manager.hpp" // Para SceneManager -#include "utils/defines.hpp" // Para GAMECANVAS_CENTER_X +#include "utils/defines.hpp" // Para GameCanvas::CENTER_X #include "utils/delta_timer.hpp" // Para DeltaTimer #include "utils/utils.hpp" // Para PaletteColor, stringToColor @@ -28,9 +28,9 @@ GameOver::GameOver() SceneManager::options = SceneManager::Options::NONE; // Inicializa las posiciones de los sprites usando las constantes - player_sprite_->setPosX(GAMECANVAS_CENTER_X + PLAYER_X_OFFSET); + player_sprite_->setPosX(GameCanvas::CENTER_X + PLAYER_X_OFFSET); player_sprite_->setPosY(TEXT_Y + SPRITE_Y_OFFSET); - tv_sprite_->setPosX(GAMECANVAS_CENTER_X - tv_sprite_->getWidth() - TV_X_OFFSET); + tv_sprite_->setPosX(GameCanvas::CENTER_X - tv_sprite_->getWidth() - TV_X_OFFSET); tv_sprite_->setPosY(TEXT_Y + SPRITE_Y_OFFSET); Screen::get()->setBorderColor(static_cast(PaletteColor::BLACK)); @@ -68,7 +68,7 @@ void GameOver::render() { auto text = Resource::Cache::get()->getText("smb2"); // Escribe el texto de GAME OVER - text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GAMECANVAS_CENTER_X, TEXT_Y, "G A M E O V E R", 1, color_); + text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GameCanvas::CENTER_X, TEXT_Y, "G A M E O V E R", 1, color_); // Dibuja los sprites (ya posicionados en el constructor, solo ajustamos Y) player_sprite_->setPosY(TEXT_Y + SPRITE_Y_OFFSET); @@ -78,12 +78,12 @@ void GameOver::render() { // Escribe el texto con las habitaciones y los items const std::string ITEMS_TEXT = 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 ROOMS_TEXT = std::to_string(Options::stats.rooms / 100) + std::to_string((Options::stats.rooms % 100) / 10) + std::to_string(Options::stats.rooms % 10); - text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GAMECANVAS_CENTER_X, TEXT_Y + ITEMS_Y_OFFSET, "ITEMS: " + ITEMS_TEXT, 1, color_); - text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GAMECANVAS_CENTER_X, TEXT_Y + ROOMS_Y_OFFSET, "ROOMS: " + ROOMS_TEXT, 1, color_); + text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GameCanvas::CENTER_X, TEXT_Y + ITEMS_Y_OFFSET, "ITEMS: " + ITEMS_TEXT, 1, color_); + text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GameCanvas::CENTER_X, TEXT_Y + ROOMS_Y_OFFSET, "ROOMS: " + ROOMS_TEXT, 1, color_); // Escribe el texto con "Tu peor pesadilla" - text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GAMECANVAS_CENTER_X, TEXT_Y + NIGHTMARE_TITLE_Y_OFFSET, "YOUR WORST NIGHTMARE IS", 1, color_); - text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GAMECANVAS_CENTER_X, TEXT_Y + NIGHTMARE_TEXT_Y_OFFSET, Options::stats.worst_nightmare, 1, color_); + text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GameCanvas::CENTER_X, TEXT_Y + NIGHTMARE_TITLE_Y_OFFSET, "YOUR WORST NIGHTMARE IS", 1, color_); + text->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, GameCanvas::CENTER_X, TEXT_Y + NIGHTMARE_TEXT_Y_OFFSET, Options::stats.worst_nightmare, 1, color_); // Vuelca el contenido del renderizador en pantalla Screen::get()->render(); diff --git a/source/game/scenes/title.cpp b/source/game/scenes/title.cpp index 7103cc9..ffbf508 100644 --- a/source/game/scenes/title.cpp +++ b/source/game/scenes/title.cpp @@ -17,7 +17,7 @@ #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 "utils/defines.hpp" // Para PLAY_AREA_CENTER_X, GAMECANVAS_WIDTH +#include "utils/defines.hpp" // Para PlayArea::CENTER_X, GameCanvas::WIDTH #include "utils/utils.hpp" // Para stringToColor, PaletteColor, playMusic // Constructor @@ -479,7 +479,7 @@ void Title::createCheevosTexture() { Screen::get()->setRendererSurface(previuos_renderer); // Crea el sprite para el listado de logros (usa la zona del menu) - cheevos_sprite_ = std::make_unique(cheevos_surface_, (GAMECANVAS_WIDTH - cheevos_surface_->getWidth()) / 2, MENU_ZONE_Y, cheevos_surface_->getWidth(), cheevos_surface_->getHeight()); + cheevos_sprite_ = std::make_unique(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_); } @@ -522,10 +522,10 @@ void Title::renderMainMenu() { const int TOTAL_HEIGHT = 3 * SPACING; // 3 espacios entre 4 items const int START_Y = MENU_CENTER_Y - (TOTAL_HEIGHT / 2); - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, START_Y, "1. PLAY", 1, COLOR); - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, START_Y + SPACING, "2. REDEFINE KEYBOARD", 1, COLOR); - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, START_Y + (2 * SPACING), "3. REDEFINE JOYSTICK", 1, COLOR); - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, START_Y + (3 * SPACING), "4. PROJECTS", 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y, "1. PLAY", 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y + SPACING, "2. REDEFINE KEYBOARD", 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y + (2 * SPACING), "3. REDEFINE JOYSTICK", 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y + (3 * SPACING), "4. PROJECTS", 1, COLOR); } // Dibuja el menu de logros @@ -674,11 +674,11 @@ void Title::renderKeyboardRemap() { // Mensaje principal: "PRESS KEY FOR [ACTION]" o "KEYS DEFINED" si completado if (remap_step_ >= 3) { - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, START_Y, "KEYS DEFINED", 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y, "KEYS DEFINED", 1, COLOR); } else { const std::string ACTION = getActionName(remap_step_); const std::string MESSAGE = "PRESS KEY FOR " + ACTION; - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, START_Y, MESSAGE, 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y, MESSAGE, 1, COLOR); } // Mostrar teclas ya capturadas (con espaciado de 2 líneas desde el mensaje principal) @@ -686,22 +686,22 @@ void Title::renderKeyboardRemap() { if (remap_step_ > 0) { const std::string LEFT_KEY = SDL_GetScancodeName(temp_keys_[0]); const std::string LEFT_MSG = "LEFT: " + LEFT_KEY; - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, KEYS_START_Y, LEFT_MSG, 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, KEYS_START_Y, LEFT_MSG, 1, COLOR); } if (remap_step_ > 1) { const std::string RIGHT_KEY = SDL_GetScancodeName(temp_keys_[1]); const std::string RIGHT_MSG = "RIGHT: " + RIGHT_KEY; - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, KEYS_START_Y + LINE_SPACING, RIGHT_MSG, 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, KEYS_START_Y + LINE_SPACING, RIGHT_MSG, 1, COLOR); } if (remap_step_ >= 3) { const std::string JUMP_KEY = SDL_GetScancodeName(temp_keys_[2]); const std::string JUMP_MSG = "JUMP: " + JUMP_KEY; - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, KEYS_START_Y + (2 * LINE_SPACING), JUMP_MSG, 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, KEYS_START_Y + (2 * LINE_SPACING), JUMP_MSG, 1, COLOR); } // Mensaje de error si existe (4 líneas después del inicio de las teclas) if (!remap_error_message_.empty()) { - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, KEYS_START_Y + (4 * LINE_SPACING), remap_error_message_, 1, ERROR_COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, KEYS_START_Y + (4 * LINE_SPACING), remap_error_message_, 1, ERROR_COLOR); } } @@ -723,11 +723,11 @@ void Title::renderJoystickRemap() { // Mensaje principal: "PRESS BUTTON FOR [ACTION]" o "BUTTONS DEFINED" si completado if (remap_step_ >= 3) { - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, START_Y, "BUTTONS DEFINED", 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y, "BUTTONS DEFINED", 1, COLOR); } else { const std::string ACTION = getActionName(remap_step_); const std::string MESSAGE = "PRESS BUTTON FOR " + ACTION; - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, START_Y, MESSAGE, 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, START_Y, MESSAGE, 1, COLOR); } // Mostrar botones ya capturados (con espaciado de 2 líneas desde el mensaje principal) @@ -735,22 +735,22 @@ void Title::renderJoystickRemap() { if (remap_step_ > 0) { const std::string LEFT_BTN = getButtonName(temp_buttons_[0]); const std::string LEFT_MSG = "LEFT: " + LEFT_BTN; - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, BUTTONS_START_Y, LEFT_MSG, 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, BUTTONS_START_Y, LEFT_MSG, 1, COLOR); } if (remap_step_ > 1) { const std::string RIGHT_BTN = getButtonName(temp_buttons_[1]); const std::string RIGHT_MSG = "RIGHT: " + RIGHT_BTN; - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, BUTTONS_START_Y + LINE_SPACING, RIGHT_MSG, 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, BUTTONS_START_Y + LINE_SPACING, RIGHT_MSG, 1, COLOR); } if (remap_step_ >= 3) { const std::string JUMP_BTN = getButtonName(temp_buttons_[2]); const std::string JUMP_MSG = "JUMP: " + JUMP_BTN; - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, BUTTONS_START_Y + (2 * LINE_SPACING), JUMP_MSG, 1, COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, BUTTONS_START_Y + (2 * LINE_SPACING), JUMP_MSG, 1, COLOR); } // Mensaje de error si existe (4 líneas después del inicio de los botones) if (!remap_error_message_.empty()) { - menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PLAY_AREA_CENTER_X, BUTTONS_START_Y + (4 * LINE_SPACING), remap_error_message_, 1, ERROR_COLOR); + menu_text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG, PlayArea::CENTER_X, BUTTONS_START_Y + (4 * LINE_SPACING), remap_error_message_, 1, ERROR_COLOR); } } diff --git a/source/utils/defines.hpp b/source/utils/defines.hpp index c8d2975..51028d9 100644 --- a/source/utils/defines.hpp +++ b/source/utils/defines.hpp @@ -2,54 +2,50 @@ #include -#include - -#include "utils/utils.hpp" - // Textos +namespace Texts { constexpr const char* WINDOW_CAPTION = "JailDoctor's Dilemma"; -constexpr const char* TEXT_COPYRIGHT = "@2022 JailDesigner"; - -// Velocidad del juego -constexpr Uint32 GAME_SPEED = 15; +constexpr const char* COPYRIGHT = "@2022 JailDesigner"; +constexpr const char* VERSION = "1.10"; // Versión por defecto +} // namespace Texts // Tamaño de bloque -constexpr int TILE_SIZE = 8; -constexpr int HALF_TILE = TILE_SIZE / 2; +namespace Tile { +constexpr int SIZE = 8; +constexpr int HALF_SIZE = SIZE / 2; +} // namespace Tile -// Tamaño de la pantalla virtual -constexpr int GAMECANVAS_WIDTH = 256; -constexpr int GAMECANVAS_HEIGHT = 192; +namespace PlayArea { +constexpr int TOP = (0 * Tile::SIZE); +constexpr int BOTTOM = (16 * Tile::SIZE); +constexpr int LEFT = (0 * Tile::SIZE); +constexpr int RIGHT = (32 * Tile::SIZE); +constexpr int WIDTH = RIGHT - LEFT; +constexpr int HEIGHT = BOTTOM - TOP; +constexpr int CENTER_X = LEFT + (WIDTH / 2); +constexpr int CENTER_FIRST_QUARTER_X = (WIDTH / 4); +constexpr int CENTER_THIRD_QUARTER_X = (WIDTH / 4) * 3; +constexpr int CENTER_Y = TOP + (HEIGHT / 2); +constexpr int FIRST_QUARTER_Y = HEIGHT / 4; +constexpr int THIRD_QUARTER_Y = (HEIGHT / 4) * 3; +} // namespace PlayArea -// Zona de juego -constexpr int PLAY_AREA_TOP = (0 * TILE_SIZE); -constexpr int PLAY_AREA_BOTTOM = (16 * TILE_SIZE); -constexpr int PLAY_AREA_LEFT = (0 * TILE_SIZE); -constexpr int PLAY_AREA_RIGHT = (32 * TILE_SIZE); -constexpr int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT; -constexpr int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP; -constexpr int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2); -constexpr int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4); -constexpr int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3; -constexpr int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2); -constexpr int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4; -constexpr int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3; +namespace GameCanvas { +constexpr int WIDTH = 256; +constexpr int HEIGHT = 192; +constexpr int CENTER_X = WIDTH / 2; +constexpr int FIRST_QUARTER_X = WIDTH / 4; +constexpr int THIRD_QUARTER_X = (WIDTH / 4) * 3; +constexpr int CENTER_Y = HEIGHT / 2; +constexpr int FIRST_QUARTER_Y = HEIGHT / 4; +constexpr int THIRD_QUARTER_Y = (HEIGHT / 4) * 3; +} // namespace GameCanvas -// Anclajes de pantalla -constexpr int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2; -constexpr int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4; -constexpr int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3; -constexpr int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2; -constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4; -constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3; +namespace Collision { +constexpr int NONE = -1; +} // namespace Collision -namespace Collision -{ - constexpr int NONE = -1; -} - -namespace Flip -{ - constexpr SDL_FlipMode LEFT = SDL_FLIP_HORIZONTAL; - constexpr SDL_FlipMode RIGHT = SDL_FLIP_NONE; -} \ No newline at end of file +namespace Flip { +constexpr SDL_FlipMode LEFT = SDL_FLIP_HORIZONTAL; +constexpr SDL_FlipMode RIGHT = SDL_FLIP_NONE; +} // namespace Flip \ No newline at end of file