migracio de Title a time based

This commit is contained in:
2025-10-26 23:07:08 +01:00
parent fc17131455
commit 87370dd11d
12 changed files with 150 additions and 134 deletions

View File

@@ -7,6 +7,9 @@ project(jaildoctors_dilemma VERSION 1.00)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_STANDARD_REQUIRED True)
# Exportar comandos de compilación para herramientas de análisis
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Establece la política CMP0072 para indicar cómo se debe seleccionar la implementación de OpenGL. # Establece la política CMP0072 para indicar cómo se debe seleccionar la implementación de OpenGL.
# En este caso, se elige la opción "GLVND", que utiliza bibliotecas modernas y modulares (libOpenGL, libGLX), # En este caso, se elige la opción "GLVND", que utiliza bibliotecas modernas y modulares (libOpenGL, libGLX),
# en lugar de la biblioteca OpenGL clásica (libGL). Esto mejora la compatibilidad con drivers recientes # en lugar de la biblioteca OpenGL clásica (libGL). Esto mejora la compatibilidad con drivers recientes

View File

@@ -86,8 +86,8 @@ class Screen {
std::string fragment_shader_source_; // Almacena el fragment shader std::string fragment_shader_source_; // Almacena el fragment shader
DisplayMonitor display_monitor_; // Informacion de la pantalla DisplayMonitor display_monitor_; // Informacion de la pantalla
#ifdef DEBUG #ifdef _DEBUG
bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla bool show_debug_info_ = true; // Indica si ha de mostrar/ocultar la información de la pantalla
#else #else
bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
#endif #endif

View File

@@ -114,7 +114,7 @@ void JA_Update()
void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels) void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels)
{ {
#ifdef DEBUG #ifdef _DEBUG
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG); SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
#endif #endif

View File

@@ -30,7 +30,7 @@ Player::Player(const PlayerData& player)
under_feet_.resize(under_feet_.size() + 2, {0, 0}); under_feet_.resize(under_feet_.size() + 2, {0, 0});
feet_.resize(feet_.size() + 2, {0, 0}); feet_.resize(feet_.size() + 2, {0, 0});
#ifdef DEBUG #ifdef _DEBUG
debug_rect_x_ = {0, 0, 0, 0}; debug_rect_x_ = {0, 0, 0, 0};
debug_rect_y_ = {0, 0, 0, 0}; debug_rect_y_ = {0, 0, 0, 0};
debug_color_ = static_cast<Uint8>(PaletteColor::GREEN); debug_color_ = static_cast<Uint8>(PaletteColor::GREEN);
@@ -42,7 +42,7 @@ Player::Player(const PlayerData& player)
void Player::render() { void Player::render() {
sprite_->render(1, color_); sprite_->render(1, color_);
#ifdef DEBUG #ifdef _DEBUG
renderDebugInfo(); renderDebugInfo();
#endif #endif
} }
@@ -221,7 +221,7 @@ void Player::move() {
applyGravity(); // Aplica gravedad al jugador applyGravity(); // Aplica gravedad al jugador
checkState(); // Comprueba el estado del jugador checkState(); // Comprueba el estado del jugador
#ifdef DEBUG #ifdef _DEBUG
debug_color_ = static_cast<Uint8>(PaletteColor::GREEN); debug_color_ = static_cast<Uint8>(PaletteColor::GREEN);
#endif #endif
@@ -234,7 +234,7 @@ void Player::move() {
proj.h = HEIGHT_; proj.h = HEIGHT_;
proj.w = static_cast<int>(std::ceil(std::fabs(vx_))); // Para evitar que tenga un ancho de 0 pixels proj.w = static_cast<int>(std::ceil(std::fabs(vx_))); // Para evitar que tenga un ancho de 0 pixels
#ifdef DEBUG #ifdef _DEBUG
debug_rect_x_ = proj; debug_rect_x_ = proj;
#endif #endif
@@ -274,7 +274,7 @@ void Player::move() {
proj.h = HEIGHT_; proj.h = HEIGHT_;
proj.w = ceil(vx_); // Para evitar que tenga un ancho de 0 pixels proj.w = ceil(vx_); // Para evitar que tenga un ancho de 0 pixels
#ifdef DEBUG #ifdef _DEBUG
debug_rect_x_ = proj; debug_rect_x_ = proj;
#endif #endif
@@ -328,7 +328,7 @@ void Player::move() {
proj.h = static_cast<int>(std::ceil(std::fabs(vy_))); // Para evitar que tenga una altura de 0 pixels proj.h = static_cast<int>(std::ceil(std::fabs(vy_))); // Para evitar que tenga una altura de 0 pixels
proj.w = WIDTH_; proj.w = WIDTH_;
#ifdef DEBUG #ifdef _DEBUG
debug_rect_y_ = proj; debug_rect_y_ = proj;
#endif #endif
@@ -355,7 +355,7 @@ void Player::move() {
proj.h = ceil(vy_); // Para evitar que tenga una altura de 0 pixels proj.h = ceil(vy_); // Para evitar que tenga una altura de 0 pixels
proj.w = WIDTH_; proj.w = WIDTH_;
#ifdef DEBUG #ifdef _DEBUG
debug_rect_y_ = proj; debug_rect_y_ = proj;
#endif #endif
@@ -380,7 +380,7 @@ void Player::move() {
// Calcula la nueva posición // Calcula la nueva posición
y_ = POINT - HEIGHT_; y_ = POINT - HEIGHT_;
setState(PlayerState::STANDING); setState(PlayerState::STANDING);
#ifdef DEBUG #ifdef _DEBUG
debug_color_ = static_cast<Uint8>(PaletteColor::YELLOW); debug_color_ = static_cast<Uint8>(PaletteColor::YELLOW);
debug_point_ = {x_ + (WIDTH_ / 2), POINT}; debug_point_ = {x_ + (WIDTH_ / 2), POINT};
#endif #endif
@@ -388,7 +388,7 @@ void Player::move() {
// No está saltando y no hay colisón con una rampa // No está saltando y no hay colisón con una rampa
// Calcula la nueva posición // Calcula la nueva posición
y_ += vy_; y_ += vy_;
#ifdef DEBUG #ifdef _DEBUG
debug_color_ = static_cast<Uint8>(PaletteColor::RED); debug_color_ = static_cast<Uint8>(PaletteColor::RED);
#endif #endif
} }
@@ -403,7 +403,7 @@ void Player::move() {
placeSprite(); // Coloca el sprite en la nueva posición placeSprite(); // Coloca el sprite en la nueva posición
collider_box_ = getRect(); // Actualiza el rectangulo de colisión collider_box_ = getRect(); // Actualiza el rectangulo de colisión
#ifdef DEBUG #ifdef _DEBUG
Debug::get()->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h)); Debug::get()->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h));
Debug::get()->add("RECT_Y: " + std::to_string(debug_rect_y_.x) + "," + std::to_string(debug_rect_y_.y) + "," + std::to_string(debug_rect_y_.w) + "," + std::to_string(debug_rect_y_.h)); Debug::get()->add("RECT_Y: " + std::to_string(debug_rect_y_.x) + "," + std::to_string(debug_rect_y_.y) + "," + std::to_string(debug_rect_y_.w) + "," + std::to_string(debug_rect_y_.h));
#endif #endif
@@ -436,7 +436,7 @@ void Player::playJumpSound() {
JA_PlaySound(jumping_sound_[jumping_counter_ / 4]); JA_PlaySound(jumping_sound_[jumping_counter_ / 4]);
} }
#ifdef DEBUG #ifdef _DEBUG
Debug::get()->add("JUMP: " + std::to_string(jumping_counter_ / 4)); Debug::get()->add("JUMP: " + std::to_string(jumping_counter_ / 4));
#endif #endif
} }
@@ -447,7 +447,7 @@ void Player::playFallSound() {
JA_PlaySound(falling_sound_[std::min((falling_counter_ / 4), (int)falling_sound_.size() - 1)]); JA_PlaySound(falling_sound_[std::min((falling_counter_ / 4), (int)falling_sound_.size() - 1)]);
} }
#ifdef DEBUG #ifdef _DEBUG
Debug::get()->add("FALL: " + std::to_string(falling_counter_ / 4)); Debug::get()->add("FALL: " + std::to_string(falling_counter_ / 4));
#endif #endif
} }
@@ -470,7 +470,7 @@ bool Player::isOnFloor() {
on_slope_l = room_->checkLeftSlopes(&under_feet_[0]); on_slope_l = room_->checkLeftSlopes(&under_feet_[0]);
on_slope_r = room_->checkRightSlopes(&under_feet_[1]); on_slope_r = room_->checkRightSlopes(&under_feet_[1]);
#ifdef DEBUG #ifdef _DEBUG
if (on_floor) { if (on_floor) {
Debug::get()->add("ON_FLOOR"); Debug::get()->add("ON_FLOOR");
} }
@@ -498,7 +498,7 @@ bool Player::isOnAutoSurface() {
on_auto_surface |= room_->checkAutoSurfaces(&f); on_auto_surface |= room_->checkAutoSurfaces(&f);
} }
#ifdef DEBUG #ifdef _DEBUG
if (on_auto_surface) { if (on_auto_surface) {
Debug::get()->add("ON_AUTO_SURFACE"); Debug::get()->add("ON_AUTO_SURFACE");
} }
@@ -522,7 +522,7 @@ bool Player::isOnDownSlope() {
on_slope |= room_->checkLeftSlopes(&under_feet_[0]); on_slope |= room_->checkLeftSlopes(&under_feet_[0]);
on_slope |= room_->checkRightSlopes(&under_feet_[1]); on_slope |= room_->checkRightSlopes(&under_feet_[1]);
#ifdef DEBUG #ifdef _DEBUG
if (on_slope) { if (on_slope) {
Debug::get()->add("ON_DOWN_SLOPE"); Debug::get()->add("ON_DOWN_SLOPE");
} }
@@ -627,7 +627,7 @@ void Player::initSprite(const std::string& surface_path, const std::string& anim
sprite_->setCurrentAnimation("walk"); sprite_->setCurrentAnimation("walk");
} }
#ifdef DEBUG #ifdef _DEBUG
// Pinta la información de debug del jugador // Pinta la información de debug del jugador
void Player::renderDebugInfo() { void Player::renderDebugInfo() {
if (Debug::get()->getEnabled()) { if (Debug::get()->getEnabled()) {
@@ -653,4 +653,4 @@ void Player::renderDebugInfo() {
surface->putPixel(debug_point_.x, debug_point_.y, rand() % 16); surface->putPixel(debug_point_.x, debug_point_.y, rand() % 16);
} }
} }
#endif // DEBUG #endif // _DEBUG

View File

@@ -98,7 +98,7 @@ class Player {
int jumping_counter_ = 0; // Cuenta el tiempo de salto int jumping_counter_ = 0; // Cuenta el tiempo de salto
int falling_counter_ = 0; // Cuenta el tiempo de caida int falling_counter_ = 0; // Cuenta el tiempo de caida
#ifdef DEBUG #ifdef _DEBUG
SDL_FRect debug_rect_x_; // Rectangulo de desplazamiento para el modo debug SDL_FRect debug_rect_x_; // Rectangulo de desplazamiento para el modo debug
SDL_FRect debug_rect_y_; // Rectangulo de desplazamiento para el modo debug SDL_FRect debug_rect_y_; // Rectangulo de desplazamiento para el modo debug
Uint8 debug_color_; // Color del recuadro de debug del jugador Uint8 debug_color_; // Color del recuadro de debug del jugador
@@ -165,7 +165,7 @@ class Player {
// Inicializa el sprite del jugador // Inicializa el sprite del jugador
void initSprite(const std::string& texture_path, const std::string& animations_path); void initSprite(const std::string& texture_path, const std::string& animations_path);
#ifdef DEBUG #ifdef _DEBUG
// Pinta la información de debug del jugador // Pinta la información de debug del jugador
void renderDebugInfo(); void renderDebugInfo();
#endif #endif

View File

@@ -378,7 +378,7 @@ void Room::fillMapTexture() {
} }
} }
#ifdef DEBUG #ifdef _DEBUG
if (Debug::get()->getEnabled()) { if (Debug::get()->getEnabled()) {
auto surface = Screen::get()->getRendererSurface(); auto surface = Screen::get()->getRendererSurface();
@@ -432,7 +432,7 @@ void Room::fillMapTexture() {
} }
} }
#endif // DEBUG #endif // _DEBUG
Screen::get()->setRendererSurface(previuos_renderer); Screen::get()->setRendererSurface(previuos_renderer);
} }
@@ -443,7 +443,7 @@ void Room::renderMap() {
map_surface_->render(nullptr, &dest); map_surface_->render(nullptr, &dest);
// Dibuja los tiles animados // Dibuja los tiles animados
#ifdef DEBUG #ifdef _DEBUG
if (!Debug::get()->getEnabled()) { if (!Debug::get()->getEnabled()) {
renderAnimatedTiles(); renderAnimatedTiles();
} }
@@ -591,25 +591,25 @@ bool Room::itemCollision(SDL_FRect& rect) {
int Room::getSlopeHeight(SDL_FPoint p, TileType slope) { int Room::getSlopeHeight(SDL_FPoint p, TileType slope) {
// Calcula la base del tile // Calcula la base del tile
int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_; int base = ((p.y / TILE_SIZE_) * TILE_SIZE_) + TILE_SIZE_;
#ifdef DEBUG #ifdef _DEBUG
Debug::get()->add("BASE = " + std::to_string(base)); Debug::get()->add("BASE = " + std::to_string(base));
#endif #endif
// Calcula cuanto se ha entrado en el tile horizontalmente // Calcula cuanto se ha entrado en el tile horizontalmente
const int pos = (static_cast<int>(p.x) % TILE_SIZE_); // Esto da un valor entre 0 y 7 const int pos = (static_cast<int>(p.x) % TILE_SIZE_); // Esto da un valor entre 0 y 7
#ifdef DEBUG #ifdef _DEBUG
Debug::get()->add("POS = " + std::to_string(pos)); Debug::get()->add("POS = " + std::to_string(pos));
#endif #endif
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa // Se resta a la base la cantidad de pixeles pos en funcion de la rampa
if (slope == TileType::SLOPE_R) { if (slope == TileType::SLOPE_R) {
base -= pos + 1; base -= pos + 1;
#ifdef DEBUG #ifdef _DEBUG
Debug::get()->add("BASE_R = " + std::to_string(base)); Debug::get()->add("BASE_R = " + std::to_string(base));
#endif #endif
} else { } else {
base -= (TILE_SIZE_ - pos); base -= (TILE_SIZE_ - pos);
#ifdef DEBUG #ifdef _DEBUG
Debug::get()->add("BASE_L = " + std::to_string(base)); Debug::get()->add("BASE_L = " + std::to_string(base));
#endif #endif
} }

View File

@@ -20,7 +20,7 @@ bool setOptions(const std::string& var, const std::string& value);
// Crea e inicializa las opciones del programa // Crea e inicializa las opciones del programa
void init() { void init() {
#ifdef DEBUG #ifdef _DEBUG
console = true; console = true;
#else #else
console = false; console = false;

View File

@@ -37,7 +37,7 @@ enum class Options {
inline Scene current = Scene::LOGO; // Escena actual inline Scene current = Scene::LOGO; // Escena actual
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
#else #else
inline Scene current = Scene::LOADING_SCREEN; // Escena actual inline Scene current = Scene::TITLE; // Escena actual
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
#endif #endif

View File

@@ -1,5 +1,3 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/scenes/game.hpp" #include "game/scenes/game.hpp"
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
@@ -14,17 +12,18 @@
#include "core/resources/asset.hpp" // Para Asset #include "core/resources/asset.hpp" // Para Asset
#include "core/resources/resource.hpp" // Para ResourceRoom, Resource #include "core/resources/resource.hpp" // Para ResourceRoom, Resource
#include "core/system/debug.hpp" // Para Debug #include "core/system/debug.hpp" // Para Debug
#include "core/system/global_events.hpp" // Para check
#include "external/jail_audio.h" // Para JA_PauseMusic, JA_GetMusicState, JA_P... #include "external/jail_audio.h" // Para JA_PauseMusic, JA_GetMusicState, JA_P...
#include "game/gameplay/cheevos.hpp" // Para Cheevos #include "game/gameplay/cheevos.hpp" // Para Cheevos
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker #include "game/gameplay/item_tracker.hpp" // Para ItemTracker
#include "game/options.hpp" // Para Options, options, Cheat, SectionState
#include "game/gameplay/room.hpp" // Para Room, RoomData #include "game/gameplay/room.hpp" // Para Room, RoomData
#include "game/gameplay/room_tracker.hpp" // Para RoomTracker #include "game/gameplay/room_tracker.hpp" // Para RoomTracker
#include "game/gameplay/scoreboard.hpp" // Para ScoreboardData, Scoreboard #include "game/gameplay/scoreboard.hpp" // Para ScoreboardData, Scoreboard
#include "game/gameplay/stats.hpp" // Para Stats #include "game/gameplay/stats.hpp" // Para Stats
#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 "game/ui/notifier.hpp" // Para Notifier, NotificationText, CHEEVO_NO...
#include "utils/defines.hpp" // Para BLOCK, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM #include "utils/defines.hpp" // Para BLOCK, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM
#include "core/system/global_events.hpp" // Para check
#include "utils/utils.hpp" // Para PaletteColor, stringToColor #include "utils/utils.hpp" // Para PaletteColor, stringToColor
// Constructor // Constructor
@@ -34,7 +33,7 @@ Game::Game(GameMode mode)
room_tracker_(std::make_shared<RoomTracker>()), room_tracker_(std::make_shared<RoomTracker>()),
stats_(std::make_shared<Stats>(Asset::get()->get("stats.csv"), Asset::get()->get("stats_buffer.csv"))), stats_(std::make_shared<Stats>(Asset::get()->get("stats.csv"), Asset::get()->get("stats_buffer.csv"))),
mode_(mode), mode_(mode),
#ifdef DEBUG #ifdef _DEBUG
current_room_("03.room"), current_room_("03.room"),
spawn_point_(PlayerSpawn(25 * BLOCK, 13 * BLOCK, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL)) spawn_point_(PlayerSpawn(25 * BLOCK, 13 * BLOCK, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL))
#else #else
@@ -42,7 +41,7 @@ Game::Game(GameMode mode)
spawn_point_(PlayerSpawn(25 * BLOCK, 13 * BLOCK, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL)) spawn_point_(PlayerSpawn(25 * BLOCK, 13 * BLOCK, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL))
#endif #endif
{ {
#ifdef DEBUG #ifdef _DEBUG
Debug::get()->setEnabled(false); Debug::get()->setEnabled(false);
#endif #endif
@@ -73,7 +72,7 @@ void Game::checkEvents() {
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
globalEvents::check(event); globalEvents::check(event);
#ifdef DEBUG #ifdef _DEBUG
checkDebugEvents(event); checkDebugEvents(event);
#endif #endif
} }
@@ -123,7 +122,7 @@ void Game::update() {
// Comprueba el teclado // Comprueba el teclado
checkInput(); checkInput();
#ifdef DEBUG #ifdef _DEBUG
Debug::get()->clear(); Debug::get()->clear();
#endif #endif
@@ -147,7 +146,7 @@ void Game::update() {
Screen::get()->update(); Screen::get()->update();
#ifdef DEBUG #ifdef _DEBUG
updateDebugInfo(); updateDebugInfo();
#endif #endif
} }
@@ -169,7 +168,7 @@ void Game::render() {
scoreboard_->render(); scoreboard_->render();
renderBlackScreen(); renderBlackScreen();
#ifdef DEBUG #ifdef _DEBUG
// Debug info // Debug info
renderDebugInfo(); renderDebugInfo();
#endif #endif
@@ -178,7 +177,7 @@ void Game::render() {
Screen::get()->render(); Screen::get()->render();
} }
#ifdef DEBUG #ifdef _DEBUG
// Pasa la información de debug // Pasa la información de debug
void Game::updateDebugInfo() { void Game::updateDebugInfo() {
Debug::get()->add("X = " + std::to_string(static_cast<int>(player_->x_)) + ", Y = " + std::to_string(static_cast<int>(player_->y_))); Debug::get()->add("X = " + std::to_string(static_cast<int>(player_->x_)) + ", Y = " + std::to_string(static_cast<int>(player_->y_)));

View File

@@ -74,7 +74,7 @@ class Game {
// Comprueba los eventos de la cola // Comprueba los eventos de la cola
void checkEvents(); void checkEvents();
#ifdef DEBUG #ifdef _DEBUG
// Pone la información de debug en pantalla // Pone la información de debug en pantalla
void updateDebugInfo(); void updateDebugInfo();

View File

@@ -24,7 +24,11 @@ Title::Title()
title_logo_sprite_(std::make_shared<SurfaceSprite>(title_logo_surface_, 29, 9, title_logo_surface_->getWidth(), title_logo_surface_->getHeight())), title_logo_sprite_(std::make_shared<SurfaceSprite>(title_logo_surface_, 29, 9, title_logo_surface_->getWidth(), title_logo_surface_->getHeight())),
loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")), loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")),
loading_screen_sprite_(std::make_shared<SurfaceSprite>(loading_screen_surface_, 0, 0, loading_screen_surface_->getWidth(), loading_screen_surface_->getHeight())), loading_screen_sprite_(std::make_shared<SurfaceSprite>(loading_screen_surface_, 0, 0, loading_screen_surface_->getWidth(), loading_screen_surface_->getHeight())),
bg_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)) { bg_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
delta_timer_(std::make_unique<DeltaTimer>()),
state_time_(0.0f),
fade_accumulator_(0.0f),
current_delta_(0.0f) {
// Inicializa variables // Inicializa variables
state_ = SceneManager::options == SceneManager::Options::TITLE_WITH_LOADING_SCREEN ? TitleState::SHOW_LOADING_SCREEN : TitleState::SHOW_MENU; state_ = SceneManager::options == SceneManager::Options::TITLE_WITH_LOADING_SCREEN ? TitleState::SHOW_LOADING_SCREEN : TitleState::SHOW_MENU;
SceneManager::current = SceneManager::Scene::TITLE; SceneManager::current = SceneManager::Scene::TITLE;
@@ -51,7 +55,7 @@ void Title::initMarquee() {
for (int i = 0; i < (int)long_text_.length(); ++i) { for (int i = 0; i < (int)long_text_.length(); ++i) {
TitleLetter l; TitleLetter l;
l.letter = long_text_.substr(i, 1); l.letter = long_text_.substr(i, 1);
l.x = 256; l.x = 256.0f;
l.enabled = false; l.enabled = false;
letters_.push_back(l); letters_.push_back(l);
} }
@@ -89,18 +93,17 @@ void Title::checkEvents() {
void Title::checkInput() { void Title::checkInput() {
if (show_cheevos_) { if (show_cheevos_) {
if (Input::get()->checkInput(InputAction::DOWN, INPUT_ALLOW_REPEAT)) { if (Input::get()->checkInput(InputAction::DOWN, INPUT_ALLOW_REPEAT)) {
moveCheevosList(1); moveCheevosList(1, current_delta_);
} else if (Input::get()->checkInput(InputAction::UP, INPUT_ALLOW_REPEAT)) { } else if (Input::get()->checkInput(InputAction::UP, INPUT_ALLOW_REPEAT)) {
moveCheevosList(0); moveCheevosList(0, current_delta_);
} else if (Input::get()->checkInput(InputAction::ACCEPT, INPUT_DO_NOT_ALLOW_REPEAT)) { } else if (Input::get()->checkInput(InputAction::ACCEPT, INPUT_DO_NOT_ALLOW_REPEAT)) {
hideCheevosList(); hideCheevosList();
counter_ = 0;
} }
} }
if (Input::get()->checkInput(InputAction::ACCEPT, INPUT_DO_NOT_ALLOW_REPEAT)) { if (Input::get()->checkInput(InputAction::ACCEPT, INPUT_DO_NOT_ALLOW_REPEAT)) {
if (state_ == TitleState::SHOW_LOADING_SCREEN) { if (state_ == TitleState::SHOW_LOADING_SCREEN) {
state_ = TitleState::FADE_LOADING_SCREEN; transitionToState(TitleState::FADE_LOADING_SCREEN);
} }
} }
@@ -108,25 +111,26 @@ void Title::checkInput() {
} }
// Actualiza la marquesina // Actualiza la marquesina
void Title::updateMarquee() { void Title::updateMarquee(float delta_time) {
const auto TEXT = Resource::get()->getText("gauntlet"); const auto TEXT = Resource::get()->getText("gauntlet");
const float displacement = MARQUEE_SPEED * delta_time;
for (int i = 0; i < (int)letters_.size(); ++i) { for (int i = 0; i < (int)letters_.size(); ++i) {
if (letters_[i].enabled) { if (letters_[i].enabled) {
letters_[i].x -= marquee_speed_; letters_[i].x -= displacement;
if (letters_[i].x < -10) { if (letters_[i].x < -10.0f) {
letters_[i].enabled = false; letters_[i].enabled = false;
} }
} else { } else {
if (i > 0 && letters_[i - 1].x < 256 && letters_[i - 1].enabled) { if (i > 0 && letters_[i - 1].x < 256.0f && letters_[i - 1].enabled) {
letters_[i].enabled = true; letters_[i].enabled = true;
letters_[i].x = letters_[i - 1].x + TEXT->lenght(letters_[i - 1].letter) + 1; letters_[i].x = letters_[i - 1].x + TEXT->lenght(letters_[i - 1].letter) + 1.0f;
} }
} }
} }
// Comprueba si ha terminado la marquesina y la reinicia // Comprueba si ha terminado la marquesina y la reinicia
if (letters_[letters_.size() - 1].x < -10) { if (letters_[letters_.size() - 1].x < -10.0f) {
// Inicializa la marquesina // Inicializa la marquesina
initMarquee(); initMarquee();
} }
@@ -144,53 +148,61 @@ void Title::renderMarquee() {
// Actualiza las variables // Actualiza las variables
void Title::update() { void Title::update() {
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego // Obtener delta time
if (SDL_GetTicks() - ticks_ > GAME_SPEED) { current_delta_ = delta_timer_->tick();
// Actualiza el contador de ticks
ticks_ = SDL_GetTicks();
// Comprueba las entradas // Comprueba las entradas
checkInput(); checkInput();
// Actualiza la pantalla
Screen::get()->update(); Screen::get()->update();
// Incrementa el contador // Actualiza el estado actual
counter_++; updateState(current_delta_);
}
// Actualiza el estado actual
void Title::updateState(float delta_time) {
state_time_ += delta_time;
switch (state_) { switch (state_) {
case TitleState::SHOW_LOADING_SCREEN: case TitleState::SHOW_LOADING_SCREEN:
if (counter_ == 500) { if (state_time_ >= SHOW_LOADING_DURATION) {
counter_ = 0; transitionToState(TitleState::FADE_LOADING_SCREEN);
state_ = TitleState::FADE_LOADING_SCREEN;
} }
break; break;
case TitleState::FADE_LOADING_SCREEN: case TitleState::FADE_LOADING_SCREEN:
if (counter_ % 4 == 0) { fade_accumulator_ += delta_time;
if (fade_accumulator_ >= FADE_STEP_INTERVAL) {
fade_accumulator_ = 0.0f;
if (loading_screen_surface_->fadeSubPalette()) { if (loading_screen_surface_->fadeSubPalette()) {
counter_ = 0; transitionToState(TitleState::SHOW_MENU);
state_ = TitleState::SHOW_MENU;
} }
} }
break; break;
case TitleState::SHOW_MENU: case TitleState::SHOW_MENU:
// Actualiza la marquesina // Actualiza la marquesina
updateMarquee(); updateMarquee(delta_time);
// Si el contador alcanza cierto valor, termina la seccion // Si el tiempo alcanza el timeout, va a créditos
if (counter_ == 2200) { if (state_time_ >= AUTO_CREDITS_TIMEOUT && !show_cheevos_) {
if (!show_cheevos_) {
SceneManager::current = SceneManager::Scene::CREDITS; SceneManager::current = SceneManager::Scene::CREDITS;
SceneManager::options = SceneManager::Options::NONE; SceneManager::options = SceneManager::Options::NONE;
} }
}
break; break;
default: default:
break; break;
} }
} }
// Transiciona a un nuevo estado
void Title::transitionToState(TitleState new_state) {
state_ = new_state;
state_time_ = 0.0f;
fade_accumulator_ = 0.0f;
} }
// Dibuja en pantalla // Dibuja en pantalla
@@ -237,10 +249,14 @@ void Title::run() {
} }
// Desplaza la lista de logros // Desplaza la lista de logros
void Title::moveCheevosList(int direction) { void Title::moveCheevosList(int direction, float delta_time) {
// Calcula el desplazamiento basado en tiempo
const float displacement = CHEEVOS_SCROLL_SPEED * delta_time;
// Modifica la posición de la ventana de vista // Modifica la posición de la ventana de vista
constexpr int SPEED = 2; cheevos_surface_view_.y = direction == 0
cheevos_surface_view_.y = direction == 0 ? cheevos_surface_view_.y - SPEED : cheevos_surface_view_.y + SPEED; ? cheevos_surface_view_.y - displacement
: cheevos_surface_view_.y + displacement;
// Ajusta los limites // Ajusta los limites
const float BOTTOM = cheevos_surface_->getHeight() - cheevos_surface_view_.h; const float BOTTOM = cheevos_surface_->getHeight() - cheevos_surface_view_.h;

View File

@@ -5,14 +5,16 @@
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string #include <string> // Para string
#include <vector> // Para vector #include <vector> // Para vector
class SurfaceSprite; // lines 9-9
class Surface; // lines 10-10 #include "utils/delta_timer.hpp" // Para DeltaTimer
class SurfaceSprite; // Forward declaration
class Surface; // Forward declaration
class Title { class Title {
private: private:
struct TitleLetter { struct TitleLetter {
std::string letter; // Letra a escribir std::string letter; // Letra a escribir
int x; // Posición en el eje x float x; // Posición en el eje x (float para precisión con delta time)
bool enabled; // Solo se escriben y mueven si estan habilitadas bool enabled; // Solo se escriben y mueven si estan habilitadas
}; };
@@ -22,6 +24,13 @@ class Title {
SHOW_MENU SHOW_MENU
}; };
// --- Constantes de tiempo (en segundos) ---
static constexpr float SHOW_LOADING_DURATION = 5.0f; // Tiempo mostrando loading screen (antes 500 frames)
static constexpr float FADE_STEP_INTERVAL = 0.033f; // Intervalo entre pasos de fade (antes cada 4 frames)
static constexpr float AUTO_CREDITS_TIMEOUT = 22.0f; // Timeout para ir a créditos (antes 2200 frames)
static constexpr float MARQUEE_SPEED = 100.0f; // Velocidad de marquesina (pixels/segundo)
static constexpr float CHEEVOS_SCROLL_SPEED = 120.0f; // Velocidad de scroll de logros (pixels/segundo)
// Objetos y punteros // Objetos y punteros
std::shared_ptr<Surface> title_logo_surface_; // Textura con los graficos std::shared_ptr<Surface> title_logo_surface_; // Textura con los graficos
std::shared_ptr<SurfaceSprite> title_logo_sprite_; // SSprite para manejar la surface std::shared_ptr<SurfaceSprite> title_logo_sprite_; // SSprite para manejar la surface
@@ -31,39 +40,28 @@ class Title {
std::shared_ptr<Surface> cheevos_surface_; // Textura con la lista de logros std::shared_ptr<Surface> cheevos_surface_; // Textura con la lista de logros
std::shared_ptr<SurfaceSprite> cheevos_sprite_; // SSprite para manejar la surface con la lista de logros std::shared_ptr<SurfaceSprite> cheevos_sprite_; // SSprite para manejar la surface con la lista de logros
// Variables // --- Variables de estado ---
int counter_ = 0; // Contador std::unique_ptr<DeltaTimer> delta_timer_; // Timer para delta time
std::string long_text_; // Texto que aparece en la parte inferior del titulo std::string long_text_; // Texto que aparece en la parte inferior del titulo
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
std::vector<TitleLetter> letters_; // Vector con las letras de la marquesina std::vector<TitleLetter> letters_; // Vector con las letras de la marquesina
int marquee_speed_ = 2; // Velocidad de desplazamiento de la marquesina
bool show_cheevos_ = false; // Indica si se muestra por pantalla el listado de logros bool show_cheevos_ = false; // Indica si se muestra por pantalla el listado de logros
SDL_FRect cheevos_surface_view_; // Zona visible de la surface con el listado de logros SDL_FRect cheevos_surface_view_; // Zona visible de la surface con el listado de logros
TitleState state_; // Estado en el que se encuentra el bucle principal TitleState state_; // Estado en el que se encuentra el bucle principal
float state_time_; // Tiempo acumulado en el estado actual
float fade_accumulator_; // Acumulador para controlar el fade por tiempo
float current_delta_; // Delta time del frame actual
// Actualiza las variables // --- Funciones ---
void update(); void update(); // Actualiza las variables
void render(); // Dibuja en pantalla
// Dibuja en pantalla void checkEvents(); // Comprueba el manejador de eventos
void render(); void checkInput(); // Comprueba las entradas
void updateState(float delta_time); // Actualiza el estado actual
// Comprueba el manejador de eventos void transitionToState(TitleState new_state); // Transiciona a un nuevo estado
void checkEvents(); void initMarquee(); // Inicializa la marquesina
void updateMarquee(float delta_time); // Actualiza la marquesina (time-based)
// Comprueba las entradas void renderMarquee(); // Dibuja la marquesina
void checkInput(); void moveCheevosList(int direction, float delta_time); // Desplaza la lista de logros (time-based)
// Inicializa la marquesina
void initMarquee();
// Actualiza la marquesina
void updateMarquee();
// Dibuja la marquesina
void renderMarquee();
// Desplaza la lista de logros
void moveCheevosList(int direction);
// Rellena la surface de fondo con todos los gráficos // Rellena la surface de fondo con todos los gráficos
void fillSurface(); void fillSurface();