revisat intro.cpp, path_sprite i writer.cpp

This commit is contained in:
2025-09-23 11:13:15 +02:00
parent 720d286dcf
commit 5e73327b2f
10 changed files with 119 additions and 105 deletions

View File

@@ -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;
}
}