mogut options.section a SceneManager

This commit is contained in:
2025-10-26 14:18:45 +01:00
parent df4965a84b
commit 51330db998
15 changed files with 129 additions and 120 deletions

View File

@@ -1,3 +1,5 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "core/input/global_inputs.hpp"
#include <SDL3/SDL.h>
@@ -13,11 +15,11 @@
namespace globalInputs {
void quit() {
const std::string code = Options::section.section == Options::Scene::GAME ? "PRESS AGAIN TO RETURN TO MENU" : "PRESS AGAIN TO EXIT";
const std::string code = SceneManager::current == SceneManager::Scene::GAME ? "PRESS AGAIN TO RETURN TO MENU" : "PRESS AGAIN TO EXIT";
auto code_found = stringInVector(Notifier::get()->getCodes(), code);
if (code_found) {
// Si la notificación de salir está activa, cambia de sección
Options::section.section = Options::section.section == Options::Scene::GAME ? Options::Scene::TITLE : Options::Scene::QUIT;
SceneManager::current = SceneManager::current == SceneManager::Scene::GAME ? SceneManager::Scene::TITLE : SceneManager::Scene::QUIT;
} else {
// Si la notificación de salir no está activa, muestra la notificación
Notifier::get()->show({code}, NotificationText::CENTER, 2000, -1, true, code);
@@ -26,16 +28,16 @@ void quit() {
// Cambia de seccion
void skip_section() {
switch (Options::section.section) {
case Options::Scene::LOGO:
case Options::Scene::LOADING_SCREEN:
case Options::Scene::CREDITS:
case Options::Scene::DEMO:
case Options::Scene::GAME_OVER:
case Options::Scene::ENDING:
case Options::Scene::ENDING2:
Options::section.section = Options::Scene::TITLE;
Options::section.subsection = Options::SceneOptions::NONE;
switch (SceneManager::current) {
case SceneManager::Scene::LOGO:
case SceneManager::Scene::LOADING_SCREEN:
case SceneManager::Scene::CREDITS:
case SceneManager::Scene::DEMO:
case SceneManager::Scene::GAME_OVER:
case SceneManager::Scene::ENDING:
case SceneManager::Scene::ENDING2:
SceneManager::current = SceneManager::Scene::TITLE;
SceneManager::options = SceneManager::Options::NONE;
break;
default:

View File

@@ -1,3 +1,5 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "core/system/director.hpp"
#include <SDL3/SDL.h>
@@ -542,41 +544,41 @@ void Director::runGame() {
int Director::run() {
// Bucle principal
while (Options::section.section != Options::Scene::QUIT) {
switch (Options::section.section) {
case Options::Scene::LOGO:
while (SceneManager::current != SceneManager::Scene::QUIT) {
switch (SceneManager::current) {
case SceneManager::Scene::LOGO:
runLogo();
break;
case Options::Scene::LOADING_SCREEN:
case SceneManager::Scene::LOADING_SCREEN:
runLoadingScreen();
break;
case Options::Scene::TITLE:
case SceneManager::Scene::TITLE:
runTitle();
break;
case Options::Scene::CREDITS:
case SceneManager::Scene::CREDITS:
runCredits();
break;
case Options::Scene::DEMO:
case SceneManager::Scene::DEMO:
runDemo();
break;
case Options::Scene::GAME:
case SceneManager::Scene::GAME:
runGame();
break;
case Options::Scene::GAME_OVER:
case SceneManager::Scene::GAME_OVER:
runGameOver();
break;
case Options::Scene::ENDING:
case SceneManager::Scene::ENDING:
runEnding();
break;
case Options::Scene::ENDING2:
case SceneManager::Scene::ENDING2:
runEnding2();
break;

View File

@@ -7,8 +7,6 @@
// Forward declarations from Options namespace
namespace Options {
enum class Scene;
enum class SceneOptions;
enum class ControlScheme;
enum class NotificationPosition;
} // namespace Options
@@ -65,12 +63,6 @@ constexpr Options::NotificationPosition NOTIFICATION_POSITION = Options::Notific
constexpr bool NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto
const Uint8 NOTIFICATION_COLOR = static_cast<Uint8>(PaletteColor::BLUE); // Color de las notificaciones por defecto
// =============================================================================
// SCENE
// =============================================================================
constexpr Options::Scene SCENE = Options::Scene::LOGO; // Sección por defecto
constexpr Options::SceneOptions SUBSECTION = Options::SceneOptions::LOGO_TO_INTRO; // Subsección por defecto
// =============================================================================
// CONTROL
// =============================================================================

View File

@@ -26,18 +26,14 @@ Notification notifications; // Opciones relativas a las notificaciones;
Window window; // Opciones relativas a la ventana
Audio audio; // Opciones relativas al audio
ControlScheme keys; // Teclas usadas para jugar
SceneState section; // Sección actual del programa
bool setOptions(const std::string& var, const std::string& value);
// Crea e inicializa las opciones del programa
void init() {
#ifdef DEBUG
section = SceneState(Scene::ENDING2, SceneOptions::LOGO_TO_INTRO);
console = true;
#else
section = SceneState(Scene::LOGO, SceneOptions::LOGO_TO_INTRO);
console = false;
#endif
}

View File

@@ -20,29 +20,6 @@ constexpr int convertVolume(int volume_percent) {
}
} // namespace VolumeHelpers
// Secciones del programa
enum class Scene {
LOGO,
LOADING_SCREEN,
TITLE,
CREDITS,
GAME,
DEMO,
GAME_OVER,
ENDING,
ENDING2,
QUIT
};
// Subsecciones
enum class SceneOptions {
NONE,
LOGO_TO_INTRO,
LOGO_TO_TITLE,
TITLE_WITH_LOADING_SCREEN,
TITLE_WITHOUT_LOADING_SCREEN
};
// Posiciones de las notificaciones
enum class NotificationPosition {
UPPER_LEFT,
@@ -125,22 +102,6 @@ struct Notification {
}
};
// Estructura para saber la seccion y subseccion del programa
struct SceneState {
Scene section;
SceneOptions subsection;
// Constructor por defecto
SceneState()
: section(GameDefaults::SCENE),
subsection(GameDefaults::SUBSECTION) {}
// Constructor
SceneState(Scene scene, SceneOptions scene_options)
: section(scene),
subsection(scene_options) {}
};
// Estructura para albergar trucos
struct Cheat {
enum class State : bool {
@@ -362,7 +323,6 @@ extern Notification notifications; // Opciones relativas a las notificaciones;
extern Window window; // Opciones relativas a la ventana
extern Audio audio; // Opciones relativas al audio
extern ControlScheme keys; // Teclas usadas para jugar
extern SceneState section; // Sección actual del programa
// --- Funciones ---
void init(); // Crea e inicializa las opciones del programa

View File

@@ -0,0 +1,39 @@
#pragma once
/*
Namespace SceneManager: gestiona el flujo entre las diferentes escenas del juego.
Define las escenas principales del programa y las opciones de transición entre ellas.
Proporciona variables globales inline para gestionar el estado actual de la escena.
*/
namespace SceneManager {
// --- Escenas del programa ---
enum class Scene {
LOGO, // Pantalla del logo
LOADING_SCREEN, // Pantalla de carga
TITLE, // Pantalla de título/menú principal
CREDITS, // Créditos del juego
GAME, // Juego principal
DEMO, // Modo demostración
GAME_OVER, // Pantalla de game over
ENDING, // Final del juego (ending 1)
ENDING2, // Final del juego (ending 2)
QUIT // Salir del programa
};
// --- Opciones para transiciones entre escenas ---
enum class Options {
NONE, // Sin opciones especiales
LOGO_TO_INTRO, // Del logo a la intro
LOGO_TO_TITLE, // Del logo al título
TITLE_WITH_LOADING_SCREEN, // Al título mostrando pantalla de carga
TITLE_WITHOUT_LOADING_SCREEN // Al título sin pantalla de carga
};
// --- Variables de estado globales (inline C++17) ---
inline Scene current = Scene::LOGO; // Escena actual
inline Options options = Options::NONE; // Opciones de la escena actual
} // namespace SceneManager

View File

@@ -1,3 +1,5 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/scenes/credits.hpp"
#include <SDL3/SDL.h>
@@ -19,8 +21,8 @@
Credits::Credits()
: shining_sprite_(std::make_shared<SAnimatedSprite>(Resource::get()->getSurface("shine.gif"), Resource::get()->getAnimations("shine.ani"))) {
// Inicializa variables
Options::section.section = Options::Scene::CREDITS;
Options::section.subsection = Options::SceneOptions::NONE;
SceneManager::current = SceneManager::Scene::CREDITS;
SceneManager::options = SceneManager::Options::NONE;
shining_sprite_->setPos({194, 174, 8, 8});
// Cambia el color del borde
@@ -165,7 +167,7 @@ void Credits::updateCounter() {
// Comprueba si ha terminado la sección
if (counter_ > 1200) {
Options::section.section = Options::Scene::DEMO;
SceneManager::current = SceneManager::Scene::DEMO;
}
}
@@ -218,7 +220,7 @@ void Credits::render() {
// Bucle para el logo del juego
void Credits::run() {
while (Options::section.section == Options::Scene::CREDITS) {
while (SceneManager::current == SceneManager::Scene::CREDITS) {
update();
checkEvents();
render();

View File

@@ -1,3 +1,5 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/scenes/ending.hpp"
#include <SDL3/SDL.h>
@@ -23,8 +25,8 @@ Ending::Ending()
cover_counter_(0),
ticks_(0),
current_scene_(0) {
Options::section.section = Options::Scene::ENDING;
Options::section.subsection = Options::SceneOptions::NONE;
SceneManager::current = SceneManager::Scene::ENDING;
SceneManager::options = SceneManager::Options::NONE;
// Inicializa los textos
iniTexts();
@@ -359,7 +361,7 @@ void Ending::iniScenes() {
void Ending::run() {
JA_PlayMusic(Resource::get()->getMusic("ending1.ogg"));
while (Options::section.section == Options::Scene::ENDING) {
while (SceneManager::current == SceneManager::Scene::ENDING) {
update();
checkEvents();
render();
@@ -423,7 +425,7 @@ void Ending::checkChangeScene() {
cover_counter_ = 0;
if (current_scene_ == 5) {
// Termina el bucle
Options::section.section = Options::Scene::ENDING2;
SceneManager::current = SceneManager::Scene::ENDING2;
// Mantiene los valores anteriores
current_scene_ = 4;

View File

@@ -1,3 +1,5 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/scenes/ending2.hpp"
#include <SDL3/SDL.h>
@@ -20,8 +22,8 @@
// Constructor
Ending2::Ending2()
: state_(EndingState::PRE_CREDITS, SDL_GetTicks(), STATE_PRE_CREDITS_DURATION_) {
Options::section.section = Options::Scene::ENDING2;
Options::section.subsection = Options::SceneOptions::NONE;
SceneManager::current = SceneManager::Scene::ENDING2;
SceneManager::options = SceneManager::Options::NONE;
// Inicializa el vector de colores
const std::vector<std::string> COLORS = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
@@ -146,7 +148,7 @@ void Ending2::checkInput() {
void Ending2::run() {
JA_PlayMusic(Resource::get()->getMusic("ending2.ogg"));
while (Options::section.section == Options::Scene::ENDING2) {
while (SceneManager::current == SceneManager::Scene::ENDING2) {
update();
checkEvents();
render();
@@ -179,8 +181,8 @@ void Ending2::updateState() {
case EndingState::FADING:
if (state_.hasEnded(EndingState::FADING)) {
Options::section.section = Options::Scene::LOGO;
Options::section.subsection = Options::SceneOptions::LOGO_TO_INTRO;
SceneManager::current = SceneManager::Scene::LOGO;
SceneManager::options = SceneManager::Options::LOGO_TO_INTRO;
}
break;

View File

@@ -1,3 +1,5 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/scenes/game.hpp"
#include <SDL3/SDL.h>
@@ -58,8 +60,8 @@ Game::Game(GameMode mode)
Cheevos::get()->enable(!Options::cheats.enabled()); // Deshabilita los logros si hay trucos activados
Cheevos::get()->clearUnobtainableState();
Options::section.section = (mode_ == GameMode::GAME) ? Options::Scene::GAME : Options::Scene::DEMO;
Options::section.subsection = Options::SceneOptions::NONE;
SceneManager::current = (mode_ == GameMode::GAME) ? SceneManager::Scene::GAME : SceneManager::Scene::DEMO;
SceneManager::options = SceneManager::Options::NONE;
}
Game::~Game() {
@@ -100,7 +102,7 @@ void Game::run() {
JA_PauseMusic();
}
while (Options::section.section == Options::Scene::GAME || Options::section.section == Options::Scene::DEMO) {
while (SceneManager::current == SceneManager::Scene::GAME || SceneManager::current == SceneManager::Scene::DEMO) {
update();
checkEvents();
render();
@@ -335,7 +337,7 @@ void Game::checkIfPlayerIsAlive() {
// Comprueba si ha terminado la partida
void Game::checkGameOver() {
if (board_->lives < 0 && black_screen_counter_ > 17) {
Options::section.section = Options::Scene::GAME_OVER;
SceneManager::current = SceneManager::Scene::GAME_OVER;
}
}
@@ -427,7 +429,7 @@ bool Game::checkEndGame() {
// Comprueba los logros de completar el juego
checkEndGameCheevos();
Options::section.section = Options::Scene::ENDING;
SceneManager::current = SceneManager::Scene::ENDING;
return true;
}
@@ -610,8 +612,8 @@ void Game::DEMO_checkRoomChange() {
demo_.counter = 0;
demo_.room_index++;
if (demo_.room_index == (int)demo_.rooms.size()) {
Options::section.section = Options::Scene::LOGO;
Options::section.subsection = Options::SceneOptions::LOGO_TO_TITLE;
SceneManager::current = SceneManager::Scene::LOGO;
SceneManager::options = SceneManager::Options::LOGO_TO_TITLE;
} else {
changeRoom(demo_.rooms[demo_.room_index]);
}

View File

@@ -1,3 +1,5 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/scenes/game_over.hpp"
#include <SDL3/SDL.h>
@@ -23,8 +25,8 @@ GameOver::GameOver()
pre_counter_(0),
counter_(0),
ticks_(0) {
Options::section.section = Options::Scene::GAME_OVER;
Options::section.subsection = Options::SceneOptions::NONE;
SceneManager::current = SceneManager::Scene::GAME_OVER;
SceneManager::options = SceneManager::Options::NONE;
player_sprite_->setPosX(GAMECANVAS_CENTER_X + 10);
player_sprite_->setPosY(30);
@@ -112,7 +114,7 @@ void GameOver::checkInput() {
// Bucle principal
void GameOver::run() {
while (Options::section.section == Options::Scene::GAME_OVER) {
while (SceneManager::current == SceneManager::Scene::GAME_OVER) {
update();
checkEvents();
render();
@@ -156,7 +158,7 @@ void GameOver::updateCounters() {
// Comprueba si ha terminado la sección
else if (counter_ == COUNTER_SECTION_END_) {
Options::section.section = Options::Scene::LOGO;
Options::section.subsection = Options::SceneOptions::LOGO_TO_TITLE;
SceneManager::current = SceneManager::Scene::LOGO;
SceneManager::options = SceneManager::Options::LOGO_TO_TITLE;
}
}

View File

@@ -1,3 +1,5 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/scenes/loading_screen.hpp"
#include <SDL3/SDL.h>
@@ -25,8 +27,8 @@ LoadingScreen::LoadingScreen()
screen_surface_->clear(static_cast<Uint8>(PaletteColor::WHITE));
// Inicializa variables
Options::section.section = Options::Scene::LOADING_SCREEN;
Options::section.subsection = Options::SceneOptions::NONE;
SceneManager::current = SceneManager::Scene::LOADING_SCREEN;
SceneManager::options = SceneManager::Options::NONE;
// Establece el orden de las lineas para imitar el direccionamiento de memoria del spectrum
for (int i = 0; i < 192; ++i) {
@@ -96,8 +98,8 @@ void LoadingScreen::updateLoad() {
// Comprueba si ha terminado la intro
if (load_counter_ >= 768) {
Options::section.section = Options::Scene::TITLE;
Options::section.subsection = Options::SceneOptions::TITLE_WITH_LOADING_SCREEN;
SceneManager::current = SceneManager::Scene::TITLE;
SceneManager::options = SceneManager::Options::TITLE_WITH_LOADING_SCREEN;
JA_StopMusic();
}
}
@@ -189,7 +191,7 @@ void LoadingScreen::run() {
Screen::get()->clearRenderer();
Screen::get()->render();
while (Options::section.section == Options::Scene::LOADING_SCREEN) {
while (SceneManager::current == SceneManager::Scene::LOADING_SCREEN) {
update();
checkEvents();
render();

View File

@@ -1,3 +1,5 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/scenes/logo.hpp"
#include <SDL3/SDL.h>
@@ -30,7 +32,7 @@ Logo::Logo()
}
// Inicializa variables
Options::section.section = Options::Scene::LOGO;
SceneManager::current = SceneManager::Scene::LOGO;
// Inicializa el vector de colores
const std::vector<Uint8> COLORS = {
@@ -206,7 +208,7 @@ void Logo::render() {
// Bucle para el logo del juego
void Logo::run() {
while (Options::section.section == Options::Scene::LOGO) {
while (SceneManager::current == SceneManager::Scene::LOGO) {
update();
checkEvents();
render();
@@ -215,11 +217,11 @@ void Logo::run() {
// Termina la sección
void Logo::endSection() {
if (Options::section.subsection == Options::SceneOptions::LOGO_TO_TITLE) {
Options::section.section = Options::Scene::TITLE;
if (SceneManager::options == SceneManager::Options::LOGO_TO_TITLE) {
SceneManager::current = SceneManager::Scene::TITLE;
}
else if (Options::section.subsection == Options::SceneOptions::LOGO_TO_INTRO) {
Options::section.section = Options::Scene::LOADING_SCREEN;
else if (SceneManager::options == SceneManager::Options::LOGO_TO_INTRO) {
SceneManager::current = SceneManager::Scene::LOADING_SCREEN;
}
}

View File

@@ -1,3 +1,5 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/scenes/title.hpp"
#include <SDL3/SDL.h>
@@ -25,9 +27,9 @@ Title::Title()
loading_screen_sprite_(std::make_shared<SSprite>(loading_screen_surface_, 0, 0, loading_screen_surface_->getWidth(), loading_screen_surface_->getHeight())),
bg_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)) {
// Inicializa variables
state_ = Options::section.subsection == Options::SceneOptions::TITLE_WITH_LOADING_SCREEN ? TitleState::SHOW_LOADING_SCREEN : TitleState::SHOW_MENU;
Options::section.section = Options::Scene::TITLE;
Options::section.subsection = Options::SceneOptions::NONE;
state_ = SceneManager::options == SceneManager::Options::TITLE_WITH_LOADING_SCREEN ? TitleState::SHOW_LOADING_SCREEN : TitleState::SHOW_MENU;
SceneManager::current = SceneManager::Scene::TITLE;
SceneManager::options = SceneManager::Options::NONE;
initMarquee();
// Crea y rellena la textura para mostrar los logros
@@ -68,8 +70,8 @@ void Title::checkEvents() {
if (!show_cheevos_) {
switch (event.key.key) {
case SDLK_1:
Options::section.section = Options::Scene::GAME;
Options::section.subsection = Options::SceneOptions::NONE;
SceneManager::current = SceneManager::Scene::GAME;
SceneManager::options = SceneManager::Options::NONE;
break;
case SDLK_2:
@@ -180,8 +182,8 @@ void Title::update() {
// Si el contador alcanza cierto valor, termina la seccion
if (counter_ == 2200) {
if (!show_cheevos_) {
Options::section.section = Options::Scene::CREDITS;
Options::section.subsection = Options::SceneOptions::NONE;
SceneManager::current = SceneManager::Scene::CREDITS;
SceneManager::options = SceneManager::Options::NONE;
}
}
break;
@@ -228,7 +230,7 @@ void Title::render() {
// Bucle para el logo del juego
void Title::run() {
while (Options::section.section == Options::Scene::TITLE) {
while (SceneManager::current == SceneManager::Scene::TITLE) {
update();
checkEvents();
render();

View File

@@ -1,3 +1,5 @@
#include "game/scene_manager.hpp" // Para SceneManager
#include "utils/global_events.hpp"
#include "core/input/mouse.hpp"
@@ -8,7 +10,7 @@ namespace globalEvents {
void check(const SDL_Event& event) {
// Evento de salida de la aplicación
if (event.type == SDL_EVENT_QUIT) {
Options::section.section = Options::Scene::QUIT;
SceneManager::current = SceneManager::Scene::QUIT;
return;
}