forked from jaildesigner-jailgames/jaildoctors_dilemma
228 lines
7.3 KiB
C++
228 lines
7.3 KiB
C++
#include "game/scenes/logo.hpp"
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include "core/input/global_inputs.hpp" // Para check
|
|
#include "core/rendering/screen.hpp" // Para Screen
|
|
#include "core/rendering/surface.hpp" // Para Surface
|
|
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
|
#include "core/resources/resource.hpp" // Para Resource
|
|
#include "game/options.hpp" // Para Options, SectionState, options, Section
|
|
#include "game/scene_manager.hpp" // Para SceneManager
|
|
#include "utils/defines.hpp" // Para GAME_SPEED
|
|
#include "utils/global_events.hpp" // Para check
|
|
#include "utils/utils.hpp" // Para PaletteColor
|
|
|
|
// Constructor
|
|
Logo::Logo()
|
|
: jailgames_surface_(Resource::get()->getSurface("jailgames.gif")),
|
|
since_1998_surface_(Resource::get()->getSurface("since_1998.gif")),
|
|
since_1998_sprite_(std::make_shared<SurfaceSprite>(since_1998_surface_, (256 - since_1998_surface_->getWidth()) / 2, 83 + jailgames_surface_->getHeight() + 5, since_1998_surface_->getWidth(), since_1998_surface_->getHeight())) {
|
|
// Configura variables
|
|
since_1998_sprite_->setClip(0, 0, since_1998_surface_->getWidth(), since_1998_surface_->getHeight());
|
|
since_1998_color_ = static_cast<Uint8>(PaletteColor::BLACK);
|
|
jailgames_color_ = static_cast<Uint8>(PaletteColor::BRIGHT_WHITE);
|
|
|
|
// Inicializa variables
|
|
SceneManager::current = SceneManager::Scene::LOGO;
|
|
|
|
// Crea los sprites de cada linea
|
|
for (int i = 0; i < jailgames_surface_->getHeight(); ++i) {
|
|
jailgames_sprite_.push_back(std::make_shared<SurfaceSprite>(jailgames_surface_, 0, i, jailgames_surface_->getWidth(), 1));
|
|
jailgames_sprite_.back()->setClip(0, i, jailgames_surface_->getWidth(), 1);
|
|
jailgames_sprite_.at(i)->setX((i % 2 == 0) ? (256 + (i * 3)) : (-181 - (i * 3)));
|
|
jailgames_sprite_.at(i)->setY(83 + i);
|
|
}
|
|
|
|
initColors(); // Inicializa el vector de colores
|
|
|
|
// Cambia el color del borde
|
|
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
|
|
}
|
|
|
|
// Comprueba el manejador de eventos
|
|
void Logo::checkEvents() {
|
|
SDL_Event event;
|
|
while (SDL_PollEvent(&event)) {
|
|
globalEvents::check(event);
|
|
}
|
|
}
|
|
|
|
// Comprueba las entradas
|
|
void Logo::checkInput() {
|
|
globalInputs::check();
|
|
}
|
|
|
|
// Gestiona el logo de JAILGAME
|
|
void Logo::updateJAILGAMES() {
|
|
if (counter_ > 30) {
|
|
for (int i = 1; i < (int)jailgames_sprite_.size(); ++i) {
|
|
constexpr int SPEED = 8;
|
|
constexpr int DEST = 37;
|
|
if (jailgames_sprite_.at(i)->getX() != 37) {
|
|
if (i % 2 == 0) {
|
|
jailgames_sprite_.at(i)->incX(-SPEED);
|
|
if (jailgames_sprite_.at(i)->getX() < DEST) {
|
|
jailgames_sprite_.at(i)->setX(DEST);
|
|
}
|
|
} else {
|
|
jailgames_sprite_.at(i)->incX(SPEED);
|
|
if (jailgames_sprite_.at(i)->getX() > DEST) {
|
|
jailgames_sprite_.at(i)->setX(DEST);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Gestiona el color de las texturas
|
|
void Logo::updateTextureColors() {
|
|
constexpr int INI = 70;
|
|
constexpr int INC = 4;
|
|
|
|
if (counter_ == INI + INC * 0) {
|
|
since_1998_color_ = color_.at(0);
|
|
}
|
|
|
|
else if (counter_ == INI + INC * 1) {
|
|
since_1998_color_ = color_.at(1);
|
|
}
|
|
|
|
else if (counter_ == INI + INC * 2) {
|
|
since_1998_color_ = color_.at(2);
|
|
}
|
|
|
|
else if (counter_ == INI + INC * 3) {
|
|
since_1998_color_ = color_.at(3);
|
|
}
|
|
|
|
else if (counter_ == INI + INC * 4) {
|
|
since_1998_color_ = color_.at(4);
|
|
}
|
|
|
|
else if (counter_ == INI + INC * 5) {
|
|
since_1998_color_ = color_.at(5);
|
|
}
|
|
|
|
else if (counter_ == INI + INC * 6) {
|
|
since_1998_color_ = color_.at(6);
|
|
}
|
|
|
|
else if (counter_ == INI + INC * 7) {
|
|
since_1998_color_ = color_.at(7);
|
|
}
|
|
|
|
else if (counter_ == INIT_FADE_ + INC * 0) {
|
|
jailgames_color_ = color_.at(6);
|
|
since_1998_color_ = color_.at(6);
|
|
}
|
|
|
|
else if (counter_ == INIT_FADE_ + INC * 1) {
|
|
jailgames_color_ = color_.at(5);
|
|
since_1998_color_ = color_.at(5);
|
|
}
|
|
|
|
else if (counter_ == INIT_FADE_ + INC * 2) {
|
|
jailgames_color_ = color_.at(4);
|
|
since_1998_color_ = color_.at(4);
|
|
}
|
|
|
|
else if (counter_ == INIT_FADE_ + INC * 3) {
|
|
jailgames_color_ = color_.at(3);
|
|
since_1998_color_ = color_.at(3);
|
|
}
|
|
|
|
else if (counter_ == INIT_FADE_ + INC * 4) {
|
|
jailgames_color_ = color_.at(2);
|
|
since_1998_color_ = color_.at(2);
|
|
}
|
|
|
|
else if (counter_ == INIT_FADE_ + INC * 5) {
|
|
jailgames_color_ = color_.at(1);
|
|
since_1998_color_ = color_.at(1);
|
|
}
|
|
|
|
else if (counter_ == INIT_FADE_ + INC * 6) {
|
|
jailgames_color_ = color_.at(0);
|
|
since_1998_color_ = color_.at(0);
|
|
}
|
|
}
|
|
|
|
// Actualiza las variables
|
|
void Logo::update() {
|
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
|
if (SDL_GetTicks() - ticks_ > GAME_SPEED) {
|
|
ticks_ = SDL_GetTicks(); // Actualiza el contador de ticks
|
|
|
|
checkInput(); // Comprueba las entradas
|
|
counter_++; // Incrementa el contador
|
|
updateJAILGAMES(); // Gestiona el logo de JAILGAME
|
|
updateTextureColors(); // Gestiona el color de las texturas
|
|
Screen::get()->update(); // Actualiza el objeto Screen
|
|
|
|
// Comprueba si ha terminado el logo
|
|
if (counter_ == END_LOGO_ + POST_LOGO_) {
|
|
endSection();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Dibuja en pantalla
|
|
void Logo::render() {
|
|
// Prepara para empezar a dibujar en la textura de juego
|
|
Screen::get()->start();
|
|
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
|
|
|
|
// Dibuja los objetos
|
|
for (const auto& s : jailgames_sprite_) {
|
|
s->render(1, jailgames_color_);
|
|
}
|
|
since_1998_sprite_->render(1, since_1998_color_);
|
|
|
|
// Vuelca el contenido del renderizador en pantalla
|
|
Screen::get()->render();
|
|
}
|
|
|
|
// Bucle para el logo del juego
|
|
void Logo::run() {
|
|
while (SceneManager::current == SceneManager::Scene::LOGO) {
|
|
update();
|
|
checkEvents();
|
|
render();
|
|
}
|
|
}
|
|
|
|
// Termina la sección
|
|
void Logo::endSection() {
|
|
switch (SceneManager::options) {
|
|
case SceneManager::Options::LOGO_TO_TITLE:
|
|
SceneManager::current = SceneManager::Scene::TITLE;
|
|
break;
|
|
|
|
case SceneManager::Options::LOGO_TO_LOADING_SCREEN:
|
|
SceneManager::current = SceneManager::Scene::LOADING_SCREEN;
|
|
break;
|
|
|
|
default:
|
|
// Ninguna acción por defecto
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Inicializa el vector de colores
|
|
void Logo::initColors() {
|
|
// Inicializa el vector de colores
|
|
const std::vector<Uint8> COLORS = {
|
|
static_cast<Uint8>(PaletteColor::BLACK),
|
|
static_cast<Uint8>(PaletteColor::BLUE),
|
|
static_cast<Uint8>(PaletteColor::RED),
|
|
static_cast<Uint8>(PaletteColor::MAGENTA),
|
|
static_cast<Uint8>(PaletteColor::GREEN),
|
|
static_cast<Uint8>(PaletteColor::CYAN),
|
|
static_cast<Uint8>(PaletteColor::YELLOW),
|
|
static_cast<Uint8>(PaletteColor::BRIGHT_WHITE)};
|
|
for (const auto& color : COLORS) {
|
|
color_.push_back(color);
|
|
}
|
|
} |