forked from jaildesigner-jailgames/jaildoctors_dilemma
treballant en PixelReveal
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#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_sprite.hpp" // Para SSprite
|
||||
@@ -34,6 +35,9 @@ Ending::Ending()
|
||||
fillCoverTexture(); // Rellena la textura para la cortinilla
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Ending::~Ending() = default;
|
||||
|
||||
// Actualiza el objeto
|
||||
void Ending::update() {
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
@@ -60,8 +64,9 @@ void Ending::render() {
|
||||
// Skip rendering durante WARMING_UP
|
||||
if (state_ != State::WARMING_UP) {
|
||||
// Dibuja las imagenes de la escena
|
||||
sprite_pics_.at(current_scene_).image_sprite->render();
|
||||
sprite_pics_.at(current_scene_).cover_sprite->render();
|
||||
const auto& pic = sprite_pics_.at(current_scene_);
|
||||
pic.image_sprite->render();
|
||||
pic.pixel_reveal->render(pic.pos_x, pic.pos_y);
|
||||
|
||||
// Dibuja los textos de la escena
|
||||
for (const auto& ti : scenes_.at(current_scene_).text_index) {
|
||||
@@ -69,8 +74,9 @@ void Ending::render() {
|
||||
const float TRIGGER_TIME = static_cast<float>(ti.trigger) / 60.0F;
|
||||
|
||||
if (state_time_ > TRIGGER_TIME) {
|
||||
sprite_texts_.at(ti.index).image_sprite->render();
|
||||
sprite_texts_.at(ti.index).cover_sprite->render();
|
||||
const auto& txt = sprite_texts_.at(ti.index);
|
||||
txt.image_sprite->render();
|
||||
txt.pixel_reveal->render(txt.pos_x, txt.pos_y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,42 +225,14 @@ void Ending::iniTexts() {
|
||||
|
||||
// Crea el sprite
|
||||
st.image_sprite = std::make_shared<SurfaceSprite>(st.image_surface, 0, 0, st.image_surface->getWidth(), st.image_surface->getHeight());
|
||||
st.image_sprite->setPosition((Options::game.width - st.image_surface->getWidth()) / 2, txt.pos);
|
||||
st.pos_x = static_cast<int>((Options::game.width - st.image_surface->getWidth()) / 2);
|
||||
st.pos_y = txt.pos;
|
||||
st.image_sprite->setPosition(st.pos_x, st.pos_y);
|
||||
|
||||
// Crea la cover_surface
|
||||
st.cover_surface = std::make_shared<Surface>(WIDTH, HEIGHT + 8);
|
||||
Screen::get()->setRendererSurface(st.cover_surface);
|
||||
// Crea el efecto de revelado pixel a pixel
|
||||
st.pixel_reveal = std::make_unique<PixelReveal>(static_cast<int>(WIDTH), static_cast<int>(HEIGHT), TEXT_PIXELS_PER_SECOND, STEP_DURATION, REVEAL_STEPS);
|
||||
|
||||
// Rellena la cover_surface con color transparente
|
||||
st.cover_surface->clear(static_cast<Uint8>(PaletteColor::TRANSPARENT));
|
||||
|
||||
// Crea una malla de 8 pixels de alto
|
||||
auto surface = Screen::get()->getRendererSurface();
|
||||
auto color = static_cast<Uint8>(PaletteColor::BLACK);
|
||||
for (int i = 0; i < WIDTH; i += 2) {
|
||||
surface->putPixel(i, 0, color);
|
||||
surface->putPixel(i, 2, color);
|
||||
surface->putPixel(i, 4, color);
|
||||
surface->putPixel(i, 6, color);
|
||||
|
||||
surface->putPixel(i + 1, 5, color);
|
||||
surface->putPixel(i + 1, 7, color);
|
||||
}
|
||||
|
||||
// El resto se rellena de color sólido
|
||||
SDL_FRect rect = {0, 8, WIDTH, HEIGHT};
|
||||
surface->fillRect(&rect, color);
|
||||
|
||||
// Crea el sprite
|
||||
st.cover_sprite = std::make_shared<SurfaceSprite>(st.cover_surface, 0, 0, st.cover_surface->getWidth(), st.cover_surface->getHeight() - 8);
|
||||
st.cover_sprite->setPosition((Options::game.width - st.cover_surface->getWidth()) / 2, txt.pos);
|
||||
st.cover_sprite->setClip(0, 8, st.cover_surface->getWidth(), st.cover_surface->getHeight());
|
||||
|
||||
// Inicializa variables
|
||||
st.cover_clip_desp = 8;
|
||||
st.cover_clip_height = HEIGHT;
|
||||
|
||||
sprite_texts_.push_back(st);
|
||||
sprite_texts_.push_back(std::move(st));
|
||||
Screen::get()->setRendererSurface(previuos_renderer);
|
||||
}
|
||||
}
|
||||
@@ -283,45 +261,15 @@ void Ending::iniPics() {
|
||||
const float HEIGHT = sp.image_surface->getHeight();
|
||||
|
||||
// Crea el sprite
|
||||
sp.pos_x = static_cast<int>((Options::game.width - WIDTH) / 2);
|
||||
sp.pos_y = pic.pos;
|
||||
sp.image_sprite = std::make_shared<SurfaceSprite>(sp.image_surface, 0, 0, WIDTH, HEIGHT);
|
||||
sp.image_sprite->setPosition((Options::game.width - WIDTH) / 2, pic.pos);
|
||||
sp.image_sprite->setPosition(sp.pos_x, sp.pos_y);
|
||||
|
||||
// Crea la cover_surface
|
||||
sp.cover_surface = std::make_shared<Surface>(WIDTH, HEIGHT + 8);
|
||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(sp.cover_surface);
|
||||
// Crea el efecto de revelado pixel a pixel
|
||||
sp.pixel_reveal = std::make_unique<PixelReveal>(static_cast<int>(WIDTH), static_cast<int>(HEIGHT), IMAGE_PIXELS_PER_SECOND, STEP_DURATION, REVEAL_STEPS);
|
||||
|
||||
// Rellena la cover_surface con color transparente
|
||||
sp.cover_surface->clear(static_cast<Uint8>(PaletteColor::TRANSPARENT));
|
||||
|
||||
// Crea una malla en los primeros 8 pixels
|
||||
auto surface = Screen::get()->getRendererSurface();
|
||||
auto color = static_cast<Uint8>(PaletteColor::BLACK);
|
||||
for (int i = 0; i < WIDTH; i += 2) {
|
||||
surface->putPixel(i, 0, color);
|
||||
surface->putPixel(i, 2, color);
|
||||
surface->putPixel(i, 4, color);
|
||||
surface->putPixel(i, 6, color);
|
||||
|
||||
surface->putPixel(i + 1, 5, color);
|
||||
surface->putPixel(i + 1, 7, color);
|
||||
}
|
||||
|
||||
// El resto se rellena de color sólido
|
||||
SDL_FRect rect = {0.0F, 8.0F, WIDTH, HEIGHT};
|
||||
surface->fillRect(&rect, color);
|
||||
|
||||
// Crea el sprite
|
||||
sp.cover_sprite = std::make_shared<SurfaceSprite>(sp.cover_surface, 0, 0, sp.cover_surface->getWidth(), sp.cover_surface->getHeight() - 8);
|
||||
sp.cover_sprite->setPosition((Options::game.width - sp.cover_surface->getWidth()) / 2, pic.pos);
|
||||
sp.cover_sprite->setClip(0, 8, sp.cover_surface->getWidth(), sp.cover_surface->getHeight());
|
||||
|
||||
// Inicializa variables
|
||||
sp.cover_clip_desp = 8;
|
||||
sp.cover_clip_height = HEIGHT;
|
||||
|
||||
sprite_pics_.push_back(sp);
|
||||
Screen::get()->setRendererSurface(previuos_renderer);
|
||||
sprite_pics_.push_back(std::move(sp));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,68 +374,18 @@ void Ending::updateSpriteCovers() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Actualiza la cortinilla de los textos
|
||||
// Actualiza el revelado de los textos
|
||||
for (const auto& ti : scenes_.at(current_scene_).text_index) {
|
||||
// Convertir trigger de frames a segundos @ 60fps
|
||||
const float TRIGGER_TIME = static_cast<float>(ti.trigger) / 60.0F;
|
||||
|
||||
if (state_time_ > TRIGGER_TIME) {
|
||||
// Tiempo transcurrido desde que se activó el trigger
|
||||
const float TIME_SINCE_TRIGGER = state_time_ - TRIGGER_TIME;
|
||||
|
||||
// Píxeles revelados: tiempo * velocidad
|
||||
const float PIXELS_REVEALED = TIME_SINCE_TRIGGER * TEXT_REVEAL_SPEED;
|
||||
|
||||
// Obtiene el sprite
|
||||
auto sprite_text = sprite_texts_.at(ti.index);
|
||||
|
||||
// Obtener altura inicial de la superficie
|
||||
const float INITIAL_HEIGHT = sprite_text.image_surface->getHeight();
|
||||
const float Y_INITIAL = sprite_text.image_sprite->getY();
|
||||
|
||||
// Fase 1: Revelar malla decorativa (8 píxeles)
|
||||
if (PIXELS_REVEALED < 8.0F) {
|
||||
sprite_text.cover_clip_desp = static_cast<int>(8.0F - PIXELS_REVEALED);
|
||||
sprite_text.cover_clip_height = static_cast<int>(INITIAL_HEIGHT);
|
||||
sprite_text.cover_sprite->setY(Y_INITIAL);
|
||||
}
|
||||
// Fase 2: Revelar contenido
|
||||
else {
|
||||
sprite_text.cover_clip_desp = 0;
|
||||
const int CONTENT_PIXELS = PIXELS_REVEALED - 8.0F;
|
||||
sprite_text.cover_clip_height = std::max(0, static_cast<int>(INITIAL_HEIGHT - CONTENT_PIXELS));
|
||||
sprite_text.cover_sprite->setY(Y_INITIAL + static_cast<int>(CONTENT_PIXELS));
|
||||
}
|
||||
|
||||
sprite_text.cover_sprite->setClip(
|
||||
0,
|
||||
sprite_text.cover_clip_desp,
|
||||
sprite_text.cover_sprite->getWidth(),
|
||||
sprite_text.cover_clip_height);
|
||||
sprite_texts_.at(ti.index).pixel_reveal->update(TIME_SINCE_TRIGGER);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la cortinilla de las imágenes (revelación continua desde el inicio de la escena)
|
||||
auto sprite_pics = sprite_pics_.at(current_scene_);
|
||||
const float PIXELS_REVEALED = state_time_ * IMAGE_REVEAL_SPEED;
|
||||
const float INITIAL_HEIGHT = sprite_pics.image_surface->getHeight();
|
||||
const float Y_INITIAL = sprite_pics.image_sprite->getY();
|
||||
|
||||
// Fase 1: Revelar malla decorativa (8 píxeles)
|
||||
if (PIXELS_REVEALED < 8.0F) {
|
||||
sprite_pics.cover_clip_desp = static_cast<int>(8.0F - PIXELS_REVEALED);
|
||||
sprite_pics.cover_clip_height = static_cast<int>(INITIAL_HEIGHT);
|
||||
sprite_pics.cover_sprite->setY(Y_INITIAL);
|
||||
}
|
||||
// Fase 2: Revelar contenido
|
||||
else {
|
||||
sprite_pics.cover_clip_desp = 0;
|
||||
const int CONTENT_PIXELS = PIXELS_REVEALED - 8.0F;
|
||||
sprite_pics.cover_clip_height = std::max(0, static_cast<int>(INITIAL_HEIGHT - CONTENT_PIXELS));
|
||||
sprite_pics.cover_sprite->setY(Y_INITIAL + static_cast<int>(CONTENT_PIXELS));
|
||||
}
|
||||
|
||||
sprite_pics.cover_sprite->setClip(0, sprite_pics.cover_clip_desp, sprite_pics.cover_sprite->getWidth(), sprite_pics.cover_clip_height);
|
||||
// Actualiza el revelado de la imagen (desde el inicio de la escena)
|
||||
sprite_pics_.at(current_scene_).pixel_reveal->update(state_time_);
|
||||
}
|
||||
|
||||
// Comprueba si se ha de cambiar de escena
|
||||
|
||||
Reference in New Issue
Block a user