afegit surface_dissolve_sprite
ending2 amb els fades correctes
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include "core/input/input.hpp" // Para Input
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||
#include "core/rendering/surface_dissolve_sprite.hpp" // Para SurfaceDissolveSprite
|
||||
#include "core/rendering/surface_moving_sprite.hpp" // Para SMovingSprite
|
||||
#include "core/rendering/text.hpp" // Para Text
|
||||
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||
@@ -267,16 +267,40 @@ void Ending2::loadSprites() {
|
||||
// Carga los sprites
|
||||
for (const auto& file : sprite_list_) {
|
||||
const auto& animation_data = Resource::Cache::get()->getAnimationData(file + ".yaml");
|
||||
sprites_.emplace_back(std::make_shared<SurfaceAnimatedSprite>(animation_data));
|
||||
sprites_.emplace_back(std::make_shared<SurfaceDissolveSprite>(animation_data));
|
||||
sprites_.back()->setColorReplace(1, static_cast<Uint8>(PaletteColor::RED));
|
||||
sprites_.back()->setProgress(1.0F); // comença invisible
|
||||
sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_);
|
||||
sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_);
|
||||
}
|
||||
|
||||
// El último sprite (player) va en blanco, no en rojo
|
||||
sprites_.back()->setColorReplace(1, static_cast<Uint8>(PaletteColor::WHITE));
|
||||
}
|
||||
|
||||
// Actualiza los sprites
|
||||
void Ending2::updateSprites(float delta) {
|
||||
for (const auto& sprite : sprites_) {
|
||||
sprite->update(delta);
|
||||
|
||||
const float Y = sprite->getPosY();
|
||||
const float H = sprite->getHeight();
|
||||
const float CANVAS_H = static_cast<float>(Options::game.height);
|
||||
|
||||
// Checkpoint inferior: sprite entra per baix → generar de dalt a baix
|
||||
if (Y > static_cast<float>(ENTRY_EXIT_PADDING)
|
||||
&& Y <= CANVAS_H - H - ENTRY_EXIT_PADDING
|
||||
&& sprite->getProgress() >= 1.0F
|
||||
&& sprite->isTransitionDone()) {
|
||||
sprite->startGenerate(TRANSITION_DURATION_MS, DissolveDirection::UP);
|
||||
}
|
||||
|
||||
// Checkpoint superior: sprite surt per dalt → dissoldre de dalt a baix
|
||||
if (Y <= static_cast<float>(ENTRY_EXIT_PADDING)
|
||||
&& sprite->getProgress() <= 0.0F
|
||||
&& sprite->isTransitionDone()) {
|
||||
sprite->startDissolve(TRANSITION_DURATION_MS, DissolveDirection::DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,6 +308,23 @@ void Ending2::updateSprites(float delta) {
|
||||
void Ending2::updateTextSprites(float delta) {
|
||||
for (const auto& sprite : sprite_texts_) {
|
||||
sprite->update(delta);
|
||||
|
||||
const float Y = sprite->getPosY();
|
||||
const float H = sprite->getHeight();
|
||||
const float CANVAS_H = static_cast<float>(Options::game.height);
|
||||
|
||||
if (Y > static_cast<float>(ENTRY_EXIT_PADDING)
|
||||
&& Y <= CANVAS_H - H - ENTRY_EXIT_PADDING
|
||||
&& sprite->getProgress() >= 1.0F
|
||||
&& sprite->isTransitionDone()) {
|
||||
sprite->startGenerate(TRANSITION_DURATION_MS, DissolveDirection::UP);
|
||||
}
|
||||
|
||||
if (Y <= static_cast<float>(ENTRY_EXIT_PADDING)
|
||||
&& sprite->getProgress() <= 0.0F
|
||||
&& sprite->isTransitionDone()) {
|
||||
sprite->startDissolve(TRANSITION_DURATION_MS, DissolveDirection::DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,31 +332,46 @@ void Ending2::updateTextSprites(float delta) {
|
||||
void Ending2::updateTexts(float delta) {
|
||||
for (const auto& sprite : texts_) {
|
||||
sprite->update(delta);
|
||||
|
||||
const float Y = sprite->getPosY();
|
||||
const float H = sprite->getHeight();
|
||||
const float CANVAS_H = static_cast<float>(Options::game.height);
|
||||
|
||||
// Checkpoint inferior: text entra per baix → generar de dalt a baix
|
||||
if (Y > static_cast<float>(ENTRY_EXIT_PADDING)
|
||||
&& Y <= CANVAS_H - H - ENTRY_EXIT_PADDING
|
||||
&& sprite->getProgress() >= 1.0F
|
||||
&& sprite->isTransitionDone()) {
|
||||
sprite->startGenerate(TRANSITION_DURATION_MS, DissolveDirection::UP);
|
||||
}
|
||||
|
||||
// Checkpoint superior: text surt per dalt → dissoldre de dalt a baix
|
||||
if (Y <= static_cast<float>(ENTRY_EXIT_PADDING)
|
||||
&& sprite->getProgress() <= 0.0F
|
||||
&& sprite->isTransitionDone()) {
|
||||
sprite->startDissolve(TRANSITION_DURATION_MS, DissolveDirection::DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja los sprites
|
||||
void Ending2::renderSprites() {
|
||||
for (size_t i = 0; i < sprites_.size(); ++i) {
|
||||
const auto& sprite = sprites_[i];
|
||||
for (const auto& sprite : sprites_) {
|
||||
const bool A = sprite->getRect().y + sprite->getRect().h > 0;
|
||||
const bool B = sprite->getRect().y < Options::game.height;
|
||||
if (A && B) {
|
||||
const Uint8 COLOR = colors_[i % colors_.size()];
|
||||
sprite->renderWithVerticalFade(FADE_H, Options::game.height, 1, COLOR);
|
||||
sprite->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja los sprites con el texto
|
||||
void Ending2::renderSpriteTexts() {
|
||||
for (size_t i = 0; i < sprite_texts_.size(); ++i) {
|
||||
const auto& sprite = sprite_texts_[i];
|
||||
for (const auto& sprite : sprite_texts_) {
|
||||
const bool A = sprite->getRect().y + sprite->getRect().h > 0;
|
||||
const bool B = sprite->getRect().y < Options::game.height;
|
||||
if (A && B) {
|
||||
const Uint8 COLOR = colors_[i % colors_.size()];
|
||||
sprite->renderWithVerticalFade(FADE_H, Options::game.height, 1, COLOR);
|
||||
sprite->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -385,7 +441,9 @@ void Ending2::createSpriteTexts() {
|
||||
|
||||
// Crea el sprite
|
||||
SDL_FRect pos = {X, Y, W, H};
|
||||
sprite_texts_.emplace_back(std::make_shared<SurfaceMovingSprite>(surface, pos));
|
||||
sprite_texts_.emplace_back(std::make_shared<SurfaceDissolveSprite>(surface, pos));
|
||||
sprite_texts_.back()->setColorReplace(1, static_cast<Uint8>(PaletteColor::WHITE));
|
||||
sprite_texts_.back()->setProgress(1.0F); // comença invisible
|
||||
sprite_texts_.back()->setVelY(SPRITE_DESP_SPEED);
|
||||
Screen::get()->setRendererSurface(previuos_renderer);
|
||||
}
|
||||
@@ -416,7 +474,8 @@ void Ending2::createTexts() {
|
||||
|
||||
// Crea el sprite
|
||||
SDL_FRect pos = {X + DX, Y, W, H};
|
||||
texts_.emplace_back(std::make_shared<SurfaceMovingSprite>(surface, pos));
|
||||
texts_.emplace_back(std::make_shared<SurfaceDissolveSprite>(surface, pos));
|
||||
texts_.back()->setProgress(1.0F); // comença invisible
|
||||
texts_.back()->setVelY(SPRITE_DESP_SPEED);
|
||||
Screen::get()->setRendererSurface(previuos_renderer);
|
||||
}
|
||||
@@ -445,7 +504,8 @@ void Ending2::createTexts() {
|
||||
|
||||
// Crea el sprite
|
||||
SDL_FRect pos = {X + DX, Y, W, H};
|
||||
texts_.emplace_back(std::make_shared<SurfaceMovingSprite>(surface, pos));
|
||||
texts_.emplace_back(std::make_shared<SurfaceDissolveSprite>(surface, pos));
|
||||
texts_.back()->setProgress(1.0F); // comença invisible
|
||||
texts_.back()->setVelY(SPRITE_DESP_SPEED);
|
||||
Screen::get()->setRendererSurface(previuos_renderer);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "utils/defines.hpp" // Para GameCanvas::WIDTH, GameCanvas::FIRST_QUAR...
|
||||
class SurfaceAnimatedSprite; // lines 9-9
|
||||
class SurfaceMovingSprite; // lines 10-10
|
||||
|
||||
#include "core/rendering/surface_dissolve_sprite.hpp" // Para SurfaceDissolveSprite
|
||||
|
||||
class SurfaceMovingSprite;
|
||||
class DeltaTimer;
|
||||
|
||||
class Ending2 {
|
||||
@@ -43,6 +45,8 @@ class Ending2 {
|
||||
static constexpr int INITIAL_Y_OFFSET = 40; // Offset inicial en Y para posicionar sprites
|
||||
static constexpr int SCREEN_MESH_HEIGHT = 8; // Altura de la malla superior/inferior de la pantalla
|
||||
static constexpr int FADE_H = 24; // Alçada de la zona de dissolució als cantons (files)
|
||||
static constexpr float TRANSITION_DURATION_MS = 500.0F; // ms per canviar d'estat (generar o dissoldre)
|
||||
static constexpr int ENTRY_EXIT_PADDING = 2; // px de padding als bordes per activar dissolució/generació
|
||||
static constexpr int TEXT_SPACING_MULTIPLIER = 2; // Multiplicador para espaciado entre líneas de texto
|
||||
|
||||
// Constantes de tiempo (basadas en tiempo real, no en frames)
|
||||
@@ -74,9 +78,9 @@ class Ending2 {
|
||||
|
||||
// --- Variables miembro ---
|
||||
// Objetos y punteros a recursos
|
||||
std::vector<std::shared_ptr<SurfaceAnimatedSprite>> sprites_; // Vector con todos los sprites a dibujar
|
||||
std::vector<std::shared_ptr<SurfaceMovingSprite>> sprite_texts_; // Vector con los sprites de texto de los sprites
|
||||
std::vector<std::shared_ptr<SurfaceMovingSprite>> texts_; // Vector con los sprites de texto
|
||||
std::vector<std::shared_ptr<SurfaceDissolveSprite>> sprites_; // Vector con todos los sprites a dibujar
|
||||
std::vector<std::shared_ptr<SurfaceDissolveSprite>> sprite_texts_; // Vector con los sprites de texto de los sprites
|
||||
std::vector<std::shared_ptr<SurfaceDissolveSprite>> texts_; // Vector con los sprites de texto
|
||||
std::unique_ptr<DeltaTimer> delta_timer_; // Timer para time-based update
|
||||
|
||||
// Variables de estado
|
||||
|
||||
Reference in New Issue
Block a user