forked from jaildesigner-jailgames/jaildoctors_dilemma
LoadingScreen: implementat visualment la càrrega de headers
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cmath> // Para std::sin
|
||||
#include <cstdlib> // Para rand
|
||||
|
||||
#include "core/audio/audio.hpp" // Para Audio
|
||||
@@ -21,20 +22,18 @@
|
||||
LoadingScreen::LoadingScreen()
|
||||
: mono_loading_screen_surface_(Resource::get()->getSurface("loading_screen_bn.gif")),
|
||||
color_loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")),
|
||||
mono_loading_screen_sprite_(std::make_shared<SurfaceSprite>(mono_loading_screen_surface_, 0, 0, mono_loading_screen_surface_->getWidth(), mono_loading_screen_surface_->getHeight())),
|
||||
color_loading_screen_sprite_(std::make_shared<SurfaceSprite>(color_loading_screen_surface_, 0, 0, color_loading_screen_surface_->getWidth(), color_loading_screen_surface_->getHeight())),
|
||||
mono_loading_screen_sprite_(std::make_unique<SurfaceSprite>(mono_loading_screen_surface_, 0, 0, mono_loading_screen_surface_->getWidth(), mono_loading_screen_surface_->getHeight())),
|
||||
color_loading_screen_sprite_(std::make_unique<SurfaceSprite>(color_loading_screen_surface_, 0, 0, color_loading_screen_surface_->getWidth(), color_loading_screen_surface_->getHeight())),
|
||||
program_sprite_(std::make_unique<SurfaceSprite>(Resource::get()->getSurface("program_jaildoc.gif"))),
|
||||
screen_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
||||
delta_timer_(std::make_unique<DeltaTimer>()),
|
||||
state_(State::SILENT1),
|
||||
state_time_(0.0F),
|
||||
current_border_type_(Border::NONE),
|
||||
load_rect_{0, 0, 0, 1.0F} {
|
||||
delta_timer_(std::make_unique<DeltaTimer>()) {
|
||||
// Configura la superficie donde se van a pintar los sprites
|
||||
screen_surface_->clear(static_cast<Uint8>(PaletteColor::WHITE));
|
||||
|
||||
// Inicializa variables
|
||||
SceneManager::current = SceneManager::Scene::LOADING_SCREEN;
|
||||
SceneManager::options = SceneManager::Options::NONE;
|
||||
program_sprite_->setPosition(0.0F, 8.0F);
|
||||
|
||||
// Inicializa el array de índices de líneas
|
||||
initLineIndexArray();
|
||||
@@ -85,27 +84,29 @@ void LoadingScreen::transitionToState(State new_state) {
|
||||
switch (new_state) {
|
||||
case State::SILENT1:
|
||||
case State::SILENT2:
|
||||
current_border_type_ = Border::WHITE;
|
||||
current_border_type_ = Border::RED;
|
||||
Audio::get()->stopMusic();
|
||||
break;
|
||||
|
||||
case State::HEADER1:
|
||||
case State::HEADER2:
|
||||
current_border_type_ = Border::RED;
|
||||
current_border_type_ = Border::RED_AND_CYAN;
|
||||
// Reproducir sonido de cargar el header
|
||||
Audio::get()->playMusic("loading_sound1.ogg");
|
||||
break;
|
||||
|
||||
case State::BYTES1:
|
||||
case State::BYTES2:
|
||||
case State::DATA1:
|
||||
printProgramName();
|
||||
/* CONTINUA */
|
||||
case State::DATA2:
|
||||
case State::LOADING_MONO:
|
||||
current_border_type_ = Border::YELLOW;
|
||||
current_border_type_ = Border::YELLOW_AND_BLUE;
|
||||
// Reproducir sonido de carga monocromática
|
||||
Audio::get()->playMusic("loading_sound2.ogg");
|
||||
break;
|
||||
|
||||
case State::LOADING_COLOR:
|
||||
current_border_type_ = Border::YELLOW;
|
||||
current_border_type_ = Border::YELLOW_AND_BLUE;
|
||||
// Reproducir sonido de carga en color
|
||||
Audio::get()->playMusic("loading_sound3.ogg");
|
||||
break;
|
||||
@@ -135,12 +136,12 @@ void LoadingScreen::updateState(float delta_time) {
|
||||
|
||||
case State::HEADER1:
|
||||
if (state_time_ >= HEADER1_DURATION) {
|
||||
transitionToState(State::BYTES1);
|
||||
transitionToState(State::DATA1);
|
||||
}
|
||||
break;
|
||||
|
||||
case State::BYTES1:
|
||||
if (state_time_ >= BYTES1_DURATION) {
|
||||
case State::DATA1:
|
||||
if (state_time_ >= DATA1_DURATION) {
|
||||
transitionToState(State::SILENT2);
|
||||
}
|
||||
break;
|
||||
@@ -157,8 +158,8 @@ void LoadingScreen::updateState(float delta_time) {
|
||||
}
|
||||
break;
|
||||
|
||||
case State::BYTES2:
|
||||
if (state_time_ >= BYTES2_DURATION) {
|
||||
case State::DATA2:
|
||||
if (state_time_ >= DATA2_DURATION) {
|
||||
transitionToState(State::COMPLETE);
|
||||
}
|
||||
break;
|
||||
@@ -226,7 +227,7 @@ void LoadingScreen::updateColorLoad(float delta_time) {
|
||||
|
||||
// Verificar si ha completado todos los bloques
|
||||
if (CURRENT_BLOCK >= COLOR_TOTAL_BLOCKS) {
|
||||
transitionToState(State::BYTES2);
|
||||
transitionToState(State::DATA2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -247,7 +248,7 @@ void LoadingScreen::updateColorLoad(float delta_time) {
|
||||
}
|
||||
|
||||
// Dibuja el efecto de carga amarillo y azul en el borde
|
||||
void LoadingScreen::renderYellowBorder() {
|
||||
void LoadingScreen::renderDataBorder() {
|
||||
// Obtiene la Surface del borde
|
||||
auto border = Screen::get()->getBorderSurface();
|
||||
|
||||
@@ -274,22 +275,22 @@ void LoadingScreen::renderYellowBorder() {
|
||||
}
|
||||
|
||||
// Dibuja el efecto de carga rojo y azul en el borde
|
||||
void LoadingScreen::renderRedBorder() {
|
||||
void LoadingScreen::renderHeaderBorder() {
|
||||
// Obtiene la Surface del borde
|
||||
auto border = Screen::get()->getBorderSurface();
|
||||
|
||||
// Pinta el borde de color azul
|
||||
border->clear(static_cast<Uint8>(PaletteColor::CYAN));
|
||||
// Pinta el borde de color azul o rojo
|
||||
border->clear(carrier_.toggle ? static_cast<Uint8>(PaletteColor::CYAN) : static_cast<Uint8>(PaletteColor::RED));
|
||||
|
||||
// Añade lineas rojas
|
||||
const auto COLOR = static_cast<Uint8>(PaletteColor::RED);
|
||||
// Añade lineas rojas o azules
|
||||
const auto COLOR = carrier_.toggle ? static_cast<Uint8>(PaletteColor::RED) : static_cast<Uint8>(PaletteColor::CYAN);
|
||||
const int WIDTH = Options::game.width + (Options::video.border.width * 2);
|
||||
const int HEIGHT = Options::game.height + (Options::video.border.height * 2);
|
||||
bool draw_enabled = true;
|
||||
|
||||
// Primera linea (para que tenga poca variacion)
|
||||
// Primera linea (con el color y tamaño de la portadora)
|
||||
int row = 0;
|
||||
const int FIRST_ROW_HEIGHT = (rand() % 4) + 3;
|
||||
const int FIRST_ROW_HEIGHT = static_cast<int>(carrier_.offset);
|
||||
if (draw_enabled) {
|
||||
for (int i = row; i < row + FIRST_ROW_HEIGHT; ++i) {
|
||||
border->drawLine(0, i, WIDTH, i, COLOR);
|
||||
@@ -298,26 +299,25 @@ void LoadingScreen::renderRedBorder() {
|
||||
row += FIRST_ROW_HEIGHT;
|
||||
draw_enabled = !draw_enabled;
|
||||
|
||||
// Resto de lineas
|
||||
// Resto de lineas (siguen a la portadora)
|
||||
while (row < HEIGHT) {
|
||||
const int ROW_HEIGHT = (rand() % 3) + 8;
|
||||
if (draw_enabled) {
|
||||
for (int i = row; i < row + ROW_HEIGHT; ++i) {
|
||||
for (int i = row; i < row + HEADER_DATAROW_HEIGHT; ++i) {
|
||||
border->drawLine(0, i, WIDTH, i, COLOR);
|
||||
}
|
||||
}
|
||||
row += ROW_HEIGHT;
|
||||
row += HEADER_DATAROW_HEIGHT;
|
||||
draw_enabled = !draw_enabled;
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el borde de color blanco
|
||||
void LoadingScreen::renderWhiteBorder() {
|
||||
// Dibuja el borde de color
|
||||
void LoadingScreen::renderColoredBorder(PaletteColor color) {
|
||||
// Obtiene la Surface del borde
|
||||
auto border = Screen::get()->getBorderSurface();
|
||||
|
||||
// Pinta el borde de color azul
|
||||
border->clear(static_cast<Uint8>(PaletteColor::WHITE));
|
||||
border->clear(static_cast<Uint8>(color));
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
@@ -332,14 +332,16 @@ void LoadingScreen::update() {
|
||||
// Actualizar la carga según el estado actual
|
||||
switch (state_) {
|
||||
case State::SILENT1:
|
||||
case State::HEADER1:
|
||||
case State::BYTES1:
|
||||
case State::DATA1:
|
||||
case State::SILENT2:
|
||||
case State::HEADER2:
|
||||
case State::BYTES2:
|
||||
case State::DATA2:
|
||||
// Por ahora no hacen nada específico
|
||||
// Tú definirás la lógica de cada estado aquí
|
||||
break;
|
||||
case State::HEADER1:
|
||||
case State::HEADER2:
|
||||
updateCarrier(DELTA_TIME);
|
||||
break;
|
||||
|
||||
case State::LOADING_MONO:
|
||||
updateMonoLoad(DELTA_TIME);
|
||||
@@ -397,18 +399,50 @@ void LoadingScreen::renderBorder() {
|
||||
if (Options::video.border.enabled) {
|
||||
// Dibuja el efecto de carga en el borde según el tipo actual
|
||||
switch (current_border_type_) {
|
||||
case Border::YELLOW:
|
||||
renderYellowBorder();
|
||||
case Border::YELLOW_AND_BLUE:
|
||||
renderDataBorder();
|
||||
break;
|
||||
case Border::RED:
|
||||
renderRedBorder();
|
||||
case Border::RED_AND_CYAN:
|
||||
renderHeaderBorder();
|
||||
break;
|
||||
case Border::WHITE:
|
||||
renderWhiteBorder();
|
||||
renderColoredBorder(PaletteColor::WHITE);
|
||||
break;
|
||||
case Border::RED:
|
||||
renderColoredBorder(PaletteColor::RED);
|
||||
break;
|
||||
case Border::CYAN:
|
||||
renderColoredBorder(PaletteColor::CYAN);
|
||||
break;
|
||||
case Border::NONE:
|
||||
// No renderizar borde
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe el nombre del programa
|
||||
void LoadingScreen::printProgramName() {
|
||||
auto previous_renderer = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(screen_surface_);
|
||||
program_sprite_->render(1, stringToColor("black"));
|
||||
Screen::get()->setRendererSurface(previous_renderer);
|
||||
}
|
||||
|
||||
void LoadingScreen::updateCarrier(float delta_time) {
|
||||
constexpr float CARRIER_BASE_SPEED = -250.0F;
|
||||
constexpr float CARRIER_HEIGHT = HEADER_DATAROW_HEIGHT;
|
||||
|
||||
// Oscilación compuesta: mezcla de dos frecuencias para evitar patrón predecible
|
||||
const float modulation = std::sin(carrier_.total_time * 1.2F) * std::sin(carrier_.total_time * 0.35F + 1.0F);
|
||||
const float speed = CARRIER_BASE_SPEED * (0.5F + 0.5F * modulation); // rango [-200, 0]
|
||||
|
||||
carrier_.offset += speed * delta_time;
|
||||
|
||||
if (carrier_.offset < 0.0F) {
|
||||
carrier_.offset += CARRIER_HEIGHT; // reinicia al rango [0,HEADER_DATAROW_HEIGHT]
|
||||
carrier_.toggle = !carrier_.toggle;
|
||||
}
|
||||
|
||||
carrier_.total_time += delta_time;
|
||||
}
|
||||
Reference in New Issue
Block a user