migrat Input a la ultima versió
cohesionats tots els metodes update de les escenes
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user