forked from jaildesigner-jailgames/jaildoctors_dilemma
treballant en PixelReveal
This commit is contained in:
@@ -2,11 +2,10 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <algorithm> // Para min
|
||||
|
||||
#include "core/audio/audio.hpp" // Para Audio
|
||||
#include "core/input/global_inputs.hpp" // Para check
|
||||
#include "core/input/input.hpp" // Para Input
|
||||
#include "core/rendering/pixel_reveal.hpp" // Para PixelReveal
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||
@@ -19,10 +18,12 @@
|
||||
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||
#include "utils/utils.hpp" // Para PaletteColor
|
||||
|
||||
// Destructor
|
||||
Credits::~Credits() = default;
|
||||
|
||||
// Constructor
|
||||
Credits::Credits()
|
||||
: text_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
||||
cover_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
||||
shining_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::Cache::get()->getAnimationData("shine.yaml"))),
|
||||
delta_timer_(std::make_unique<DeltaTimer>()) {
|
||||
// Configura la escena
|
||||
@@ -115,24 +116,8 @@ void Credits::fillTexture() {
|
||||
// Recoloca el sprite del brillo
|
||||
shining_sprite_->setPosX(POS_X + 2);
|
||||
|
||||
// Rellena la textura que cubre el texto con color transparente
|
||||
cover_surface_->clear(static_cast<Uint8>(PaletteColor::TRANSPARENT));
|
||||
|
||||
// Los primeros 8 pixels crea una malla
|
||||
auto color = static_cast<Uint8>(PaletteColor::BLACK);
|
||||
for (int i = 0; i < 256; i += 2) {
|
||||
cover_surface_->putPixel(i, 0, color);
|
||||
cover_surface_->putPixel(i, 2, color);
|
||||
cover_surface_->putPixel(i, 4, color);
|
||||
cover_surface_->putPixel(i, 6, color);
|
||||
|
||||
cover_surface_->putPixel(i + 1, 5, color);
|
||||
cover_surface_->putPixel(i + 1, 7, color);
|
||||
}
|
||||
|
||||
// El resto se rellena de color sólido
|
||||
SDL_FRect rect = {0, 8, 256, 192};
|
||||
cover_surface_->fillRect(&rect, color);
|
||||
// Crea el efecto de revelado pixel a pixel
|
||||
pixel_reveal_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, PIXELS_PER_SECOND, STEP_DURATION, REVEAL_STEPS);
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
@@ -145,6 +130,8 @@ void Credits::update() {
|
||||
|
||||
updateState(DELTA_TIME); // Actualiza la máquina de estados
|
||||
|
||||
pixel_reveal_->update(reveal_time_); // Actualiza el efecto de revelado
|
||||
|
||||
// Actualiza el sprite con el brillo si está después del tiempo de inicio
|
||||
if (reveal_time_ > SHINE_START_TIME) {
|
||||
shining_sprite_->update(DELTA_TIME);
|
||||
@@ -239,11 +226,8 @@ void Credits::render() {
|
||||
// Dibuja la textura con el texto en pantalla
|
||||
text_surface_->render(0, 0);
|
||||
|
||||
// Dibuja la textura que cubre el texto
|
||||
// OFFSET basado en reveal_time_ (que se congela durante pausas, como counter_ original)
|
||||
const float OFFSET = std::min(reveal_time_ * REVEAL_SPEED / 8.0F, 192.0F / 2.0F);
|
||||
SDL_FRect src_rect = {0.0F, 0.0F, 256.0F, 192.0F - (OFFSET * 2.0F)};
|
||||
cover_surface_->render(0, static_cast<int>(OFFSET * 2.0F), &src_rect);
|
||||
// Dibuja la máscara de revelado pixel a pixel
|
||||
pixel_reveal_->render(0, 0);
|
||||
|
||||
// Dibuja el sprite con el brillo
|
||||
if (reveal_time_ > SHINE_START_TIME) {
|
||||
|
||||
Reference in New Issue
Block a user