forked from jaildesigner-jailgames/jaildoctors_dilemma
afegit pixel_reveal a credits i a ending
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
#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
|
||||
@@ -16,7 +14,6 @@
|
||||
#include "core/system/global_events.hpp" // Para check
|
||||
#include "game/options.hpp" // Para Options, options, OptionsGame, SectionS...
|
||||
#include "game/scene_manager.hpp" // Para SceneManager
|
||||
#include "utils/defines.hpp" // Para GAME_SPEED
|
||||
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||
#include "utils/utils.hpp" // Para PaletteColor
|
||||
|
||||
@@ -30,9 +27,7 @@ Ending::Ending()
|
||||
iniPics(); // Inicializa las imagenes
|
||||
iniScenes(); // Inicializa las escenas
|
||||
|
||||
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); // Cambia el color del borde
|
||||
cover_surface_ = std::make_shared<Surface>(Options::game.width, Options::game.height + 8); // Crea la textura para cubrir el texto
|
||||
fillCoverTexture(); // Rellena la textura para la cortinilla
|
||||
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); // Cambia el color del borde
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -81,7 +76,9 @@ void Ending::render() {
|
||||
}
|
||||
|
||||
// Dibuja la cortinilla de cambio de escena
|
||||
renderCoverTexture();
|
||||
if (scene_cover_) {
|
||||
scene_cover_->render(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
@@ -107,9 +104,10 @@ void Ending::transitionToState(State new_state) {
|
||||
state_ = new_state;
|
||||
state_time_ = 0.0F;
|
||||
|
||||
// Al cambiar a una escena, resetear fadeout_time_
|
||||
// Al cambiar a una escena, resetear la cortinilla de salida y el contador de fade
|
||||
if (new_state != State::WARMING_UP && new_state != State::ENDING) {
|
||||
fadeout_time_ = 0.0F;
|
||||
scene_cover_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,9 +125,12 @@ void Ending::updateState(float delta_time) {
|
||||
|
||||
case State::SCENE_0:
|
||||
checkChangeScene();
|
||||
// Actualizar fadeout_time_ si estamos cerca del final
|
||||
if (state_time_ >= SCENE_0_DURATION - FADEOUT_START_OFFSET) {
|
||||
fadeout_time_ += delta_time;
|
||||
if (!scene_cover_) {
|
||||
scene_cover_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, COVER_PIXELS_PER_SECOND, STEP_DURATION, COVER_STEPS, true);
|
||||
}
|
||||
scene_cover_->update(fadeout_time_);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -137,6 +138,10 @@ void Ending::updateState(float delta_time) {
|
||||
checkChangeScene();
|
||||
if (state_time_ >= SCENE_1_DURATION - FADEOUT_START_OFFSET) {
|
||||
fadeout_time_ += delta_time;
|
||||
if (!scene_cover_) {
|
||||
scene_cover_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, COVER_PIXELS_PER_SECOND, STEP_DURATION, COVER_STEPS, true);
|
||||
}
|
||||
scene_cover_->update(fadeout_time_);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -144,6 +149,10 @@ void Ending::updateState(float delta_time) {
|
||||
checkChangeScene();
|
||||
if (state_time_ >= SCENE_2_DURATION - FADEOUT_START_OFFSET) {
|
||||
fadeout_time_ += delta_time;
|
||||
if (!scene_cover_) {
|
||||
scene_cover_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, COVER_PIXELS_PER_SECOND, STEP_DURATION, COVER_STEPS, true);
|
||||
}
|
||||
scene_cover_->update(fadeout_time_);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -151,6 +160,10 @@ void Ending::updateState(float delta_time) {
|
||||
checkChangeScene();
|
||||
if (state_time_ >= SCENE_3_DURATION - FADEOUT_START_OFFSET) {
|
||||
fadeout_time_ += delta_time;
|
||||
if (!scene_cover_) {
|
||||
scene_cover_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, COVER_PIXELS_PER_SECOND, STEP_DURATION, COVER_STEPS, true);
|
||||
}
|
||||
scene_cover_->update(fadeout_time_);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -158,6 +171,10 @@ void Ending::updateState(float delta_time) {
|
||||
checkChangeScene();
|
||||
if (state_time_ >= SCENE_4_DURATION - FADEOUT_START_OFFSET) {
|
||||
fadeout_time_ += delta_time;
|
||||
if (!scene_cover_) {
|
||||
scene_cover_ = std::make_unique<PixelReveal>(Options::game.width, Options::game.height, COVER_PIXELS_PER_SECOND, STEP_DURATION, COVER_STEPS, true);
|
||||
}
|
||||
scene_cover_->update(fadeout_time_);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -432,42 +449,3 @@ void Ending::checkChangeScene() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rellena la textura para la cortinilla
|
||||
void Ending::fillCoverTexture() {
|
||||
// Rellena la textura que cubre el texto con color transparente
|
||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(cover_surface_);
|
||||
cover_surface_->clear(static_cast<Uint8>(PaletteColor::TRANSPARENT));
|
||||
|
||||
// Los primeros 8 pixels crea una malla
|
||||
const auto COLOR = static_cast<Uint8>(PaletteColor::BLACK);
|
||||
auto surface = Screen::get()->getRendererSurface();
|
||||
for (int i = 0; i < 256; i += 2) {
|
||||
surface->putPixel(i + 0, Options::game.height + 0, COLOR);
|
||||
surface->putPixel(i + 1, Options::game.height + 1, COLOR);
|
||||
surface->putPixel(i + 0, Options::game.height + 2, COLOR);
|
||||
surface->putPixel(i + 1, Options::game.height + 3, COLOR);
|
||||
|
||||
surface->putPixel(i, Options::game.height + 4, COLOR);
|
||||
surface->putPixel(i, Options::game.height + 6, COLOR);
|
||||
}
|
||||
|
||||
// El resto se rellena de color sólido
|
||||
SDL_FRect rect = {0, 0, 256, Options::game.height};
|
||||
surface->fillRect(&rect, COLOR);
|
||||
|
||||
Screen::get()->setRendererSurface(previuos_renderer);
|
||||
}
|
||||
|
||||
// Dibuja la cortinilla de cambio de escena
|
||||
void Ending::renderCoverTexture() {
|
||||
if (fadeout_time_ > 0.0F) {
|
||||
// Convertir fadeout_time_ a equivalente de cover_counter_ @ 60fps
|
||||
const float FADEOUT_COUNTER = std::min(fadeout_time_ * 60.0F, 100.0F);
|
||||
|
||||
SDL_FRect src_rect = {0.0F, 200.0F - (FADEOUT_COUNTER * 2.0F), 256.0F, FADEOUT_COUNTER * 2.0F};
|
||||
SDL_FRect dst_rect = {0.0F, 0.0F, 256.0F, FADEOUT_COUNTER * 2.0F};
|
||||
cover_surface_->render(&src_rect, &dst_rect);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user