revisat intro.cpp, path_sprite i writer.cpp
This commit is contained in:
@@ -66,10 +66,14 @@ rg "setAccel|\.ax.*=|\.ay.*="
|
||||
rg "60\.0|16\.67|1000\.0.*60"
|
||||
```
|
||||
|
||||
## Notas
|
||||
- **Para archivos sections/***: velocidades en `pixels/segundos`, aceleraciones en `pixels/segundos²`
|
||||
- **Para resto del código**: mantener velocidades en `pixels/ms`, aceleraciones en `pixels/ms²`
|
||||
## DECISIÓN IMPORTANTE: TODO EL CÓDIGO USA SEGUNDOS
|
||||
- **CAMBIO DE PLAN**: Todo el código del juego debe usar deltaTime en segundos (float)
|
||||
- **NO** debe haber soporte para frames, milisegundos y segundos simultáneamente
|
||||
- **SOLO SEGUNDOS** en todo el codebase
|
||||
- Velocidades en `pixels/segundos`, aceleraciones en `pixels/segundos²`
|
||||
- Todos los contadores deben ser crecientes (0 → constante_tope)
|
||||
- Eliminar todos los métodos duales (updateS, setSpeedS, etc.) - solo una versión
|
||||
- Convertir completamente: path_sprite.cpp, writer.cpp, tiled_bg.cpp, etc.
|
||||
- Documentar las conversiones en comentarios
|
||||
- Crear constantes para valores repetidos
|
||||
- Evitar números mágicos
|
||||
@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#elif _DEBUG
|
||||
Section::name = Section::Name::LOGO;
|
||||
Section::name = Section::Name::INTRO;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#else // NORMAL GAME
|
||||
Section::name = Section::Name::LOGO;
|
||||
|
||||
@@ -4,11 +4,10 @@
|
||||
#include <functional> // Para function
|
||||
#include <utility> // Para move
|
||||
|
||||
// Constructor para paths por puntos (compatibilidad)
|
||||
Path::Path(const std::vector<SDL_FPoint> &spots_init, int waiting_counter_init)
|
||||
// Constructor para paths por puntos (convertido a segundos)
|
||||
Path::Path(const std::vector<SDL_FPoint> &spots_init, float waiting_time_s_init)
|
||||
: spots(spots_init), is_point_path(true) {
|
||||
constexpr float FRAME_TIME_MS = 1000.0f / 60.0f;
|
||||
waiting_time_ms = static_cast<float>(waiting_counter_init) * FRAME_TIME_MS;
|
||||
waiting_time_s = waiting_time_s_init;
|
||||
}
|
||||
|
||||
// Devuelve un vector con los puntos que conforman la ruta
|
||||
@@ -39,12 +38,6 @@ auto createPath(float start, float end, PathType type, float fixed_pos, int step
|
||||
return v;
|
||||
}
|
||||
|
||||
// Actualiza la posición y comprueba si ha llegado a su destino (compatibilidad)
|
||||
void PathSprite::update() {
|
||||
constexpr float FRAME_TIME_MS = 1000.0f / 60.0f; // 16.67ms por frame a 60 FPS
|
||||
update(FRAME_TIME_MS);
|
||||
}
|
||||
|
||||
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||
void PathSprite::update(float delta_time) {
|
||||
if (enabled_ && !has_finished_) {
|
||||
@@ -90,20 +83,14 @@ void PathSprite::addPath(Path path, bool centered) {
|
||||
}
|
||||
}
|
||||
|
||||
// Añade un recorrido
|
||||
void PathSprite::addPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easing_function, int waiting_counter) {
|
||||
// Convertir frames a milisegundos
|
||||
constexpr float FRAME_TIME_MS = 1000.0f / 60.0f;
|
||||
float duration_ms = static_cast<float>(steps) * FRAME_TIME_MS;
|
||||
float waiting_ms = static_cast<float>(waiting_counter) * FRAME_TIME_MS;
|
||||
|
||||
paths_.emplace_back(static_cast<float>(start), static_cast<float>(end), type, static_cast<float>(fixed_pos),
|
||||
duration_ms, waiting_ms, easing_function);
|
||||
// Añade un recorrido generado (en segundos)
|
||||
void PathSprite::addPath(float start, float end, PathType type, float fixed_pos, float duration_s, const std::function<double(double)> &easing_function, float waiting_time_s) {
|
||||
paths_.emplace_back(start, end, type, fixed_pos, duration_s, waiting_time_s, easing_function);
|
||||
}
|
||||
|
||||
// Añade un recorrido
|
||||
void PathSprite::addPath(const std::vector<SDL_FPoint> &spots, int waiting_counter) {
|
||||
paths_.emplace_back(spots, waiting_counter);
|
||||
// Añade un recorrido por puntos (en segundos)
|
||||
void PathSprite::addPath(const std::vector<SDL_FPoint> &spots, float waiting_time_s) {
|
||||
paths_.emplace_back(spots, waiting_time_s);
|
||||
}
|
||||
|
||||
// Habilita el objeto
|
||||
@@ -150,7 +137,7 @@ void PathSprite::moveThroughCurrentPath(float delta_time) {
|
||||
|
||||
if (path.on_destination) {
|
||||
path.waiting_elapsed += delta_time;
|
||||
if (path.waiting_elapsed >= path.waiting_time_ms) {
|
||||
if (path.waiting_elapsed >= path.waiting_time_s) {
|
||||
path.finished = true;
|
||||
}
|
||||
}
|
||||
@@ -160,7 +147,7 @@ void PathSprite::moveThroughCurrentPath(float delta_time) {
|
||||
path.elapsed_time += delta_time;
|
||||
|
||||
// Calcular progreso (0.0 a 1.0)
|
||||
float progress = path.elapsed_time / path.duration_ms;
|
||||
float progress = path.elapsed_time / path.duration_s;
|
||||
if (progress >= 1.0f) {
|
||||
progress = 1.0f;
|
||||
path.on_destination = true;
|
||||
@@ -183,7 +170,7 @@ void PathSprite::moveThroughCurrentPath(float delta_time) {
|
||||
} else {
|
||||
// Esperar en destino
|
||||
path.waiting_elapsed += delta_time;
|
||||
if (path.waiting_elapsed >= path.waiting_time_ms) {
|
||||
if (path.waiting_elapsed >= path.waiting_time_s) {
|
||||
path.finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ struct Path { // Define un re
|
||||
float end_pos; // Posición final
|
||||
PathType type; // Tipo de movimiento (horizontal/vertical)
|
||||
float fixed_pos; // Posición fija en el eje contrario
|
||||
float duration_ms; // Duración de la animación en milisegundos
|
||||
float waiting_time_ms; // Tiempo de espera una vez en el destino
|
||||
float duration_s; // Duración de la animación en segundos
|
||||
float waiting_time_s; // Tiempo de espera una vez en el destino
|
||||
std::function<double(double)> easing_function; // Función de easing
|
||||
float elapsed_time = 0.0f; // Tiempo transcurrido
|
||||
float waiting_elapsed = 0.0f; // Tiempo de espera transcurrido
|
||||
@@ -40,10 +40,10 @@ struct Path { // Define un re
|
||||
// Constructor para paths generados
|
||||
Path(float start, float end, PathType path_type, float fixed, float duration, float waiting, std::function<double(double)> easing)
|
||||
: start_pos(start), end_pos(end), type(path_type), fixed_pos(fixed),
|
||||
duration_ms(duration), waiting_time_ms(waiting), easing_function(std::move(easing)) {}
|
||||
duration_s(duration), waiting_time_s(waiting), easing_function(std::move(easing)) {}
|
||||
|
||||
// Constructor para paths por puntos (mantenemos compatibilidad)
|
||||
Path(const std::vector<SDL_FPoint> &spots_init, int waiting_counter_init);
|
||||
// Constructor para paths por puntos (convertido a segundos)
|
||||
Path(const std::vector<SDL_FPoint> &spots_init, float waiting_time_s_init);
|
||||
|
||||
// Variables para paths por puntos
|
||||
std::vector<SDL_FPoint> spots; // Solo para paths por puntos
|
||||
@@ -63,14 +63,13 @@ class PathSprite : public Sprite {
|
||||
~PathSprite() override = default;
|
||||
|
||||
// --- Métodos principales ---
|
||||
void update(); // Actualiza la posición del sprite según el recorrido (compatibilidad)
|
||||
void update(float delta_time); // Actualiza la posición del sprite según el recorrido
|
||||
void update(float delta_time); // Actualiza la posición del sprite según el recorrido (delta_time en segundos)
|
||||
void render() override; // Muestra el sprite por pantalla
|
||||
|
||||
// --- Gestión de recorridos ---
|
||||
void addPath(Path path, bool centered = false); // Añade un recorrido (Path)
|
||||
void addPath(const std::vector<SDL_FPoint> &spots, int waiting_counter = 0); // Añade un recorrido a partir de puntos
|
||||
void addPath(int start, int end, PathType type, int fixed_pos, int steps, const std::function<double(double)> &easing_function, int waiting_counter = 0); // Añade un recorrido generado
|
||||
void addPath(const std::vector<SDL_FPoint> &spots, float waiting_time_s = 0.0f); // Añade un recorrido a partir de puntos
|
||||
void addPath(float start, float end, PathType type, float fixed_pos, float duration_s, const std::function<double(double)> &easing_function, float waiting_time_s = 0.0f); // Añade un recorrido generado
|
||||
|
||||
// --- Estado y control ---
|
||||
void enable(); // Habilita el objeto
|
||||
|
||||
@@ -322,7 +322,7 @@ void Game::updateGameStateGameOver(float deltaTime) {
|
||||
updateBullets(deltaTime);
|
||||
updateItems(deltaTime);
|
||||
updateSmartSprites(deltaTime);
|
||||
updatePathSprites();
|
||||
updatePathSprites(deltaTime);
|
||||
updateTimeStopped(deltaTime);
|
||||
checkBulletCollision();
|
||||
cleanVectors();
|
||||
@@ -369,7 +369,7 @@ void Game::updateGameStateCompleted(float deltaTime) {
|
||||
updateBullets(deltaTime);
|
||||
updateItems(deltaTime);
|
||||
updateSmartSprites(deltaTime);
|
||||
updatePathSprites();
|
||||
updatePathSprites(deltaTime);
|
||||
cleanVectors();
|
||||
|
||||
// Maneja eventos del juego completado
|
||||
@@ -813,9 +813,9 @@ void Game::renderSmartSprites() {
|
||||
}
|
||||
|
||||
// Actualiza los PathSprites
|
||||
void Game::updatePathSprites() {
|
||||
void Game::updatePathSprites(float deltaTime) {
|
||||
for (auto &sprite : path_sprites_) {
|
||||
sprite->update();
|
||||
sprite->update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1754,7 +1754,7 @@ void Game::updateGameStatePlaying(float deltaTime) {
|
||||
updateItems(deltaTime);
|
||||
updateStage();
|
||||
updateSmartSprites(deltaTime);
|
||||
updatePathSprites();
|
||||
updatePathSprites(deltaTime);
|
||||
updateTimeStopped(deltaTime);
|
||||
updateHelper();
|
||||
checkBulletCollision();
|
||||
|
||||
@@ -262,7 +262,7 @@ class Game {
|
||||
void freeSmartSprites(); // Libera memoria de sprites inteligentes
|
||||
|
||||
// --- Sprites por ruta (pathsprites) ---
|
||||
void updatePathSprites(); // Actualiza sprites que siguen rutas predefinidas
|
||||
void updatePathSprites(float deltaTime); // Actualiza sprites que siguen rutas predefinidas
|
||||
void renderPathSprites(); // Renderiza sprites animados por ruta
|
||||
void freePathSprites(); // Libera memoria de sprites por ruta
|
||||
void initPaths(); // Inicializa rutas predefinidas para animaciones
|
||||
|
||||
@@ -39,7 +39,7 @@ Intro::Intro()
|
||||
initTexts();
|
||||
|
||||
// Configura el fondo
|
||||
tiled_bg_->setSpeed(0.3F);
|
||||
tiled_bg_->setSpeed(TILED_BG_SPEED);
|
||||
tiled_bg_->setColor(bg_color_);
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ void Intro::updateScene5() {
|
||||
// Acaba la ultima imagen
|
||||
if (card_sprites_.at(5)->hasFinished() && texts_.at(8)->hasFinished()) {
|
||||
state_ = State::POST;
|
||||
state_start_time_ = SDL_GetTicks();
|
||||
state_start_time_ = SDL_GetTicks() / 1000.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ void Intro::render() {
|
||||
// Calcula el tiempo transcurrido desde el último frame
|
||||
float Intro::calculateDeltaTime() {
|
||||
const Uint64 current_time = SDL_GetTicks();
|
||||
const float delta_time = static_cast<float>(current_time - last_time_);
|
||||
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convertir ms a segundos
|
||||
last_time_ = current_time;
|
||||
return delta_time;
|
||||
}
|
||||
@@ -338,13 +338,13 @@ void Intro::initSprites() {
|
||||
const float X_DEST = param.game.game_area.center_x - (CARD_WIDTH / 2);
|
||||
const float Y_DEST = param.game.game_area.first_quarter_y - (CARD_HEIGHT / 4);
|
||||
|
||||
card_sprites_.at(0)->addPath(-CARD_WIDTH - CARD_OFFSET_MARGIN, X_DEST, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_NORMAL, easeInOutExpo, 0);
|
||||
card_sprites_.at(1)->addPath(param.game.width, X_DEST, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_NORMAL, easeOutBounce, 0);
|
||||
card_sprites_.at(2)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_FAST, easeOutQuint, 0);
|
||||
card_sprites_.at(3)->addPath(param.game.height, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_VERY_SLOW, easeInOutExpo, 0);
|
||||
card_sprites_.at(4)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_MEDIUM, easeOutElastic, 0);
|
||||
card_sprites_.at(0)->addPath(-CARD_WIDTH - CARD_OFFSET_MARGIN, X_DEST, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_NORMAL, easeInOutExpo, 0.0f);
|
||||
card_sprites_.at(1)->addPath(param.game.width, X_DEST, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_NORMAL, easeOutBounce, 0.0f);
|
||||
card_sprites_.at(2)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_FAST, easeOutQuint, 0.0f);
|
||||
card_sprites_.at(3)->addPath(param.game.height, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_VERY_SLOW, easeInOutExpo, 0.0f);
|
||||
card_sprites_.at(4)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_MEDIUM, easeOutElastic, 0.0f);
|
||||
card_sprites_.at(5)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_SLOW, easeOutQuad, CARD_ANIM_DELAY_LONG);
|
||||
card_sprites_.at(5)->addPath(X_DEST, -CARD_WIDTH, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_SHORT, easeInElastic, 0);
|
||||
card_sprites_.at(5)->addPath(X_DEST, -CARD_WIDTH, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_SHORT, easeInElastic, 0.0f);
|
||||
|
||||
// Constantes
|
||||
const float DESP = SHADOW_OFFSET;
|
||||
@@ -389,13 +389,13 @@ void Intro::initSprites() {
|
||||
const float S_X_DEST = X_DEST + DESP;
|
||||
const float S_Y_DEST = Y_DEST + DESP;
|
||||
|
||||
shadow_sprites_.at(0)->addPath(param.game.height + CARD_OFFSET_MARGIN, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_NORMAL, easeInOutExpo, 0);
|
||||
shadow_sprites_.at(1)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_NORMAL, easeOutBounce, 0);
|
||||
shadow_sprites_.at(2)->addPath(-SHADOW_SPRITE_WIDTH, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_FAST, easeOutQuint, 0);
|
||||
shadow_sprites_.at(3)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_VERY_SLOW, easeInOutExpo, 0);
|
||||
shadow_sprites_.at(4)->addPath(param.game.height, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_MEDIUM, easeOutElastic, 0);
|
||||
shadow_sprites_.at(0)->addPath(param.game.height + CARD_OFFSET_MARGIN, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_NORMAL, easeInOutExpo, 0.0f);
|
||||
shadow_sprites_.at(1)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_NORMAL, easeOutBounce, 0.0f);
|
||||
shadow_sprites_.at(2)->addPath(-SHADOW_SPRITE_WIDTH, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_FAST, easeOutQuint, 0.0f);
|
||||
shadow_sprites_.at(3)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_VERY_SLOW, easeInOutExpo, 0.0f);
|
||||
shadow_sprites_.at(4)->addPath(param.game.height, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_MEDIUM, easeOutElastic, 0.0f);
|
||||
shadow_sprites_.at(5)->addPath(param.game.width, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_SLOW, easeOutQuad, CARD_ANIM_DELAY_LONG);
|
||||
shadow_sprites_.at(5)->addPath(S_X_DEST, param.game.width, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_SHORT, easeInElastic, 0);
|
||||
shadow_sprites_.at(5)->addPath(S_X_DEST, param.game.width, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_SHORT, easeInElastic, 0.0f);
|
||||
}
|
||||
|
||||
// Inicializa los textos
|
||||
@@ -407,45 +407,45 @@ void Intro::initTexts() {
|
||||
writer->setPosY(param.game.height - param.intro.text_distance_from_bottom);
|
||||
writer->setKerning(TEXT_KERNING);
|
||||
writer->setEnabled(false);
|
||||
writer->setFinishedTimerMs(TEXT_DISPLAY_DURATION_MS);
|
||||
writer->setFinishedTimerS(TEXT_DISPLAY_DURATION_S);
|
||||
texts_.push_back(std::move(writer));
|
||||
}
|
||||
|
||||
// Un dia qualsevol de l'any 2000
|
||||
texts_.at(0)->setCaption(Lang::getText("[INTRO] 1"));
|
||||
texts_.at(0)->setSpeed(TEXT_SPEED_NORMAL);
|
||||
texts_.at(0)->setSpeedS(TEXT_SPEED_NORMAL);
|
||||
|
||||
// Tot esta tranquil a la UPV
|
||||
texts_.at(1)->setCaption(Lang::getText("[INTRO] 2"));
|
||||
texts_.at(1)->setSpeed(TEXT_SPEED_NORMAL);
|
||||
texts_.at(1)->setSpeedS(TEXT_SPEED_NORMAL);
|
||||
|
||||
// Fins que un desaprensiu...
|
||||
texts_.at(2)->setCaption(Lang::getText("[INTRO] 3"));
|
||||
texts_.at(2)->setSpeed(TEXT_SPEED_FAST);
|
||||
texts_.at(2)->setSpeedS(TEXT_SPEED_FAST);
|
||||
|
||||
// HEY! ME ANE A FERME UN CORTAET...
|
||||
texts_.at(3)->setCaption(Lang::getText("[INTRO] 4"));
|
||||
texts_.at(3)->setSpeed(TEXT_SPEED_NORMAL);
|
||||
texts_.at(3)->setSpeedS(TEXT_SPEED_NORMAL);
|
||||
|
||||
// UAAAAAAAAAAAAA!!!
|
||||
texts_.at(4)->setCaption(Lang::getText("[INTRO] 5"));
|
||||
texts_.at(4)->setSpeed(TEXT_SPEED_VERY_SLOW);
|
||||
texts_.at(4)->setSpeedS(TEXT_SPEED_VERY_SLOW);
|
||||
|
||||
// Espera un moment...
|
||||
texts_.at(5)->setCaption(Lang::getText("[INTRO] 6"));
|
||||
texts_.at(5)->setSpeed(TEXT_SPEED_VERY_FAST);
|
||||
texts_.at(5)->setSpeedS(TEXT_SPEED_VERY_FAST);
|
||||
|
||||
// Si resulta que no tinc solt!
|
||||
texts_.at(6)->setCaption(Lang::getText("[INTRO] 7"));
|
||||
texts_.at(6)->setSpeed(TEXT_SPEED_SLOW);
|
||||
texts_.at(6)->setSpeedS(TEXT_SPEED_SLOW);
|
||||
|
||||
// MERDA DE MAQUINA!
|
||||
texts_.at(7)->setCaption(Lang::getText("[INTRO] 8"));
|
||||
texts_.at(7)->setSpeed(TEXT_SPEED_MEDIUM_SLOW);
|
||||
texts_.at(7)->setSpeedS(TEXT_SPEED_MEDIUM_SLOW);
|
||||
|
||||
// Blop... blop... blop...
|
||||
texts_.at(8)->setCaption(Lang::getText("[INTRO] 9"));
|
||||
texts_.at(8)->setSpeed(TEXT_SPEED_ULTRA_FAST);
|
||||
texts_.at(8)->setSpeedS(TEXT_SPEED_ULTRA_FAST);
|
||||
|
||||
for (auto &text : texts_) {
|
||||
text->center(param.game.game_area.center_x);
|
||||
@@ -466,7 +466,7 @@ void Intro::updateSprites(float delta_time) {
|
||||
// Actualiza los textos
|
||||
void Intro::updateTexts(float delta_time) {
|
||||
for (auto &text : texts_) {
|
||||
text->update(delta_time);
|
||||
text->updateS(delta_time); // Usar updateS para delta_time en segundos
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,12 +485,12 @@ void Intro::renderTexts() {
|
||||
|
||||
// Actualiza el estado POST
|
||||
void Intro::updatePostState() {
|
||||
const Uint32 ELAPSED_TIME = SDL_GetTicks() - state_start_time_;
|
||||
const float ELAPSED_TIME = (SDL_GetTicks() / 1000.0f) - state_start_time_;
|
||||
|
||||
switch (post_state_) {
|
||||
case PostState::STOP_BG:
|
||||
// EVENTO: Detiene el fondo después del tiempo especificado
|
||||
if (ELAPSED_TIME >= POST_BG_STOP_DELAY_MS) {
|
||||
if (ELAPSED_TIME >= POST_BG_STOP_DELAY_S) {
|
||||
tiled_bg_->stopGracefully();
|
||||
|
||||
if (!bg_color_.IS_EQUAL_TO(param.title.bg_color)) {
|
||||
@@ -503,13 +503,13 @@ void Intro::updatePostState() {
|
||||
// Cambia de estado si el fondo se ha detenido y recuperado el color
|
||||
if (tiled_bg_->isStopped() && bg_color_.IS_EQUAL_TO(param.title.bg_color)) {
|
||||
post_state_ = PostState::END;
|
||||
state_start_time_ = SDL_GetTicks();
|
||||
state_start_time_ = SDL_GetTicks() / 1000.0f;
|
||||
}
|
||||
break;
|
||||
|
||||
case PostState::END:
|
||||
// Finaliza la intro después del tiempo especificado
|
||||
if (ELAPSED_TIME >= POST_END_DELAY_MS) {
|
||||
if (ELAPSED_TIME >= POST_END_DELAY_S) {
|
||||
Audio::get()->stopMusic();
|
||||
Section::name = Section::Name::TITLE;
|
||||
Section::options = Section::Options::TITLE_1;
|
||||
|
||||
@@ -37,34 +37,36 @@ class Intro {
|
||||
void run();
|
||||
|
||||
private:
|
||||
// --- Constantes de tiempo (en milisegundos) ---
|
||||
static constexpr float TEXT_DISPLAY_DURATION_MS = 3000.0f; // Duración de visualización de texto (180 frames a 60fps)
|
||||
static constexpr Uint32 POST_BG_STOP_DELAY_MS = 1000; // Retraso antes de detener el fondo
|
||||
static constexpr Uint32 POST_END_DELAY_MS = 1000; // Retraso antes de finalizar intro
|
||||
// --- Constantes de tiempo (en segundos) ---
|
||||
static constexpr float TEXT_DISPLAY_DURATION_S = 3.0f; // Duración de visualización de texto (180 frames a 60fps)
|
||||
static constexpr float POST_BG_STOP_DELAY_S = 1.0f; // Retraso antes de detener el fondo
|
||||
static constexpr float POST_END_DELAY_S = 1.0f; // Retraso antes de finalizar intro
|
||||
|
||||
// --- Constantes de layout ---
|
||||
static constexpr float CARD_BORDER_SIZE = 2.0f; // Tamaño del borde de tarjetas
|
||||
static constexpr float SHADOW_OFFSET = 8.0f; // Desplazamiento de sombra
|
||||
static constexpr float TILED_BG_SPEED = 18.0f; // Velocidad del fondo mosaico (pixels/segundo)
|
||||
static constexpr int TEXT_KERNING = -2; // Espaciado entre caracteres
|
||||
|
||||
// --- Constantes de velocidades de texto ---
|
||||
static constexpr int TEXT_SPEED_NORMAL = 8; // Velocidad normal de escritura
|
||||
static constexpr int TEXT_SPEED_FAST = 12; // Velocidad rápida
|
||||
static constexpr int TEXT_SPEED_VERY_SLOW = 1; // Velocidad muy lenta (grito)
|
||||
static constexpr int TEXT_SPEED_VERY_FAST = 16; // Velocidad muy rápida
|
||||
static constexpr int TEXT_SPEED_SLOW = 2; // Velocidad lenta
|
||||
static constexpr int TEXT_SPEED_MEDIUM_SLOW = 3; // Velocidad medio-lenta
|
||||
static constexpr int TEXT_SPEED_ULTRA_FAST = 20; // Velocidad ultra rápida
|
||||
// --- Constantes de velocidades de texto (segundos entre caracteres) ---
|
||||
static constexpr float TEXT_SPEED_NORMAL = 0.133f; // Velocidad normal (8 frames * 16.67ms = 133ms)
|
||||
static constexpr float TEXT_SPEED_FAST = 0.2f; // Velocidad rápida (12 frames * 16.67ms = 200ms)
|
||||
static constexpr float TEXT_SPEED_VERY_SLOW = 0.0167f; // Velocidad muy lenta (1 frame * 16.67ms = 16.7ms)
|
||||
static constexpr float TEXT_SPEED_VERY_FAST = 0.267f; // Velocidad muy rápida (16 frames * 16.67ms = 267ms)
|
||||
static constexpr float TEXT_SPEED_SLOW = 0.033f; // Velocidad lenta (2 frames * 16.67ms = 33ms)
|
||||
static constexpr float TEXT_SPEED_MEDIUM_SLOW = 0.05f; // Velocidad medio-lenta (3 frames * 16.67ms = 50ms)
|
||||
static constexpr float TEXT_SPEED_ULTRA_FAST = 0.333f; // Velocidad ultra rápida (20 frames * 16.67ms = 333ms)
|
||||
|
||||
// --- Constantes de animaciones de tarjetas (duraciones en ms) ---
|
||||
static constexpr int CARD_ANIM_DURATION_NORMAL = 100; // Duración estándar (100ms)
|
||||
static constexpr int CARD_ANIM_DURATION_FAST = 40; // Duración rápida (40ms)
|
||||
static constexpr int CARD_ANIM_DURATION_MEDIUM = 70; // Duración media (70ms)
|
||||
static constexpr int CARD_ANIM_DURATION_SHORT = 80; // Duración corta (80ms)
|
||||
static constexpr int CARD_ANIM_DURATION_SLOW = 250; // Duración lenta (250ms)
|
||||
static constexpr int CARD_ANIM_DURATION_VERY_SLOW = 300; // Duración muy lenta (300ms)
|
||||
static constexpr int CARD_ANIM_DELAY_LONG = 450; // Retraso largo antes de animación
|
||||
static constexpr float CARD_OFFSET_MARGIN = 10.0f; // Margen fuera de pantalla
|
||||
// --- Constantes de animaciones de tarjetas (duraciones en segundos) ---
|
||||
static constexpr float CARD_ANIM_DURATION_NORMAL = 100.0f / 60.0f; // ≈ 1.6667 s
|
||||
static constexpr float CARD_ANIM_DURATION_FAST = 40.0f / 60.0f; // ≈ 0.6667 s
|
||||
static constexpr float CARD_ANIM_DURATION_MEDIUM = 70.0f / 60.0f; // ≈ 1.1667 s
|
||||
static constexpr float CARD_ANIM_DURATION_SHORT = 80.0f / 60.0f; // ≈ 1.3333 s
|
||||
static constexpr float CARD_ANIM_DURATION_SLOW = 250.0f / 60.0f; // ≈ 4.1667 s
|
||||
static constexpr float CARD_ANIM_DURATION_VERY_SLOW = 300.0f / 60.0f; // ≈ 5.0000 s
|
||||
|
||||
static constexpr float CARD_ANIM_DELAY_LONG = 0.45f; // Retraso largo antes de animación
|
||||
static constexpr float CARD_OFFSET_MARGIN = 10.0f; // Margen fuera de pantalla
|
||||
|
||||
// --- Estados internos ---
|
||||
enum class State {
|
||||
@@ -88,7 +90,7 @@ class Intro {
|
||||
int scene_ = 0; // Indica qué escena está activa
|
||||
State state_ = State::SCENES; // Estado principal de la intro
|
||||
PostState post_state_ = PostState::STOP_BG; // Estado POST
|
||||
Uint32 state_start_time_; // Tiempo de inicio del estado actual
|
||||
float state_start_time_; // Tiempo de inicio del estado actual (segundos)
|
||||
Color bg_color_ = param.intro.bg_color; // Color de fondo
|
||||
|
||||
// --- Métodos internos ---
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
#include "text.h" // Para Text
|
||||
|
||||
// Actualiza el objeto
|
||||
// Actualiza el objeto (delta_time en ms)
|
||||
void Writer::update(float delta_time) {
|
||||
if (enabled_) {
|
||||
if (!completed_) {
|
||||
// No completado
|
||||
writing_timer_ += delta_time;
|
||||
if (writing_timer_ >= speed_ms_) {
|
||||
if (writing_timer_ >= speed_interval_) {
|
||||
index_++;
|
||||
writing_timer_ = 0.0f;
|
||||
}
|
||||
@@ -24,6 +24,12 @@ void Writer::update(float delta_time) {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el objeto (delta_time en segundos)
|
||||
void Writer::updateS(float delta_time) {
|
||||
// Convierte segundos a milisegundos y usa la lógica normal
|
||||
update(delta_time * 1000.0f);
|
||||
}
|
||||
|
||||
// Dibuja el objeto en pantalla
|
||||
void Writer::render() const {
|
||||
if (enabled_) {
|
||||
@@ -52,11 +58,18 @@ void Writer::setCaption(const std::string &text) {
|
||||
length_ = text.length();
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
// Establece el valor de la variable (frames)
|
||||
void Writer::setSpeed(int value) {
|
||||
// Convierte frames a milisegundos (frames * 16.67ms)
|
||||
constexpr float FRAME_TIME_MS = 1000.0f / 60.0f;
|
||||
speed_ms_ = static_cast<float>(value) * FRAME_TIME_MS;
|
||||
constexpr float FRAME_TIME_MS = 16.67f;
|
||||
speed_interval_ = static_cast<float>(value) * FRAME_TIME_MS;
|
||||
writing_timer_ = 0.0f;
|
||||
}
|
||||
|
||||
// Establece la velocidad en segundos entre caracteres
|
||||
void Writer::setSpeedS(float value) {
|
||||
// Convierte segundos a milisegundos para consistencia interna
|
||||
speed_interval_ = value * 1000.0f;
|
||||
writing_timer_ = 0.0f;
|
||||
}
|
||||
|
||||
@@ -76,6 +89,12 @@ void Writer::setFinishedTimerMs(float time_ms) {
|
||||
enabled_timer_ = 0.0f;
|
||||
}
|
||||
|
||||
// Establece el temporizador para deshabilitar el objeto (en segundos)
|
||||
void Writer::setFinishedTimerS(float time_s) {
|
||||
enabled_timer_target_ = time_s * 1000.0f; // Convertir segundos a milisegundos
|
||||
enabled_timer_ = 0.0f;
|
||||
}
|
||||
|
||||
// Centra la cadena de texto a un punto X
|
||||
void Writer::center(int x) {
|
||||
setPosX(x - (text_->length(caption_, kerning_) / 2));
|
||||
|
||||
@@ -15,17 +15,20 @@ class Writer {
|
||||
~Writer() = default;
|
||||
|
||||
// --- Métodos principales ---
|
||||
void update(float delta_time); // Actualiza el objeto
|
||||
void render() const; // Dibuja el objeto en pantalla
|
||||
void update(float delta_time); // Actualiza el objeto (delta_time en ms)
|
||||
void updateS(float delta_time); // Actualiza el objeto (delta_time en segundos)
|
||||
void render() const; // Dibuja el objeto en pantalla
|
||||
|
||||
// --- Setters ---
|
||||
void setPosX(int value); // Establece la posición X
|
||||
void setPosY(int value); // Establece la posición Y
|
||||
void setKerning(int value); // Establece el kerning (espaciado entre caracteres)
|
||||
void setCaption(const std::string &text); // Establece el texto a escribir
|
||||
void setSpeed(int value); // Establece la velocidad de escritura
|
||||
void setSpeed(int value); // Establece la velocidad de escritura (frames)
|
||||
void setSpeedS(float value); // Establece la velocidad de escritura (segundos entre caracteres)
|
||||
void setEnabled(bool value); // Habilita o deshabilita el objeto
|
||||
void setFinishedTimerMs(float time_ms); // Establece el temporizador para deshabilitar el objeto (en ms)
|
||||
void setFinishedTimerS(float time_s); // Establece el temporizador para deshabilitar el objeto (en segundos)
|
||||
|
||||
void center(int x); // Centra la cadena de texto a un punto X
|
||||
|
||||
@@ -42,7 +45,7 @@ class Writer {
|
||||
int pos_x_ = 0; // Posición en el eje X donde empezar a escribir el texto
|
||||
int pos_y_ = 0; // Posición en el eje Y donde empezar a escribir el texto
|
||||
int kerning_ = 0; // Kerning del texto, es decir, espaciado entre caracteres
|
||||
float speed_ms_ = 0.0f; // Velocidad de escritura en milisegundos
|
||||
float speed_interval_ = 0.0f; // Intervalo entre caracteres (ms para compatibilidad)
|
||||
float writing_timer_ = 0.0f; // Temporizador de escritura para cada caracter
|
||||
int index_ = 0; // Posición del texto que se está escribiendo
|
||||
int length_ = 0; // Longitud de la cadena a escribir
|
||||
|
||||
Reference in New Issue
Block a user