Afegit efecte d'eixida a les instruccions
This commit is contained in:
@@ -22,6 +22,10 @@
|
||||
#include "utils.h" // Para Color, shdw_txt_color, Zone, no_color
|
||||
#include "mouse.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
// Constructor
|
||||
Instructions::Instructions()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
@@ -46,6 +50,9 @@ Instructions::Instructions()
|
||||
fade_->setMode(FadeMode::IN);
|
||||
fade_->activate();
|
||||
|
||||
// Inicializa las líneas con un retraso progresivo de 50 ms
|
||||
lines_ = initializeLines(256);
|
||||
|
||||
// Rellena la textura de texto
|
||||
fillTexture();
|
||||
|
||||
@@ -225,14 +232,36 @@ void Instructions::update()
|
||||
// Actualiza los sprites
|
||||
updateSprites();
|
||||
|
||||
// Establece la ventana del backbuffer
|
||||
view_.y = std::max(0, param.game.height - counter_ + 100);
|
||||
|
||||
// Verifica si view_.y == 0 y gestiona el temporizador
|
||||
if (view_.y == 0)
|
||||
{
|
||||
if (!start_delay_triggered_)
|
||||
{
|
||||
// Activa el temporizador si no ha sido activado
|
||||
start_delay_triggered_ = true;
|
||||
start_delay_time_ = SDL_GetTicks();
|
||||
}
|
||||
else if (SDL_GetTicks() - start_delay_time_ >= 4000)
|
||||
{
|
||||
// Han pasado tres segundos, mover líneas
|
||||
all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el mosaico de fondo
|
||||
tiled_bg_->update();
|
||||
|
||||
// Actualiza el objeto "fade"
|
||||
fade_->update();
|
||||
|
||||
// Rellena el backbuffer
|
||||
fillBackbuffer();
|
||||
|
||||
// Comprueba si el contador ha llegado al final
|
||||
if (counter_ == counter_end_)
|
||||
if (all_lines_off_screen_)
|
||||
{
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
@@ -243,9 +272,6 @@ void Instructions::update()
|
||||
// Pinta en pantalla
|
||||
void Instructions::render()
|
||||
{
|
||||
// Rellena el backbuffer
|
||||
fillBackbuffer();
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
Screen::get()->start();
|
||||
|
||||
@@ -255,11 +281,11 @@ void Instructions::render()
|
||||
// Dibuja el mosacico de fondo
|
||||
tiled_bg_->render();
|
||||
|
||||
// Establece la ventana del backbuffer
|
||||
view_.y = std::max(0, param.game.height - counter_ + 100);
|
||||
|
||||
// Copia la textura y el backbuffer al renderizador
|
||||
SDL_RenderCopy(renderer_, backbuffer_, nullptr, &view_);
|
||||
if (view_.y == 0)
|
||||
renderLines(renderer_, backbuffer_, lines_);
|
||||
else
|
||||
SDL_RenderCopy(renderer_, backbuffer_, nullptr, &view_);
|
||||
|
||||
fade_->render();
|
||||
|
||||
@@ -334,4 +360,61 @@ void Instructions::run()
|
||||
checkEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// Método para inicializar las líneas
|
||||
std::vector<Line> Instructions::initializeLines(int height)
|
||||
{
|
||||
std::vector<Line> lines;
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
int direction = (y % 2 == 0) ? -1 : 1; // Pares a la izquierda, impares a la derecha
|
||||
lines.emplace_back(y, 0.0f, direction);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
// Método para mover las líneas con suavizado
|
||||
bool Instructions::moveLines(std::vector<Line> &lines, int width, float duration, Uint32 startDelay)
|
||||
{
|
||||
Uint32 currentTime = SDL_GetTicks();
|
||||
bool allLinesOffScreen = true;
|
||||
|
||||
for (auto &line : lines)
|
||||
{
|
||||
// Establecer startTime en el primer cuadro de animación
|
||||
if (line.startTime == 0)
|
||||
{
|
||||
line.startTime = currentTime + line.y * startDelay;
|
||||
}
|
||||
|
||||
float elapsedTime = (currentTime - line.startTime) / 1000.0f; // Convertir a segundos
|
||||
if (elapsedTime < 0)
|
||||
{
|
||||
allLinesOffScreen = false; // Si aún no se debe mover esta línea, no están todas fuera de pantalla
|
||||
continue;
|
||||
}
|
||||
if (elapsedTime >= duration)
|
||||
{
|
||||
continue; // Si la línea ha salido de los límites, no la muevas más
|
||||
}
|
||||
|
||||
float t = elapsedTime / duration;
|
||||
float smoothFactor = easeInOutQuint(t);
|
||||
line.x = line.direction * smoothFactor * width;
|
||||
allLinesOffScreen = false; // Si alguna línea aún se está moviendo, no están todas fuera de pantalla
|
||||
}
|
||||
|
||||
return allLinesOffScreen;
|
||||
}
|
||||
|
||||
// Método para renderizar las líneas
|
||||
void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines)
|
||||
{
|
||||
for (const auto &line : lines)
|
||||
{
|
||||
SDL_Rect srcRect = {0, line.y, 320, 1};
|
||||
SDL_Rect dstRect = {static_cast<int>(line.x), line.y, 320, 1};
|
||||
SDL_RenderCopy(renderer, texture, &srcRect, &dstRect);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user