diff --git a/source/core/rendering/text.cpp b/source/core/rendering/text.cpp index 60d0d24..71e4e79 100644 --- a/source/core/rendering/text.cpp +++ b/source/core/rendering/text.cpp @@ -240,7 +240,7 @@ void Text::writeColoredMono(int x, int y, const std::string& text, Uint8 color, } // Obtiene la longitud en pixels de una cadena monoespaciada -auto Text::lengthMono(const std::string& text, int cell_w) const -> int { +auto Text::lengthMono(const std::string& text, int cell_w) -> int { size_t pos = 0; int count = 0; while (pos < text.size()) { diff --git a/source/core/rendering/text.hpp b/source/core/rendering/text.hpp index a2d8f2c..134f3db 100644 --- a/source/core/rendering/text.hpp +++ b/source/core/rendering/text.hpp @@ -50,7 +50,7 @@ class Text { void writeColoredMono(int x, int y, const std::string& text, Uint8 color, int cell_w); // Escribe texto monoespaciado con color [[nodiscard]] auto length(const std::string& text, int kerning = 1) const -> int; // Obtiene la longitud en pixels de una cadena - [[nodiscard]] auto lengthMono(const std::string& text, int cell_w) const -> int; // Obtiene la longitud en pixels de una cadena monoespaciada + [[nodiscard]] static auto lengthMono(const std::string& text, int cell_w) -> int; // Obtiene la longitud en pixels de una cadena monoespaciada [[nodiscard]] auto getCharacterSize() const -> int; // Devuelve el tamaño del caracter [[nodiscard]] auto glyphWidth(uint32_t codepoint, int kerning = 0) const -> int; // Devuelve el ancho en pixels de un glifo [[nodiscard]] auto getGlyphClip(uint32_t codepoint) const -> SDL_FRect; // Devuelve el clip rect del glifo diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 6333c81..05c9969 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -223,7 +223,7 @@ void Player::moveHorizontal(float delta_time) { } const auto& tc = room_->getTileCollider(); - float new_x = x_ + vx_ * delta_time; + float new_x = x_ + (vx_ * delta_time); // Colisión con paredes if (vx_ < 0.0F) { @@ -431,9 +431,9 @@ void Player::transitionToState(State state) { // Bordes de pantalla // ============================================================================ -auto Player::handleBorders() -> Room::Border { - const float CENTER_X = x_ + WIDTH / 2.0F; - const float CENTER_Y = y_ + HEIGHT / 2.0F; +auto Player::handleBorders() const -> Room::Border { + const float CENTER_X = x_ + (WIDTH / 2.0F); + const float CENTER_Y = y_ + (HEIGHT / 2.0F); if (CENTER_X < PlayArea::LEFT) { return Room::Border::LEFT; } if (CENTER_X > PlayArea::RIGHT) { return Room::Border::RIGHT; } diff --git a/source/game/entities/player.hpp b/source/game/entities/player.hpp index 81c5217..c6e1a39 100644 --- a/source/game/entities/player.hpp +++ b/source/game/entities/player.hpp @@ -143,7 +143,7 @@ class Player { void syncSpriteAndCollider(); void placeSprite(); void animate(float delta_time); - auto handleBorders() -> Room::Border; + auto handleBorders() const -> Room::Border; // --- Inicialización --- void initSprite(const std::string& animations_path); diff --git a/source/game/gameplay/scoreboard.hpp b/source/game/gameplay/scoreboard.hpp index 321eca2..1a2bdf4 100644 --- a/source/game/gameplay/scoreboard.hpp +++ b/source/game/gameplay/scoreboard.hpp @@ -12,12 +12,12 @@ class Scoreboard { public: // Tipos anidados struct Data { - int items{0}; // Lleva la cuenta de los objetos recogidos - int lives{0}; // Lleva la cuenta de las vidas restantes del jugador - int rooms{0}; // Lleva la cuenta de las habitaciones visitadas - bool music{true}; // Indica si ha de sonar la música durante el juego - Uint8 color{0}; // Color para escribir el texto del marcador - Uint32 ini_clock{0}; // Tiempo inicial para calcular el tiempo transcurrido + int items{0}; // Lleva la cuenta de los objetos recogidos + int lives{0}; // Lleva la cuenta de las vidas restantes del jugador + int rooms{0}; // Lleva la cuenta de las habitaciones visitadas + bool music{true}; // Indica si ha de sonar la música durante el juego + Uint8 color{0}; // Color para escribir el texto del marcador + Uint32 ini_clock{0}; // Tiempo inicial para calcular el tiempo transcurrido }; // Métodos públicos diff --git a/source/game/gameplay/tile_collider.cpp b/source/game/gameplay/tile_collider.cpp index a7242ef..6bf008f 100644 --- a/source/game/gameplay/tile_collider.cpp +++ b/source/game/gameplay/tile_collider.cpp @@ -14,7 +14,7 @@ auto TileCollider::getTileAt(int tile_x, int tile_y) const -> Tile { if (tile_x < 0 || tile_x >= MW || tile_y < 0 || tile_y >= MH) { return Tile::EMPTY; } - int value = tile_map_[tile_y * MW + tile_x]; + int value = tile_map_[(tile_y * MW) + tile_x]; if (value >= 0 && value <= 5) { return static_cast(value); } @@ -30,7 +30,7 @@ auto TileCollider::isSolid(int tile_x, int tile_y) const -> bool { // SLOPE_L (\): alto a la izquierda, bajo a la derecha. surface = bottom - (7 - x_in_tile) // SLOPE_R (/): alto a la derecha, bajo a la izquierda. surface = bottom - x_in_tile auto TileCollider::getSlopeY(int tile_x, int tile_y, float px) const -> float { - float tile_bottom = static_cast((tile_y + 1) * TS - 1); + auto tile_bottom = static_cast(((tile_y + 1) * TS) - 1); float x_in_tile = px - static_cast(tile_x * TS); x_in_tile = std::clamp(x_in_tile, 0.0F, static_cast(TS - 1)); @@ -96,6 +96,7 @@ auto TileCollider::checkCeiling(float x, float y, float w) const -> float { // SLOPE: solo si los pies estaban por encima de la superficie Y el jugador no está // parcialmente dentro de otra slope (evita aterrizar al hacer drop-through // o al saltar a través de una slope desde abajo). +// NOLINTNEXTLINE(readability-function-cognitive-complexity) auto TileCollider::checkFloor(float x, float foot_y_current, float w, float foot_y_new) const -> FloorHit { int start_row = toTile(static_cast(foot_y_current)); int end_row = toTile(static_cast(foot_y_new)); @@ -115,7 +116,7 @@ auto TileCollider::checkFloor(float x, float foot_y_current, float w, float foot if (tile == Tile::WALL) { floor_y = static_cast(row * TS); } else if (tile == Tile::PASSABLE) { - float tile_top = static_cast(row * TS); + auto tile_top = static_cast(row * TS); // Solo cuenta como suelo si los pies estaban por encima antes del movimiento if (foot_y_current <= tile_top) { floor_y = tile_top; @@ -130,7 +131,7 @@ auto TileCollider::checkFloor(float x, float foot_y_current, float w, float foot } if (floor_y != Collision::NONE && (best.y == Collision::NONE || floor_y < best.y)) { - best = {floor_y, tile, col, row}; + best = {.y = floor_y, .type = tile, .tile_x = col, .tile_y = row}; } } } @@ -193,6 +194,7 @@ auto TileCollider::isInsideAnySlope(float x, float foot_y, float w) const -> boo // Busca una slope directamente debajo del jugador (para transición ground→slope). // Escanea la fila de los pies Y la fila superior: las slopes en escalera siempre // tienen el tile de entrada una fila arriba del suelo desde el que se accede. +// NOLINTNEXTLINE(readability-function-cognitive-complexity) auto TileCollider::checkSlopeBelow(float x, float foot_y, float w) const -> SlopeInfo { int foot_row = toTile(static_cast(foot_y)); int left_col = toTile(static_cast(x)); @@ -205,14 +207,14 @@ auto TileCollider::checkSlopeBelow(float x, float foot_y, float w) const -> Slop float foot_x = (col == left_col) ? x : x + w - 1; float slope_y = getSlopeY(col, row, foot_x); if (slope_y <= foot_y && slope_y >= foot_y - TS) { - return {true, Tile::SLOPE_L, col, row, slope_y}; + return {.on_slope = true, .type = Tile::SLOPE_L, .tile_x = col, .tile_y = row, .surface_y = slope_y}; } } if (tile == Tile::SLOPE_R) { float foot_x = (col == right_col) ? x + w - 1 : x; float slope_y = getSlopeY(col, row, foot_x); if (slope_y <= foot_y && slope_y >= foot_y - TS) { - return {true, Tile::SLOPE_R, col, row, slope_y}; + return {.on_slope = true, .type = Tile::SLOPE_R, .tile_x = col, .tile_y = row, .surface_y = slope_y}; } } } diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index c3dce27..099af09 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -71,7 +71,6 @@ Game::Game(Mode mode) game_backbuffer_surface_ = std::make_shared(Options::game.width, Options::game.height); changeRoom(current_room_); - #ifdef _DEBUG Console::get()->setScope("debug"); #else @@ -331,7 +330,6 @@ void Game::updatePlaying(float delta_time) { checkPlayerAndEnemies(); checkIfPlayerIsAlive(); - // Avanzar transición if (transitioning_) { transition_timer_ += delta_time; @@ -906,7 +904,6 @@ void Game::togglePause() { scoreboard_->setPaused(paused_); } - // Inicializa al jugador void Game::initPlayer(const Player::SpawnData& spawn_point, std::shared_ptr room) { // NOLINT(readability-convert-member-functions-to-static) const bool IGNORE_INPUT = player_ != nullptr && player_->getIgnoreInput(); diff --git a/source/game/scenes/title.hpp b/source/game/scenes/title.hpp index 2308d9d..dee9012 100644 --- a/source/game/scenes/title.hpp +++ b/source/game/scenes/title.hpp @@ -31,9 +31,9 @@ class Title { }; // --- Constantes de tiempo (en segundos) --- - 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 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 // --- Métodos --- void handleEvents(); // Comprueba el manejador de eventos void handleMainMenuKeyPress(SDL_Keycode key); // Maneja las teclas del menu principal diff --git a/source/main.cpp b/source/main.cpp index 5f56ae0..98ae8fd 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -13,7 +13,7 @@ Empezado en Castalla el 01/07/2022. #include "core/system/director.hpp" #include "core/system/event_buffer.hpp" -SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) { +auto SDL_AppInit(void** appstate, int argc, char* argv[]) -> SDL_AppResult { (void)argc; (void)argv; @@ -22,13 +22,13 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) { return SDL_APP_CONTINUE; } -SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) { +auto SDL_AppEvent(void* appstate, SDL_Event* event) -> SDL_AppResult { (void)appstate; EventBuffer::events.push_back(*event); return SDL_APP_CONTINUE; } -SDL_AppResult SDL_AppIterate(void* appstate) { +auto SDL_AppIterate(void* appstate) -> SDL_AppResult { auto* director = static_cast(appstate); return director->iterate(); } diff --git a/source/utils/color.cpp b/source/utils/color.cpp index 52165cf..3c8b2ab 100644 --- a/source/utils/color.cpp +++ b/source/utils/color.cpp @@ -12,39 +12,39 @@ auto Color::fromString(const std::string& name) -> Uint8 { // Incluye nombres oficiales del CPC y aliases para compatibilidad static const std::unordered_map COLOR_MAP = { // Transparente - {"transparent", index(Cpc::CLEAR)}, + {"transparent", getIndex(Cpc::CLEAR)}, // Colores oficiales Amstrad CPC - {"black", index(Cpc::BLACK)}, - {"blue", index(Cpc::BLUE)}, - {"bright_blue", index(Cpc::BRIGHT_BLUE)}, - {"red", index(Cpc::RED)}, - {"magenta", index(Cpc::MAGENTA)}, - {"mauve", index(Cpc::MAUVE)}, - {"bright_red", index(Cpc::BRIGHT_RED)}, - {"purple", index(Cpc::PURPLE)}, - {"bright_magenta", index(Cpc::BRIGHT_MAGENTA)}, - {"green", index(Cpc::GREEN)}, - {"cyan", index(Cpc::CYAN)}, - {"sky_blue", index(Cpc::SKY_BLUE)}, - {"yellow", index(Cpc::YELLOW)}, - {"white", index(Cpc::WHITE)}, - {"pastel_blue", index(Cpc::PASTEL_BLUE)}, - {"orange", index(Cpc::ORANGE)}, - {"pink", index(Cpc::PINK)}, - {"pastel_magenta", index(Cpc::PASTEL_MAGENTA)}, - {"bright_green", index(Cpc::BRIGHT_GREEN)}, - {"sea_green", index(Cpc::SEA_GREEN)}, - {"bright_cyan", index(Cpc::BRIGHT_CYAN)}, - {"lime", index(Cpc::LIME)}, - {"pastel_green", index(Cpc::PASTEL_GREEN)}, - {"pastel_cyan", index(Cpc::PASTEL_CYAN)}, - {"bright_yellow", index(Cpc::BRIGHT_YELLOW)}, - {"pastel_yellow", index(Cpc::PASTEL_YELLOW)}, - {"bright_white", index(Cpc::BRIGHT_WHITE)}, + {"black", getIndex(Cpc::BLACK)}, + {"blue", getIndex(Cpc::BLUE)}, + {"bright_blue", getIndex(Cpc::BRIGHT_BLUE)}, + {"red", getIndex(Cpc::RED)}, + {"magenta", getIndex(Cpc::MAGENTA)}, + {"mauve", getIndex(Cpc::MAUVE)}, + {"bright_red", getIndex(Cpc::BRIGHT_RED)}, + {"purple", getIndex(Cpc::PURPLE)}, + {"bright_magenta", getIndex(Cpc::BRIGHT_MAGENTA)}, + {"green", getIndex(Cpc::GREEN)}, + {"cyan", getIndex(Cpc::CYAN)}, + {"sky_blue", getIndex(Cpc::SKY_BLUE)}, + {"yellow", getIndex(Cpc::YELLOW)}, + {"white", getIndex(Cpc::WHITE)}, + {"pastel_blue", getIndex(Cpc::PASTEL_BLUE)}, + {"orange", getIndex(Cpc::ORANGE)}, + {"pink", getIndex(Cpc::PINK)}, + {"pastel_magenta", getIndex(Cpc::PASTEL_MAGENTA)}, + {"bright_green", getIndex(Cpc::BRIGHT_GREEN)}, + {"sea_green", getIndex(Cpc::SEA_GREEN)}, + {"bright_cyan", getIndex(Cpc::BRIGHT_CYAN)}, + {"lime", getIndex(Cpc::LIME)}, + {"pastel_green", getIndex(Cpc::PASTEL_GREEN)}, + {"pastel_cyan", getIndex(Cpc::PASTEL_CYAN)}, + {"bright_yellow", getIndex(Cpc::BRIGHT_YELLOW)}, + {"pastel_yellow", getIndex(Cpc::PASTEL_YELLOW)}, + {"bright_white", getIndex(Cpc::BRIGHT_WHITE)}, // Aliases para compatibilidad con archivos YAML existentes (Spectrum) - {"bright_black", index(Cpc::BLACK)}, // No existe en CPC, mapea a negro + {"bright_black", getIndex(Cpc::BLACK)}, // No existe en CPC, mapea a negro }; auto it = COLOR_MAP.find(name); @@ -53,5 +53,5 @@ auto Color::fromString(const std::string& name) -> Uint8 { } // Si no se encuentra, devuelve negro por defecto - return index(Cpc::BLACK); + return getIndex(Cpc::BLACK); } diff --git a/source/utils/color.hpp b/source/utils/color.hpp index 5bad808..4aa9da0 100644 --- a/source/utils/color.hpp +++ b/source/utils/color.hpp @@ -78,7 +78,7 @@ class Color { * @param color Color del enum Cpc * @return Índice de paleta (Uint8) */ - static constexpr auto index(Cpc color) -> Uint8 { + static constexpr auto getIndex(Cpc color) -> Uint8 { // NOLINT(readability-identifier-naming) return static_cast(color); } diff --git a/source/utils/utils.hpp b/source/utils/utils.hpp index 947e79d..c3ea62c 100644 --- a/source/utils/utils.hpp +++ b/source/utils/utils.hpp @@ -26,11 +26,11 @@ struct Rgb { }; // COLISIONES Y GEOMETRÍA -auto distanceSquared(int x1, int y1, int x2, int y2) -> double; // Distancia² entre dos puntos -auto checkCollision(const Circle& a, const Circle& b) -> bool; // Colisión círculo-círculo -auto checkCollision(const Circle& a, const SDL_FRect& rect) -> bool; // Colisión círculo-rectángulo -auto checkCollision(const SDL_FRect& a, const SDL_FRect& b) -> bool; // Colisión rectángulo-rectángulo -auto checkCollision(const SDL_FPoint& p, const SDL_FRect& r) -> bool; // Colisión punto-rectángulo +auto distanceSquared(int x1, int y1, int x2, int y2) -> double; // Distancia² entre dos puntos +auto checkCollision(const Circle& a, const Circle& b) -> bool; // Colisión círculo-círculo +auto checkCollision(const Circle& a, const SDL_FRect& rect) -> bool; // Colisión círculo-rectángulo +auto checkCollision(const SDL_FRect& a, const SDL_FRect& b) -> bool; // Colisión rectángulo-rectángulo +auto checkCollision(const SDL_FPoint& p, const SDL_FRect& r) -> bool; // Colisión punto-rectángulo // CONVERSIONES DE TIPOS SDL auto toSDLRect(const SDL_FRect& frect) -> SDL_Rect; // Convierte SDL_FRect a SDL_Rect auto toSDLPoint(const SDL_FPoint& fpoint) -> SDL_Point; // Convierte SDL_FPoint a SDL_Point