forked from jaildesigner-jailgames/jaildoctors_dilemma
migrat Input a la ultima versió
cohesionats tots els metodes update de les escenes
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
|
||||
#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
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||
@@ -40,16 +42,17 @@ Credits::Credits()
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Credits::checkEvents() {
|
||||
void Credits::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Credits::checkInput() {
|
||||
GlobalInputs::check();
|
||||
void Credits::handleInput() {
|
||||
Input::get()->update();
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Inicializa los textos
|
||||
@@ -153,24 +156,21 @@ void Credits::fillTexture() {
|
||||
// Actualiza las variables
|
||||
void Credits::update() {
|
||||
// Obtiene el delta time
|
||||
current_delta_ = delta_timer_->tick();
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
total_time_ += DELTA_TIME; // Actualiza el tiempo total
|
||||
|
||||
// Comprueba las entradas
|
||||
checkInput();
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
// Actualiza el tiempo total
|
||||
total_time_ += current_delta_;
|
||||
|
||||
// Actualiza la máquina de estados
|
||||
updateState(current_delta_);
|
||||
|
||||
// Actualiza la pantalla
|
||||
Screen::get()->update(current_delta_);
|
||||
updateState(DELTA_TIME); // Actualiza la máquina de estados
|
||||
|
||||
// Actualiza el sprite con el brillo si está después del tiempo de inicio
|
||||
if (reveal_time_ > SHINE_START_TIME) {
|
||||
shining_sprite_->update(current_delta_);
|
||||
shining_sprite_->update(DELTA_TIME);
|
||||
}
|
||||
|
||||
Audio::get()->update(); // Actualiza el objeto Audio
|
||||
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
|
||||
}
|
||||
|
||||
// Transición entre estados
|
||||
@@ -276,7 +276,6 @@ void Credits::render() {
|
||||
void Credits::run() {
|
||||
while (SceneManager::current == SceneManager::Scene::CREDITS) {
|
||||
update();
|
||||
checkEvents();
|
||||
render();
|
||||
}
|
||||
}
|
||||
@@ -33,16 +33,16 @@ class Credits {
|
||||
};
|
||||
|
||||
// --- Constantes de tiempo (basado en 60 FPS) ---
|
||||
static constexpr float REVEAL_PHASE_1_DURATION = 3.733F; // 224 frames @ 60fps
|
||||
static constexpr float PAUSE_DURATION = 1.667F; // 100 frames @ 60fps
|
||||
static constexpr float REVEAL_PHASE_2_DURATION = 5.333F; // 320 frames (544-224) @ 60fps
|
||||
static constexpr float REVEAL_PHASE_3_DURATION = 2.133F; // 128 frames (672-544) @ 60fps
|
||||
static constexpr float DISPLAY_WITH_SHINE_DURATION = 7.967F; // 478 frames (1150-672) @ 60fps
|
||||
static constexpr float FADE_OUT_DURATION = 0.833F; // 50 frames (1200-1150) @ 60fps
|
||||
static constexpr float TOTAL_DURATION = 20.0F; // 1200 frames @ 60fps
|
||||
static constexpr float SHINE_START_TIME = 12.833F; // 770 frames @ 60fps
|
||||
static constexpr float FADE_OUT_START = 19.167F; // 1150 frames @ 60fps
|
||||
static constexpr float REVEAL_SPEED = 60.0F; // counter equivalente por segundo @ 60fps
|
||||
static constexpr float REVEAL_PHASE_1_DURATION = 3.733F; // 224 frames @ 60fps
|
||||
static constexpr float PAUSE_DURATION = 1.667F; // 100 frames @ 60fps
|
||||
static constexpr float REVEAL_PHASE_2_DURATION = 5.333F; // 320 frames (544-224) @ 60fps
|
||||
static constexpr float REVEAL_PHASE_3_DURATION = 2.133F; // 128 frames (672-544) @ 60fps
|
||||
static constexpr float DISPLAY_WITH_SHINE_DURATION = 7.967F; // 478 frames (1150-672) @ 60fps
|
||||
static constexpr float FADE_OUT_DURATION = 0.833F; // 50 frames (1200-1150) @ 60fps
|
||||
static constexpr float TOTAL_DURATION = 20.0F; // 1200 frames @ 60fps
|
||||
static constexpr float SHINE_START_TIME = 12.833F; // 770 frames @ 60fps
|
||||
static constexpr float FADE_OUT_START = 19.167F; // 1150 frames @ 60fps
|
||||
static constexpr float REVEAL_SPEED = 60.0F; // counter equivalente por segundo @ 60fps
|
||||
struct Captions {
|
||||
std::string label; // Texto a escribir
|
||||
Uint8 color; // Color del texto
|
||||
@@ -59,16 +59,15 @@ class Credits {
|
||||
float state_time_ = 0.0F; // Tiempo acumulado en el estado actual
|
||||
float total_time_ = 0.0F; // Tiempo total acumulado
|
||||
float reveal_time_ = 0.0F; // Tiempo acumulado solo durante revelación (se congela en pausas)
|
||||
float current_delta_ = 0.0F; // Delta time del frame actual
|
||||
std::vector<Captions> texts_; // Vector con los textos
|
||||
|
||||
// --- Funciones ---
|
||||
void update(); // Actualiza las variables
|
||||
void render(); // Dibuja en pantalla
|
||||
static void checkEvents(); // Comprueba el manejador de eventos
|
||||
static void checkInput(); // Comprueba las entradas
|
||||
void updateState(float delta_time); // Actualiza la máquina de estados
|
||||
void transitionToState(State new_state); // Transición entre estados
|
||||
void iniTexts(); // Inicializa los textos
|
||||
void fillTexture(); // Escribe el texto en la textura
|
||||
void update(); // Actualiza las variables
|
||||
void render(); // Dibuja en pantalla
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void updateState(float delta_time); // Actualiza la máquina de estados
|
||||
void transitionToState(State new_state); // Transición entre estados
|
||||
void iniTexts(); // Inicializa los textos
|
||||
void fillTexture(); // Escribe el texto en la textura
|
||||
};
|
||||
|
||||
@@ -4,14 +4,15 @@
|
||||
|
||||
#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
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||
#include "core/rendering/text.hpp" // Para Text, TEXT_STROKE
|
||||
#include "core/resources/resource.hpp" // Para Resource
|
||||
#include "core/system/global_events.hpp" // Para check
|
||||
#include "core/audio/audio.hpp" // Para Audio
|
||||
#include "game/options.hpp" // Para Options, options, OptionsGame, SectionS...
|
||||
#include "game/scene_manager.hpp" // Para SceneManager
|
||||
#include "utils/defines.hpp" // Para GAME_SPEED
|
||||
@@ -46,22 +47,17 @@ Ending::Ending()
|
||||
// Actualiza el objeto
|
||||
void Ending::update() {
|
||||
// Obtiene el delta time
|
||||
current_delta_ = delta_timer_->tick();
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
total_time_ += DELTA_TIME; // Actualiza el tiempo total
|
||||
|
||||
// Comprueba las entradas
|
||||
checkInput();
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
// Actualiza el tiempo total
|
||||
total_time_ += current_delta_;
|
||||
updateState(DELTA_TIME); // Actualiza la máquina de estados
|
||||
updateSpriteCovers(); // Actualiza las cortinillas de los elementos
|
||||
|
||||
// Actualiza la máquina de estados
|
||||
updateState(current_delta_);
|
||||
|
||||
// Actualiza las cortinillas de los elementos
|
||||
updateSpriteCovers();
|
||||
|
||||
// Actualiza el objeto Screen
|
||||
Screen::get()->update(current_delta_);
|
||||
Audio::get()->update(); // Actualiza el objeto Audio
|
||||
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
|
||||
}
|
||||
|
||||
// Dibuja el final en pantalla
|
||||
@@ -98,16 +94,17 @@ void Ending::render() {
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Ending::checkEvents() {
|
||||
void Ending::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Ending::checkInput() {
|
||||
GlobalInputs::check();
|
||||
void Ending::handleInput() {
|
||||
Input::get()->update();
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Transición entre estados
|
||||
@@ -424,7 +421,6 @@ void Ending::run() {
|
||||
|
||||
while (SceneManager::current == SceneManager::Scene::ENDING) {
|
||||
update();
|
||||
checkEvents();
|
||||
render();
|
||||
}
|
||||
|
||||
@@ -472,8 +468,7 @@ void Ending::updateSpriteCovers() {
|
||||
0,
|
||||
sprite_texts_.at(ti.index).cover_clip_desp,
|
||||
sprite_texts_.at(ti.index).cover_sprite->getWidth(),
|
||||
sprite_texts_.at(ti.index).cover_clip_height
|
||||
);
|
||||
sprite_texts_.at(ti.index).cover_clip_height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,12 +491,7 @@ void Ending::updateSpriteCovers() {
|
||||
sprite_pics_.at(current_scene_).cover_sprite->setY(Y_INITIAL + static_cast<int>(CONTENT_PIXELS));
|
||||
}
|
||||
|
||||
sprite_pics_.at(current_scene_).cover_sprite->setClip(
|
||||
0,
|
||||
sprite_pics_.at(current_scene_).cover_clip_desp,
|
||||
sprite_pics_.at(current_scene_).cover_sprite->getWidth(),
|
||||
sprite_pics_.at(current_scene_).cover_clip_height
|
||||
);
|
||||
sprite_pics_.at(current_scene_).cover_sprite->setClip(0, sprite_pics_.at(current_scene_).cover_clip_desp, sprite_pics_.at(current_scene_).cover_sprite->getWidth(), sprite_pics_.at(current_scene_).cover_clip_height);
|
||||
}
|
||||
|
||||
// Comprueba si se ha de cambiar de escena
|
||||
|
||||
@@ -31,17 +31,17 @@ class Ending {
|
||||
};
|
||||
|
||||
// --- Constantes de tiempo (basado en 60 FPS) ---
|
||||
static constexpr float WARMUP_DURATION = 3.333F; // 200 frames @ 60fps
|
||||
static constexpr float FADEOUT_DURATION = 1.667F; // 100 frames @ 60fps
|
||||
static constexpr float SCENE_0_DURATION = 16.667F; // 1000 frames @ 60fps
|
||||
static constexpr float SCENE_1_DURATION = 23.333F; // 1400 frames @ 60fps
|
||||
static constexpr float SCENE_2_DURATION = 16.667F; // 1000 frames @ 60fps
|
||||
static constexpr float SCENE_3_DURATION = 13.333F; // 800 frames @ 60fps
|
||||
static constexpr float SCENE_4_DURATION = 16.667F; // 1000 frames @ 60fps
|
||||
static constexpr float TEXT_REVEAL_SPEED = 30.0F; // 2px cada 4 frames @ 60fps
|
||||
static constexpr float IMAGE_REVEAL_SPEED = 60.0F; // 2px cada 2 frames @ 60fps
|
||||
static constexpr float TEXT_LAPSE = 1.333F; // 80 frames @ 60fps
|
||||
static constexpr float FADEOUT_START_OFFSET = 1.667F; // Inicio fade-out 100 frames antes del fin
|
||||
static constexpr float WARMUP_DURATION = 3.333F; // 200 frames @ 60fps
|
||||
static constexpr float FADEOUT_DURATION = 1.667F; // 100 frames @ 60fps
|
||||
static constexpr float SCENE_0_DURATION = 16.667F; // 1000 frames @ 60fps
|
||||
static constexpr float SCENE_1_DURATION = 23.333F; // 1400 frames @ 60fps
|
||||
static constexpr float SCENE_2_DURATION = 16.667F; // 1000 frames @ 60fps
|
||||
static constexpr float SCENE_3_DURATION = 13.333F; // 800 frames @ 60fps
|
||||
static constexpr float SCENE_4_DURATION = 16.667F; // 1000 frames @ 60fps
|
||||
static constexpr float TEXT_REVEAL_SPEED = 30.0F; // 2px cada 4 frames @ 60fps
|
||||
static constexpr float IMAGE_REVEAL_SPEED = 60.0F; // 2px cada 2 frames @ 60fps
|
||||
static constexpr float TEXT_LAPSE = 1.333F; // 80 frames @ 60fps
|
||||
static constexpr float FADEOUT_START_OFFSET = 1.667F; // Inicio fade-out 100 frames antes del fin
|
||||
|
||||
// --- Estructuras ---
|
||||
struct EndingSurface // Estructura con dos texturas y sprites, uno para mostrar y el otro hace de cortinilla
|
||||
@@ -81,25 +81,24 @@ class Ending {
|
||||
float state_time_ = 0.0F; // Tiempo acumulado en el estado actual
|
||||
float total_time_ = 0.0F; // Tiempo total acumulado desde el inicio
|
||||
float fadeout_time_ = 0.0F; // Tiempo acumulado para el fade-out
|
||||
float current_delta_ = 0.0F; // Delta time del frame actual
|
||||
std::vector<EndingSurface> sprite_texts_; // Vector con los sprites de texto con su cortinilla
|
||||
std::vector<EndingSurface> sprite_pics_; // Vector con los sprites de texto con su cortinilla
|
||||
int current_scene_ = 0; // Escena actual (0-4)
|
||||
std::vector<SceneData> scenes_; // Vector con los textos e imagenes de cada escena
|
||||
|
||||
// --- Funciones ---
|
||||
void update(); // Actualiza el objeto
|
||||
void render(); // Dibuja el final en pantalla
|
||||
static void checkEvents(); // Comprueba el manejador de eventos
|
||||
static void checkInput(); // Comprueba las entradas
|
||||
void iniTexts(); // Inicializa los textos
|
||||
void iniPics(); // Inicializa las imagenes
|
||||
void iniScenes(); // Inicializa las escenas
|
||||
void updateState(float delta_time); // Actualiza la máquina de estados
|
||||
void transitionToState(State new_state); // Transición entre estados
|
||||
void updateSpriteCovers(); // Actualiza las cortinillas de los elementos
|
||||
void checkChangeScene(); // Comprueba si se ha de cambiar de escena
|
||||
void fillCoverTexture(); // Rellena la textura para la cortinilla
|
||||
void renderCoverTexture(); // Dibuja la cortinilla de cambio de escena
|
||||
void updateMusicVolume() const; // Actualiza el volumen de la musica
|
||||
void update(); // Actualiza el objeto
|
||||
void render(); // Dibuja el final en pantalla
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void iniTexts(); // Inicializa los textos
|
||||
void iniPics(); // Inicializa las imagenes
|
||||
void iniScenes(); // Inicializa las escenas
|
||||
void updateState(float delta_time); // Actualiza la máquina de estados
|
||||
void transitionToState(State new_state); // Transición entre estados
|
||||
void updateSpriteCovers(); // Actualiza las cortinillas de los elementos
|
||||
void checkChangeScene(); // Comprueba si se ha de cambiar de escena
|
||||
void fillCoverTexture(); // Rellena la textura para la cortinilla
|
||||
void renderCoverTexture(); // Dibuja la cortinilla de cambio de escena
|
||||
void updateMusicVolume() const; // Actualiza el volumen de la musica
|
||||
};
|
||||
@@ -6,6 +6,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/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||
@@ -54,20 +55,19 @@ Ending2::Ending2()
|
||||
// Actualiza el objeto
|
||||
void Ending2::update() {
|
||||
// Obtiene el delta time
|
||||
current_delta_ = delta_timer_->tick();
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
|
||||
// Comprueba las entradas
|
||||
checkInput();
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
// Actualiza el estado
|
||||
updateState(current_delta_);
|
||||
updateState(DELTA_TIME); // Actualiza el estado
|
||||
|
||||
switch (state_.state) {
|
||||
case EndingState::CREDITS:
|
||||
// Actualiza los sprites, los textos y los textos del final
|
||||
updateSprites(current_delta_);
|
||||
updateTextSprites(current_delta_);
|
||||
updateTexts(current_delta_);
|
||||
updateSprites(DELTA_TIME);
|
||||
updateTextSprites(DELTA_TIME);
|
||||
updateTexts(DELTA_TIME);
|
||||
break;
|
||||
|
||||
case EndingState::FADING:
|
||||
@@ -80,8 +80,8 @@ void Ending2::update() {
|
||||
break;
|
||||
}
|
||||
|
||||
// Actualiza el objeto
|
||||
Screen::get()->update(current_delta_);
|
||||
Audio::get()->update(); // Actualiza el objeto Audio
|
||||
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
|
||||
}
|
||||
|
||||
// Dibuja el final en pantalla
|
||||
@@ -127,16 +127,17 @@ void Ending2::render() {
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Ending2::checkEvents() {
|
||||
void Ending2::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Ending2::checkInput() {
|
||||
GlobalInputs::check();
|
||||
void Ending2::handleInput() {
|
||||
Input::get()->update();
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
@@ -145,7 +146,6 @@ void Ending2::run() {
|
||||
|
||||
while (SceneManager::current == SceneManager::Scene::ENDING2) {
|
||||
update();
|
||||
checkEvents();
|
||||
render();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,11 +50,11 @@ class Ending2 {
|
||||
static constexpr int TEXT_SPACING_MULTIPLIER = 2; // Multiplicador para espaciado entre líneas de texto
|
||||
|
||||
// Constantes de tiempo (basadas en tiempo real, no en frames)
|
||||
static constexpr float SPRITE_DESP_SPEED = -12.0F; // Velocidad de desplazamiento en pixels/segundo (era -0.2 px/frame @ 60fps)
|
||||
static constexpr float STATE_PRE_CREDITS_DURATION = 3.0F; // Duración del estado previo a créditos en segundos
|
||||
static constexpr float STATE_POST_CREDITS_DURATION = 5.0F; // Duración del estado posterior a créditos en segundos
|
||||
static constexpr float STATE_FADE_DURATION = 5.0F; // Duración del fade final en segundos
|
||||
static constexpr int MUSIC_FADE_DURATION = 3000; // Duración del fade de música en milisegundos (para Audio API)
|
||||
static constexpr float SPRITE_DESP_SPEED = -12.0F; // Velocidad de desplazamiento en pixels/segundo (era -0.2 px/frame @ 60fps)
|
||||
static constexpr float STATE_PRE_CREDITS_DURATION = 3.0F; // Duración del estado previo a créditos en segundos
|
||||
static constexpr float STATE_POST_CREDITS_DURATION = 5.0F; // Duración del estado posterior a créditos en segundos
|
||||
static constexpr float STATE_FADE_DURATION = 5.0F; // Duración del fade final en segundos
|
||||
static constexpr int MUSIC_FADE_DURATION = 3000; // Duración del fade de música en milisegundos (para Audio API)
|
||||
|
||||
// --- Objetos y punteros ---
|
||||
std::vector<std::shared_ptr<SurfaceAnimatedSprite>> sprites_; // Vector con todos los sprites a dibujar
|
||||
@@ -68,26 +68,25 @@ class Ending2 {
|
||||
float sprite_max_width_ = 0; // El valor de ancho del sprite mas ancho
|
||||
float sprite_max_height_ = 0; // El valor de alto del sprite mas alto
|
||||
float state_time_ = 0.0F; // Tiempo acumulado en el estado actual
|
||||
float current_delta_ = 0.0F; // Delta time del frame actual
|
||||
State state_; // Controla el estado de la clase
|
||||
|
||||
// --- Fucniones ---
|
||||
void update(); // Actualiza el objeto
|
||||
void render(); // Dibuja el final en pantalla
|
||||
static void checkEvents(); // Comprueba el manejador de eventos
|
||||
static void checkInput(); // Comprueba las entradas
|
||||
void updateState(float delta_time); // Actualiza el estado
|
||||
void update(); // Actualiza el objeto
|
||||
void render(); // Dibuja el final en pantalla
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void updateState(float delta_time); // Actualiza el estado
|
||||
void transitionToState(EndingState new_state); // Transición entre estados
|
||||
void iniSpriteList(); // Inicializa la lista de sprites
|
||||
void loadSprites(); // Carga todos los sprites desde una lista
|
||||
void updateSprites(float delta); // Actualiza los sprites
|
||||
void updateTextSprites(float delta); // Actualiza los sprites de texto
|
||||
void updateTexts(float delta); // Actualiza los sprites de texto del final
|
||||
void renderSprites(); // Dibuja los sprites
|
||||
void renderSpriteTexts(); // Dibuja los sprites con el texto
|
||||
void renderTexts(); // Dibuja los sprites con el texto del final
|
||||
void placeSprites(); // Coloca los sprites en su sito
|
||||
void createSpriteTexts(); // Crea los sprites con las texturas con los textos
|
||||
void createTexts(); // Crea los sprites con las texturas con los textos del final
|
||||
void updateFinalFade(); // Actualiza el fade final
|
||||
void iniSpriteList(); // Inicializa la lista de sprites
|
||||
void loadSprites(); // Carga todos los sprites desde una lista
|
||||
void updateSprites(float delta); // Actualiza los sprites
|
||||
void updateTextSprites(float delta); // Actualiza los sprites de texto
|
||||
void updateTexts(float delta); // Actualiza los sprites de texto del final
|
||||
void renderSprites(); // Dibuja los sprites
|
||||
void renderSpriteTexts(); // Dibuja los sprites con el texto
|
||||
void renderTexts(); // Dibuja los sprites con el texto del final
|
||||
void placeSprites(); // Coloca los sprites en su sito
|
||||
void createSpriteTexts(); // Crea los sprites con las texturas con los textos
|
||||
void createTexts(); // Crea los sprites con las texturas con los textos del final
|
||||
void updateFinalFade(); // Actualiza el fade final
|
||||
};
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
#include <utility>
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "core/audio/audio.hpp" // Para Audio
|
||||
#include "core/input/global_inputs.hpp" // Para check
|
||||
#include "core/input/input.hpp" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_REPEAT
|
||||
#include "core/input/input.hpp" // Para Input, InputAction, Input::DO_NOT_ALLOW_REPEAT
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||
@@ -14,7 +15,6 @@
|
||||
#include "core/resources/resource.hpp" // Para ResourceRoom, Resource
|
||||
#include "core/system/debug.hpp" // Para Debug
|
||||
#include "core/system/global_events.hpp" // Para check
|
||||
#include "core/audio/audio.hpp" // Para Audio
|
||||
#include "game/gameplay/cheevos.hpp" // Para Cheevos
|
||||
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker
|
||||
#include "game/gameplay/room.hpp" // Para Room, RoomData
|
||||
@@ -69,30 +69,32 @@ Game::~Game() {
|
||||
}
|
||||
|
||||
// Comprueba los eventos de la cola
|
||||
void Game::checkEvents() {
|
||||
void Game::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
#ifdef _DEBUG
|
||||
checkDebugEvents(event);
|
||||
handleDebugEvents(event);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el teclado
|
||||
void Game::checkInput() {
|
||||
if (Input::get()->checkInput(InputAction::TOGGLE_MUSIC, INPUT_DO_NOT_ALLOW_REPEAT)) {
|
||||
void Game::handleInput() {
|
||||
Input::get()->update();
|
||||
|
||||
if (Input::get()->checkAction(InputAction::TOGGLE_MUSIC, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||
board_->music = !board_->music;
|
||||
board_->music ? Audio::get()->resumeMusic() : Audio::get()->pauseMusic();
|
||||
Notifier::get()->show({"MUSIC " + std::string(board_->music ? "ENABLED" : "DISABLED")}, NotificationText::CENTER);
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(InputAction::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT)) {
|
||||
else if (Input::get()->checkAction(InputAction::PAUSE, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||
togglePause();
|
||||
Notifier::get()->show({std::string(paused_ ? "GAME PAUSED" : "GAME RUNNING")}, NotificationText::CENTER);
|
||||
}
|
||||
|
||||
GlobalInputs::check();
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Bucle para el juego
|
||||
@@ -104,7 +106,6 @@ void Game::run() {
|
||||
|
||||
while (SceneManager::current == SceneManager::Scene::GAME || SceneManager::current == SceneManager::Scene::DEMO) {
|
||||
update();
|
||||
checkEvents();
|
||||
render();
|
||||
}
|
||||
|
||||
@@ -118,8 +119,8 @@ void Game::update() {
|
||||
// Calcula el delta time
|
||||
const float DELTA_TIME = delta_timer_.tick();
|
||||
|
||||
// Comprueba el teclado
|
||||
checkInput();
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
#ifdef _DEBUG
|
||||
Debug::get()->clear();
|
||||
@@ -143,7 +144,8 @@ void Game::update() {
|
||||
keepMusicPlaying();
|
||||
updateBlackScreen(DELTA_TIME);
|
||||
|
||||
Screen::get()->update(DELTA_TIME);
|
||||
Audio::get()->update(); // Actualiza el objeto Audio
|
||||
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
|
||||
|
||||
#ifdef _DEBUG
|
||||
updateDebugInfo();
|
||||
@@ -213,7 +215,7 @@ void Game::renderDebugInfo() {
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
void Game::checkDebugEvents(const SDL_Event& event) {
|
||||
void Game::handleDebugEvents(const SDL_Event& event) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {
|
||||
switch (event.key.key) {
|
||||
case SDL_SCANCODE_G:
|
||||
@@ -588,8 +590,8 @@ void Game::keepMusicPlaying() {
|
||||
|
||||
// Si la música no está sonando
|
||||
if (Audio::get()->getMusicState() == Audio::MusicState::STOPPED) {
|
||||
Audio::get()->playMusic(MUSIC_PATH);
|
||||
}
|
||||
Audio::get()->playMusic(MUSIC_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
// DEMO MODE: Inicializa las variables para el modo demo
|
||||
|
||||
@@ -82,10 +82,10 @@ class Game {
|
||||
// --- Funciones ---
|
||||
void update(); // Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||
void render(); // Pinta los objetos en pantalla
|
||||
void checkEvents(); // Comprueba los eventos de la cola
|
||||
void handleEvents(); // Comprueba los eventos de la cola
|
||||
void renderRoomName(); // Escribe el nombre de la pantalla
|
||||
auto changeRoom(const std::string& room_path) -> bool; // Cambia de habitación
|
||||
void checkInput(); // Comprueba el teclado
|
||||
void handleInput(); // Comprueba el teclado
|
||||
void checkPlayerIsOnBorder(); // Comprueba si el jugador esta en el borde de la pantalla y actua
|
||||
auto checkPlayerAndEnemies() -> bool; // Comprueba las colisiones del jugador con los enemigos
|
||||
void checkPlayerAndItems(); // Comprueba las colisiones del jugador con los objetos
|
||||
@@ -110,8 +110,8 @@ class Game {
|
||||
void demoInit(); // DEMO MODE: Inicializa las variables para el modo demo
|
||||
void demoCheckRoomChange(float delta_time); // DEMO MODE: Comprueba si se ha de cambiar de habitación
|
||||
#ifdef _DEBUG
|
||||
void updateDebugInfo(); // Pone la información de debug en pantalla
|
||||
static void renderDebugInfo(); // Pone la información de debug en pantalla
|
||||
void checkDebugEvents(const SDL_Event& event); // Comprueba los eventos
|
||||
void updateDebugInfo(); // Pone la información de debug en pantalla
|
||||
static void renderDebugInfo(); // Pone la información de debug en pantalla
|
||||
void handleDebugEvents(const SDL_Event& event); // Comprueba los eventos
|
||||
#endif
|
||||
};
|
||||
@@ -5,13 +5,14 @@
|
||||
#include <algorithm> // Para min, max
|
||||
#include <string> // Para basic_string, operator+, to_string
|
||||
|
||||
#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/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||
#include "core/rendering/text.hpp" // Para TEXT_CENTER, TEXT_COLOR, Text
|
||||
#include "core/resources/resource.hpp" // Para Resource
|
||||
#include "core/system/global_events.hpp" // Para check
|
||||
#include "core/audio/audio.hpp" // Para Audio
|
||||
#include "game/options.hpp" // Para Options, options, OptionsStats, Secti...
|
||||
#include "game/scene_manager.hpp" // Para SceneManager
|
||||
#include "utils/defines.hpp" // Para GAMECANVAS_CENTER_X
|
||||
@@ -45,24 +46,19 @@ GameOver::GameOver()
|
||||
// Actualiza el objeto
|
||||
void GameOver::update() {
|
||||
// Obtiene el delta time desde el último frame
|
||||
const float delta = delta_timer_->tick();
|
||||
elapsed_time_ += delta;
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
elapsed_time_ += DELTA_TIME;
|
||||
|
||||
// Comprueba las entradas
|
||||
checkInput();
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
// Actualiza el estado de la escena
|
||||
updateState();
|
||||
updateState(); // Actualiza el estado de la escena
|
||||
updateColor(); // Actualiza el color usado para renderizar los textos e imagenes
|
||||
player_sprite_->update(DELTA_TIME); // Actualiza el sprite
|
||||
tv_sprite_->update(DELTA_TIME); // Actualiza el sprite
|
||||
|
||||
// Actualiza el color usado para renderizar los textos e imagenes
|
||||
updateColor();
|
||||
|
||||
// Actualiza los dos sprites con delta time
|
||||
player_sprite_->update(delta);
|
||||
tv_sprite_->update(delta);
|
||||
|
||||
// Actualiza el objeto Screen
|
||||
Screen::get()->update(delta);
|
||||
Audio::get()->update(); // Actualiza el objeto Audio
|
||||
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
|
||||
}
|
||||
|
||||
// Dibuja el final en pantalla
|
||||
@@ -95,23 +91,23 @@ void GameOver::render() {
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void GameOver::checkEvents() {
|
||||
void GameOver::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void GameOver::checkInput() {
|
||||
GlobalInputs::check();
|
||||
void GameOver::handleInput() {
|
||||
Input::get()->update();
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
void GameOver::run() {
|
||||
while (SceneManager::current == SceneManager::Scene::GAME_OVER) {
|
||||
update();
|
||||
checkEvents();
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,35 +19,35 @@ class GameOver {
|
||||
private:
|
||||
// --- Estados ---
|
||||
enum class State {
|
||||
WAITING, // Espera inicial antes de empezar
|
||||
FADE_IN, // Fade in de colores desde black
|
||||
DISPLAY, // Mostrando contenido con color brillante
|
||||
FADE_OUT, // Fade out hacia black
|
||||
ENDING, // Pantalla en negro antes de salir
|
||||
TRANSITION // Cambio a logo
|
||||
WAITING, // Espera inicial antes de empezar
|
||||
FADE_IN, // Fade in de colores desde black
|
||||
DISPLAY, // Mostrando contenido con color brillante
|
||||
FADE_OUT, // Fade out hacia black
|
||||
ENDING, // Pantalla en negro antes de salir
|
||||
TRANSITION // Cambio a logo
|
||||
};
|
||||
|
||||
// --- Constantes de Duración (segundos) ---
|
||||
static constexpr float WAITING_DURATION = 0.8f; // Espera inicial
|
||||
static constexpr float FADE_IN_DURATION = 0.32f; // Duración del fade in
|
||||
static constexpr float DISPLAY_DURATION = 4.64f; // Duración mostrando contenido
|
||||
static constexpr float FADE_OUT_DURATION = 0.32f; // Duración del fade out
|
||||
static constexpr float ENDING_DURATION = 1.12f; // Espera en negro antes de salir
|
||||
static constexpr float WAITING_DURATION = 0.8f; // Espera inicial
|
||||
static constexpr float FADE_IN_DURATION = 0.32f; // Duración del fade in
|
||||
static constexpr float DISPLAY_DURATION = 4.64f; // Duración mostrando contenido
|
||||
static constexpr float FADE_OUT_DURATION = 0.32f; // Duración del fade out
|
||||
static constexpr float ENDING_DURATION = 1.12f; // Espera en negro antes de salir
|
||||
|
||||
// --- Constantes de Posición ---
|
||||
static constexpr int TEXT_Y = 32; // Posición Y del texto principal
|
||||
static constexpr int SPRITE_Y_OFFSET = 30; // Offset Y para sprites desde TEXT_Y
|
||||
static constexpr int PLAYER_X_OFFSET = 10; // Offset X del jugador desde el centro
|
||||
static constexpr int TV_X_OFFSET = 10; // Offset X del TV desde el centro
|
||||
static constexpr int ITEMS_Y_OFFSET = 80; // Offset Y del texto de items desde TEXT_Y
|
||||
static constexpr int ROOMS_Y_OFFSET = 90; // Offset Y del texto de rooms desde TEXT_Y
|
||||
static constexpr int NIGHTMARE_TITLE_Y_OFFSET = 110; // Offset Y del título nightmare desde TEXT_Y
|
||||
static constexpr int NIGHTMARE_TEXT_Y_OFFSET = 120; // Offset Y del texto nightmare desde TEXT_Y
|
||||
static constexpr int TEXT_Y = 32; // Posición Y del texto principal
|
||||
static constexpr int SPRITE_Y_OFFSET = 30; // Offset Y para sprites desde TEXT_Y
|
||||
static constexpr int PLAYER_X_OFFSET = 10; // Offset X del jugador desde el centro
|
||||
static constexpr int TV_X_OFFSET = 10; // Offset X del TV desde el centro
|
||||
static constexpr int ITEMS_Y_OFFSET = 80; // Offset Y del texto de items desde TEXT_Y
|
||||
static constexpr int ROOMS_Y_OFFSET = 90; // Offset Y del texto de rooms desde TEXT_Y
|
||||
static constexpr int NIGHTMARE_TITLE_Y_OFFSET = 110; // Offset Y del título nightmare desde TEXT_Y
|
||||
static constexpr int NIGHTMARE_TEXT_Y_OFFSET = 120; // Offset Y del texto nightmare desde TEXT_Y
|
||||
|
||||
// --- Objetos y punteros ---
|
||||
std::shared_ptr<SurfaceAnimatedSprite> player_sprite_; // Sprite con el jugador
|
||||
std::shared_ptr<SurfaceAnimatedSprite> tv_sprite_; // Sprite con el televisor
|
||||
std::shared_ptr<DeltaTimer> delta_timer_; // Timer para time-based logic
|
||||
std::shared_ptr<DeltaTimer> delta_timer_; // Timer para time-based logic
|
||||
|
||||
// --- Variables ---
|
||||
State state_ = State::WAITING; // Estado actual de la escena
|
||||
@@ -56,11 +56,11 @@ class GameOver {
|
||||
Uint8 color_; // Color usado para el texto y los sprites
|
||||
|
||||
// --- Funciones ---
|
||||
void update(); // Actualiza el objeto
|
||||
void render(); // Dibuja el final en pantalla
|
||||
static void checkEvents(); // Comprueba el manejador de eventos
|
||||
static void checkInput(); // Comprueba las entradas
|
||||
void updateState(); // Actualiza el estado y transiciones
|
||||
void updateColor(); // Actualiza el color usado para renderizar los textos e imagenes
|
||||
void renderSprites(); // Dibuja los sprites
|
||||
void update(); // Actualiza el objeto
|
||||
void render(); // Dibuja el final en pantalla
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void updateState(); // Actualiza el estado y transiciones
|
||||
void updateColor(); // Actualiza el color usado para renderizar los textos e imagenes
|
||||
void renderSprites(); // Dibuja los sprites
|
||||
};
|
||||
@@ -6,6 +6,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/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||
@@ -49,16 +50,17 @@ LoadingScreen::~LoadingScreen() {
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void LoadingScreen::checkEvents() {
|
||||
void LoadingScreen::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void LoadingScreen::checkInput() {
|
||||
GlobalInputs::check();
|
||||
void LoadingScreen::handleInput() {
|
||||
Input::get()->update();
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Inicializa el array de índices de líneas (imita el direccionamiento de memoria del Spectrum)
|
||||
@@ -323,7 +325,9 @@ void LoadingScreen::update() {
|
||||
// Obtener delta time desde el último frame
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
|
||||
checkInput(); // Comprueba las entradas
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
updateState(DELTA_TIME); // Actualiza el estado y gestiona transiciones
|
||||
|
||||
// Actualizar la carga según el estado actual
|
||||
@@ -352,8 +356,8 @@ void LoadingScreen::update() {
|
||||
}
|
||||
|
||||
// Singletones
|
||||
Audio::update(); // Actualiza el objeto Audio
|
||||
Screen::get()->update(); // Actualiza el objeto Screen
|
||||
Audio::update(); // Actualiza el objeto Audio
|
||||
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
|
||||
}
|
||||
|
||||
// Dibuja en pantalla
|
||||
@@ -384,7 +388,6 @@ void LoadingScreen::run() {
|
||||
|
||||
while (SceneManager::current == SceneManager::Scene::LOADING_SCREEN) {
|
||||
update();
|
||||
checkEvents();
|
||||
render();
|
||||
}
|
||||
|
||||
|
||||
@@ -77,8 +77,8 @@ class LoadingScreen {
|
||||
// --- Funciones ---
|
||||
void update(); // Actualiza las variables
|
||||
void render(); // Dibuja en pantalla
|
||||
static void checkEvents(); // Comprueba el manejador de eventos
|
||||
static void checkInput(); // Comprueba las entradas
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void updateState(float delta_time); // Actualiza el estado actual
|
||||
void transitionToState(State new_state); // Transiciona a un nuevo estado
|
||||
void updateMonoLoad(float delta_time); // Gestiona la carga monocromática (time-based)
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
|
||||
#include <algorithm> // Para std::clamp
|
||||
|
||||
#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/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||
@@ -39,16 +41,17 @@ Logo::Logo()
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Logo::checkEvents() {
|
||||
void Logo::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Logo::checkInput() {
|
||||
GlobalInputs::check();
|
||||
void Logo::handleInput() {
|
||||
Input::get()->update();
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Gestiona el logo de JAILGAME (time-based)
|
||||
@@ -180,10 +183,14 @@ void Logo::update() {
|
||||
// Obtener delta time desde el último frame
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
|
||||
checkInput(); // Comprueba las entradas
|
||||
updateState(DELTA_TIME); // Actualiza el estado y gestiona transiciones
|
||||
updateJAILGAMES(DELTA_TIME); // Gestiona el logo de JAILGAME
|
||||
updateTextureColors(); // Gestiona el color de las texturas
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
updateState(DELTA_TIME); // Actualiza el estado y gestiona transiciones
|
||||
updateJAILGAMES(DELTA_TIME); // Gestiona el logo de JAILGAME
|
||||
updateTextureColors(); // Gestiona el color de las texturas
|
||||
|
||||
Audio::get()->update(); // Actualiza el objeto Audio
|
||||
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
|
||||
}
|
||||
|
||||
@@ -207,7 +214,6 @@ void Logo::render() {
|
||||
void Logo::run() {
|
||||
while (SceneManager::current == SceneManager::Scene::LOGO) {
|
||||
update();
|
||||
checkEvents();
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ class Logo {
|
||||
// --- Funciones ---
|
||||
void update(); // Actualiza las variables
|
||||
void render(); // Dibuja en pantalla
|
||||
static void checkEvents(); // Comprueba el manejador de eventos
|
||||
static void checkInput(); // Comprueba las entradas
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAME (time-based)
|
||||
void updateTextureColors(); // Gestiona el color de las texturas
|
||||
void updateState(float delta_time); // Actualiza el estado actual
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
|
||||
#include <algorithm> // Para clamp
|
||||
|
||||
#include "core/audio/audio.hpp" // Para Audio
|
||||
#include "core/input/global_inputs.hpp" // Para check
|
||||
#include "core/input/input.hpp" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_REPEAT, REP...
|
||||
#include "core/input/input.hpp" // Para Input, InputAction, Input::DO_NOT_ALLOW_REPEAT, REP...
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||
@@ -30,8 +31,7 @@ Title::Title()
|
||||
first_active_letter_(0),
|
||||
last_active_letter_(0),
|
||||
state_time_(0.0F),
|
||||
fade_accumulator_(0.0F),
|
||||
current_delta_(0.0F) {
|
||||
fade_accumulator_(0.0F) {
|
||||
// Inicializa variables
|
||||
state_ = SceneManager::options == SceneManager::Options::TITLE_WITH_LOADING_SCREEN ? State::SHOW_LOADING_SCREEN : State::SHOW_MENU;
|
||||
SceneManager::current = SceneManager::Scene::TITLE;
|
||||
@@ -72,10 +72,10 @@ void Title::initMarquee() {
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Title::checkEvents() {
|
||||
void Title::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
GlobalEvents::handle(event);
|
||||
|
||||
// Solo se comprueban estas teclas si no está activo el menu de logros
|
||||
if (event.type == SDL_EVENT_KEY_DOWN) {
|
||||
@@ -99,24 +99,26 @@ void Title::checkEvents() {
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Title::checkInput() {
|
||||
void Title::handleInput(float delta_time) {
|
||||
Input::get()->update();
|
||||
|
||||
if (show_cheevos_) {
|
||||
if (Input::get()->checkInput(InputAction::DOWN, INPUT_ALLOW_REPEAT)) {
|
||||
moveCheevosList(1, current_delta_);
|
||||
} else if (Input::get()->checkInput(InputAction::UP, INPUT_ALLOW_REPEAT)) {
|
||||
moveCheevosList(0, current_delta_);
|
||||
} else if (Input::get()->checkInput(InputAction::ACCEPT, INPUT_DO_NOT_ALLOW_REPEAT)) {
|
||||
if (Input::get()->checkAction(InputAction::RIGHT, Input::ALLOW_REPEAT)) {
|
||||
moveCheevosList(1, delta_time);
|
||||
} else if (Input::get()->checkAction(InputAction::LEFT, Input::ALLOW_REPEAT)) {
|
||||
moveCheevosList(0, delta_time);
|
||||
} else if (Input::get()->checkAction(InputAction::ACCEPT, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||
hideCheevosList();
|
||||
}
|
||||
}
|
||||
|
||||
if (Input::get()->checkInput(InputAction::ACCEPT, INPUT_DO_NOT_ALLOW_REPEAT)) {
|
||||
if (Input::get()->checkAction(InputAction::ACCEPT, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||
if (state_ == State::SHOW_LOADING_SCREEN) {
|
||||
transitionToState(State::FADE_LOADING_SCREEN);
|
||||
}
|
||||
}
|
||||
|
||||
GlobalInputs::check();
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Actualiza la marquesina
|
||||
@@ -169,16 +171,15 @@ void Title::renderMarquee() {
|
||||
// Actualiza las variables
|
||||
void Title::update() {
|
||||
// Obtener delta time
|
||||
current_delta_ = delta_timer_->tick();
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
|
||||
// Comprueba las entradas
|
||||
checkInput();
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(DELTA_TIME); // Comprueba las entradas
|
||||
|
||||
// Actualiza la pantalla
|
||||
Screen::get()->update(current_delta_);
|
||||
updateState(DELTA_TIME); // Actualiza el estado actual
|
||||
|
||||
// Actualiza el estado actual
|
||||
updateState(current_delta_);
|
||||
Audio::get()->update(); // Actualiza el objeto Audio
|
||||
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
|
||||
}
|
||||
|
||||
// Actualiza el estado actual
|
||||
@@ -263,7 +264,6 @@ void Title::render() {
|
||||
void Title::run() {
|
||||
while (SceneManager::current == SceneManager::Scene::TITLE) {
|
||||
update();
|
||||
checkEvents();
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,13 +69,12 @@ class Title {
|
||||
State state_; // Estado en el que se encuentra el bucle principal
|
||||
float state_time_; // Tiempo acumulado en el estado actual
|
||||
float fade_accumulator_; // Acumulador para controlar el fade por tiempo
|
||||
float current_delta_; // Delta time del frame actual
|
||||
|
||||
// --- Funciones ---
|
||||
void update(); // Actualiza las variables
|
||||
void render(); // Dibuja en pantalla
|
||||
void checkEvents(); // Comprueba el manejador de eventos
|
||||
void checkInput(); // Comprueba las entradas
|
||||
void handleEvents(); // Comprueba el manejador de eventos
|
||||
void handleInput(float delta_time); // Comprueba las entradas
|
||||
void updateState(float delta_time); // Actualiza el estado actual
|
||||
void transitionToState(State new_state); // Transiciona a un nuevo estado
|
||||
void initMarquee(); // Inicializa la marquesina
|
||||
|
||||
Reference in New Issue
Block a user