From 300edc90b541b51628247af3d77790d70339a441 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 17 Oct 2025 14:02:40 +0200 Subject: [PATCH] PathSprite: ja permet createPath amb temps o frames --- source/path_sprite.cpp | 48 +++++++++++++++++++++++++++-------- source/sections/game.cpp | 55 ++++++++++++++++++++++++---------------- 2 files changed, 71 insertions(+), 32 deletions(-) diff --git a/source/path_sprite.cpp b/source/path_sprite.cpp index d0ad7ef..1407cf3 100644 --- a/source/path_sprite.cpp +++ b/source/path_sprite.cpp @@ -56,29 +56,57 @@ void PathSprite::render() { // Añade un recorrido void PathSprite::addPath(Path path, bool centered) { PathCentered path_centered = PathCentered::NONE; + if (centered) { - path_centered = (path.spots.back().x == path.spots.front().x) ? PathCentered::ON_X : PathCentered::ON_Y; + if (path.is_point_path) { + // Lógica de centrado para paths por PUNTOS (como antes) + if (!path.spots.empty()) { + // Si X es constante, es un path Vertical, centramos en X + path_centered = (path.spots.back().x == path.spots.front().x) ? PathCentered::ON_X : PathCentered::ON_Y; + } + } else { + // Lógica de centrado para paths GENERADOS (por duración) + // Si el tipo es Vertical, centramos en X + path_centered = (path.type == PathType::VERTICAL) ? PathCentered::ON_X : PathCentered::ON_Y; + } } switch (path_centered) { case PathCentered::ON_X: { - const int X = path.spots.back().x - (pos_.w / 2); - for (auto &spot : path.spots) { - spot.x = X; + // Centrar en el eje X (para paths Verticales) + const float X_offset = pos_.w / 2.0f; // Asume que pos_.w está inicializado por el constructor de Sprite + if (path.is_point_path) { + const float X_base = !path.spots.empty() ? path.spots.front().x : 0.0f; + const float X = X_base - X_offset; + for (auto &spot : path.spots) { + spot.x = X; + } + } else { + // Es un path generado, ajustamos la posición fija (que es X) + path.fixed_pos -= X_offset; } - paths_.emplace_back(path); + paths_.emplace_back(std::move(path)); // Usamos std::move break; } case PathCentered::ON_Y: { - const int Y = path.spots.back().y - (pos_.h / 2); - for (auto &spot : path.spots) { - spot.y = Y; + // Centrar en el eje Y (para paths Horizontales) + const float Y_offset = pos_.h / 2.0f; // Asume que pos_.h está inicializado + if (path.is_point_path) { + const float Y_base = !path.spots.empty() ? path.spots.front().y : 0.0f; + const float Y = Y_base - Y_offset; + for (auto &spot : path.spots) { + spot.y = Y; + } + } else { + // Es un path generado, ajustamos la posición fija (que es Y) + path.fixed_pos -= Y_offset; } - paths_.emplace_back(path); + paths_.emplace_back(std::move(path)); // Usamos std::move break; } default: - paths_.emplace_back(path); + // Sin centrado + paths_.emplace_back(std::move(path)); // Usamos std::move break; } } diff --git a/source/sections/game.cpp b/source/sections/game.cpp index db1b058..815ac8d 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -513,7 +513,6 @@ void Game::checkPlayerItemCollision(std::shared_ptr& player) { } } - // Maneja la colisión entre bala y Tabe auto Game::checkBulletTabeCollision(const std::shared_ptr& bullet) -> bool { if (!tabe_->isEnabled()) { @@ -600,7 +599,6 @@ void Game::handleBalloonDestruction(std::shared_ptr balloon, const std: updateHiScore(); } - // Actualiza los items void Game::updateItems(float deltaTime) { for (auto& item : items_) { @@ -904,6 +902,9 @@ void Game::render() { fade_in_->render(); // Dibuja el fade de entrada fade_out_->render(); // Dibuja el fade de salida + //SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 255); + //SDL_RenderLine(renderer_, param.game.play_area.rect.x, param.game.play_area.center_y, param.game.play_area.rect.w, param.game.play_area.center_y); + screen_->render(); // Vuelca el contenido del renderizador en pantalla } @@ -1000,6 +1001,10 @@ void Game::run() { // Inicializa las variables que contienen puntos de ruta para mover objetos void Game::initPaths() { + // --- Duración estándar para 80 frames --- + // (Basado en tu ejemplo: 80 frames → 1.333s) + const float DURATION_80F_S = 1.333f; + // Recorrido para el texto de "Get Ready!" (0,1) { const auto& texture = Resource::get()->getTexture("game_text_get_ready"); @@ -1007,9 +1012,10 @@ void Game::initPaths() { const int X0 = -W; const int X1 = param.game.play_area.center_x - (W / 2); const int X2 = param.game.play_area.rect.w; - const int Y = param.game.play_area.center_y; - paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 0.5f); - paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0); + // Y_base es la LÍNEA CENTRAL. addPath(true) restará H/2 + const int Y_base = param.game.play_area.center_y; + paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 0.5f, easeOutQuint); + paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 0.0f, easeInQuint); } // Recorrido para el texto de "Last Stage!" o de "X stages left" (2,3) @@ -1019,9 +1025,10 @@ void Game::initPaths() { const int Y0 = param.game.play_area.rect.h - H; const int Y1 = param.game.play_area.center_y - (H / 2); const int Y2 = -H; - const int X = param.game.play_area.center_x; - paths_.emplace_back(createPath(Y0, Y1, PathType::VERTICAL, X, 80, easeOutQuint), 0.5f); - paths_.emplace_back(createPath(Y1, Y2, PathType::VERTICAL, X, 80, easeInQuint), 0); + // X_base es la LÍNEA CENTRAL. addPath(true) restará W/2 + const int X_base = param.game.play_area.center_x; + paths_.emplace_back(Y0, Y1, PathType::VERTICAL, X_base, DURATION_80F_S, 0.5f, easeOutQuint); + paths_.emplace_back(Y1, Y2, PathType::VERTICAL, X_base, DURATION_80F_S, 0.0f, easeInQuint); } // Recorrido para el texto de "Congratulations!!" (4,5) @@ -1032,9 +1039,10 @@ void Game::initPaths() { const int X0 = -W; const int X1 = param.game.play_area.center_x - (W / 2); const int X2 = param.game.play_area.rect.w; - const int Y = param.game.play_area.center_y - (H / 2); - paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 7.0F); - paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0); + // Y_base es la LÍNEA CENTRAL. addPath(true) restará H/2 + const int Y_base = param.game.play_area.center_y - (H / 2); + paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 7.0f, easeOutQuint); + paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 0.0f, easeInQuint); } // Recorrido para el texto de "1.000.000 points!" (6,7) @@ -1045,9 +1053,10 @@ void Game::initPaths() { const int X0 = param.game.play_area.rect.w; const int X1 = param.game.play_area.center_x - (W / 2); const int X2 = -W; - const int Y = param.game.play_area.center_y + (H / 2); - paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 7.0F); - paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0); + // Y_base es la LÍNEA CENTRAL (desplazada PREV_H hacia abajo). addPath(true) restará H/2 + const int Y_base = param.game.play_area.center_y + (H / 2); + paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 7.0f, easeOutQuint); + paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 0.0f, easeInQuint); } // Recorrido para el texto de "New Record!" (8,9) @@ -1056,11 +1065,12 @@ void Game::initPaths() { const auto W = texture->getWidth(); const auto H = texture->getHeight(); const int X0 = -W; - const int X1 = param.game.play_area.center_x - (W / 2); + const int X1 = param.game.play_area.center_x - (W / 2); // Destino (no-fijo), está bien const int X2 = param.game.play_area.rect.w; - const int Y = param.game.play_area.center_y - (H / 2) - (H * 2); - paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 1.0f); - paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0); + // Y_base es la LÍNEA CENTRAL (desplazada 2*H hacia arriba). addPath(true) restará H/2 + const int Y_base = param.game.play_area.center_y - (H * 2); + paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 1.0f, easeOutQuint); + paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 0.0f, easeInQuint); } // Recorrido para el texto de "Game Over" (10,11) @@ -1068,11 +1078,12 @@ void Game::initPaths() { const auto& texture = Resource::get()->getTexture("game_text_game_over"); const auto H = texture->getHeight(); const int Y0 = param.game.play_area.rect.h - H; - const int Y1 = param.game.play_area.center_y - (H / 2); + const int Y1 = param.game.play_area.center_y - (H / 2); // Destino (no-fijo), está bien const int Y2 = -H; - const int X = param.game.play_area.center_x; - paths_.emplace_back(createPath(Y0, Y1, PathType::VERTICAL, X, 80, easeOutQuint), 2.0f); - paths_.emplace_back(createPath(Y1, Y2, PathType::VERTICAL, X, 80, easeInQuint), 0); + // X_base es la LÍNEA CENTRAL. addPath(true) restará W/2 + const int X_base = param.game.play_area.center_x; + paths_.emplace_back(Y0, Y1, PathType::VERTICAL, X_base, DURATION_80F_S, 2.0f, easeOutQuint); + paths_.emplace_back(Y1, Y2, PathType::VERTICAL, X_base, DURATION_80F_S, 0.0f, easeInQuint); } }