From 482dc3de54d876fa078c5b0a361975385140db56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Mon, 10 Mar 2025 23:24:00 +0100 Subject: [PATCH] Afegit global_events.cpp --- source/background.cpp | 10 -- source/background.h | 3 - source/balloon_manager.cpp | 9 -- source/balloon_manager.h | 3 - source/credits.cpp | 23 ++--- source/define_buttons.cpp | 27 +----- source/define_buttons.h | 2 +- source/game.cpp | 188 ++++++++++++++++--------------------- source/game.h | 7 +- source/game_logo.cpp | 9 -- source/game_logo.h | 3 - source/global_events.cpp | 32 +++++++ source/global_events.h | 9 ++ source/hiscore_table.cpp | 28 +----- source/hiscore_table.h | 3 - source/instructions.cpp | 62 ++++-------- source/instructions.h | 3 - source/intro.cpp | 29 +----- source/logo.cpp | 147 +---------------------------- source/logo.h | 8 -- source/text.cpp | 6 -- source/text.h | 3 - source/tiled_bg.cpp | 6 -- source/tiled_bg.h | 3 - source/title.cpp | 101 ++++++++------------ source/title.h | 3 - 26 files changed, 197 insertions(+), 530 deletions(-) diff --git a/source/background.cpp b/source/background.cpp index 719d652..f985435 100644 --- a/source/background.cpp +++ b/source/background.cpp @@ -226,16 +226,6 @@ void Background::render() SDL_RenderCopy(renderer_, color_texture_, &src_rect_, &dst_rect_); } -// Vuelve a cargar las texturas -void Background::reloadTextures() -{ - buildings_texture_->reLoad(); - top_clouds_texture_->reLoad(); - bottom_clouds_texture_->reLoad(); - grass_texture_->reLoad(); - gradients_texture_->reLoad(); -} - // Ajusta el valor de la variable void Background::setCloudsSpeed(float value) { diff --git a/source/background.h b/source/background.h index 960d2cc..0029ef4 100644 --- a/source/background.h +++ b/source/background.h @@ -131,9 +131,6 @@ public: // Establece la posición del objeto void setPos(SDL_Rect pos); - // Vuelve a cargar las texturas - void reloadTextures(); - // Ajusta el valor de la variable void setCloudsSpeed(float value); diff --git a/source/balloon_manager.cpp b/source/balloon_manager.cpp index 8399fd9..2ac957f 100644 --- a/source/balloon_manager.cpp +++ b/source/balloon_manager.cpp @@ -370,15 +370,6 @@ void BalloonManager::normalColorsToAllBalloons() } } -// Recarga las texturas -void BalloonManager::reLoad() -{ - for (auto &texture : balloon_textures_) - { - texture->reLoad(); - } -} - // Crea dos globos gordos void BalloonManager::createTwoBigBalloons() { diff --git a/source/balloon_manager.h b/source/balloon_manager.h index 7614364..18eb4f5 100644 --- a/source/balloon_manager.h +++ b/source/balloon_manager.h @@ -104,9 +104,6 @@ public: // Cambia el color de todos los globos void normalColorsToAllBalloons(); - // Recarga las texturas - void reLoad(); - // Crea dos globos gordos void createTwoBigBalloons(); diff --git a/source/credits.cpp b/source/credits.cpp index f1187d3..dd7c08d 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -15,7 +15,7 @@ #include "input.h" // Para Input #include "jail_audio.h" // Para JA_GetMusicState, JA_SetMusicVolume #include "lang.h" // Para getText -#include "mouse.h" // Para handleEvent +#include "global_events.h" // Para handleEvent #include "param.h" // Para Param, ParamGame, param #include "player.h" // Para Player, PlayerState #include "resource.h" // Para Resource @@ -128,22 +128,11 @@ void Credits::render() // Comprueba el manejador de eventos void Credits::checkEvents() { - SDL_Event event; - - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(&event)) - { - // Evento de salida de la aplicación - if (event.type == SDL_QUIT) - { - section::name = section::Name::QUIT; - section::options = section::Options::QUIT_FROM_EVENT; - break; - } - - // Comprueba el cursor - Mouse::handleEvent(event); - } + SDL_Event event; + while (SDL_PollEvent(&event)) + { + globalEvents::check(event); + } } // Comprueba las entradas diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index f6449d2..a794330 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -62,32 +62,11 @@ void DefineButtons::bindButtons() } // Comprueba los eventos -void DefineButtons::checkEvents() +void DefineButtons::checkEvents(const SDL_Event &event) { - if (enabled_) + if (enabled_ && event.type == SDL_CONTROLLERBUTTONDOWN) { - SDL_Event event; - - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_QUIT: - { - section::name = section::Name::QUIT; - section::options = section::Options::QUIT_WITH_KEYBOARD; - break; - } - case SDL_CONTROLLERBUTTONDOWN: - { - doControllerButtonDown(event.cbutton); - break; - } - default: - break; - } - } + doControllerButtonDown(event.cbutton); } } diff --git a/source/define_buttons.h b/source/define_buttons.h index 11b4a45..f8e2288 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -67,7 +67,7 @@ public: void render(); // Comprueba los eventos - void checkEvents(); + void checkEvents(const SDL_Event &event); // Habilita el objeto bool enable(int index); diff --git a/source/game.cpp b/source/game.cpp index c3880a6..a081df0 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -22,7 +22,7 @@ #include "jail_audio.h" // Para JA_PlaySound, JA_GetMusicState #include "lang.h" // Para getText #include "manage_hiscore_table.h" // Para ManageHiScoreTable, HiScoreEntry -#include "mouse.h" // Para handleEvent +#include "global_events.h" // Para handleEvent #include "notifier.h" // Para Notifier #include "param.h" // Para Param, param, ParamGame, ParamFade #include "path_sprite.h" // Para Path, PathSprite, createPath, Path... @@ -1218,15 +1218,7 @@ void Game::checkEvents() SDL_Event event; while (SDL_PollEvent(&event)) { - // Evento de salida de la aplicación - if (event.type == SDL_QUIT) - { - section::name = section::Name::QUIT; - section::options = section::Options::QUIT_FROM_EVENT; - break; - } - - else if (event.type == SDL_WINDOWEVENT) + if (event.type == SDL_WINDOWEVENT) { switch (event.window.event) { @@ -1240,111 +1232,19 @@ void Game::checkEvents() pause(false); break; } - case SDL_WINDOWEVENT_SIZE_CHANGED: - { - reloadTextures(); - break; - } + default: break; } } #ifdef DEBUG - else if (event.type == SDL_KEYDOWN && event.key.repeat == 0) - { - switch (event.key.keysym.sym) - { - case SDLK_1: // Crea una powerball - { - balloon_manager_->createPowerBall(); - break; - } - case SDLK_2: // Crea dos globos gordos - { - balloon_manager_->createTwoBigBalloons(); - } - break; - case SDLK_3: // Activa el modo para pasar el juego automaticamente - { - auto_pop_balloons_ = !auto_pop_balloons_; - Notifier::get()->show({"auto advance: " + boolToString(auto_pop_balloons_)}); - if (auto_pop_balloons_) - { - balloon_manager_->destroyAllBalloons(); - } - balloon_manager_->setDeployBalloons(!auto_pop_balloons_); - break; - } - case SDLK_4: // Suelta un item - { - createItem(ItemType::CLOCK, players_.at(0)->getPosX(), players_.at(0)->getPosY() - 40); - break; - } - case SDLK_5: // 5.000 - { - const int x = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2; - createItemText(x, game_text_textures_.at(2)); - break; - } - case SDLK_6: // Crea un mensaje - { - createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready")); - break; - } - case SDLK_7: // 100.000 - { - // screen_->flash(flash_color, 3); - // tabe_->setState(TabeState::HIT); - const int x = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2; - createItemText(x, game_text_textures_.at(6)); - break; - break; - } - case SDLK_8: - { - for (auto player : players_) - { - if (player->isPlaying()) - { - createItem(ItemType::COFFEE_MACHINE, player->getPosX(), param.game.game_area.rect.y - param.game.coffee_machine_h); - break; - } - } - break; - } - case SDLK_9: - { - tabe_->enable(); - break; - } - default: - break; - } - } + checkDebugEvents(event); #endif - // Comprueba el cursor - Mouse::handleEvent(event); + globalEvents::check(event); } } -// Recarga las texturas -void Game::reloadTextures() -{ - for (auto &texture : item_textures_) - texture->reLoad(); - - for (auto &textures : player_textures_) - for (auto &texture : textures) - texture->reLoad(); - - for (auto &texture : game_text_textures_) - texture->reLoad(); - - bullet_texture_->reLoad(); - background_->reloadTextures(); -} - // Actualiza el marcador void Game::updateScoreboard() { @@ -2071,4 +1971,80 @@ void Game::setState(GameState state) { state_ = state; counter_ = 0; -} \ No newline at end of file +} + +#ifdef DEBUG +// Comprueba los eventos en el modo DEBUG +void Game::checkDebugEvents(const SDL_Event &event) +{ + if (event.type == SDL_KEYDOWN && event.key.repeat == 0) + { + switch (event.key.keysym.sym) + { + case SDLK_1: // Crea una powerball + { + balloon_manager_->createPowerBall(); + break; + } + case SDLK_2: // Crea dos globos gordos + { + balloon_manager_->createTwoBigBalloons(); + break; + } + case SDLK_3: // Activa el modo para pasar el juego automaticamente + { + auto_pop_balloons_ = !auto_pop_balloons_; + Notifier::get()->show({"auto advance: " + boolToString(auto_pop_balloons_)}); + if (auto_pop_balloons_) + { + balloon_manager_->destroyAllBalloons(); + } + balloon_manager_->setDeployBalloons(!auto_pop_balloons_); + break; + } + case SDLK_4: // Suelta un item + { + createItem(ItemType::CLOCK, players_.at(0)->getPosX(), players_.at(0)->getPosY() - 40); + break; + } + case SDLK_5: // 5.000 + { + const int X = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2; + createItemText(X, game_text_textures_.at(2)); + break; + } + case SDLK_6: // Crea un mensaje + { + createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready")); + break; + } + case SDLK_7: // 100.000 + { + const int X = players_.at(0)->getPosX() + (players_.at(0)->getWidth() - game_text_textures_[3]->getWidth()) / 2; + createItemText(X, game_text_textures_.at(6)); + break; + break; + } + case SDLK_8: + { + for (auto player : players_) + { + if (player->isPlaying()) + { + createItem(ItemType::COFFEE_MACHINE, player->getPosX(), param.game.game_area.rect.y - param.game.coffee_machine_h); + break; + } + } + break; + } + case SDLK_9: + { + tabe_->enable(); + break; + } + default: + break; + } + } +} +#endif \ No newline at end of file diff --git a/source/game.h b/source/game.h index 5e688d1..de1358b 100644 --- a/source/game.h +++ b/source/game.h @@ -2,6 +2,7 @@ #include // Para SDL_Renderer, SDL_Texture #include // Para Uint32, Uint8 +#include // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN #include // Para shared_ptr, unique_ptr #include // Para string #include // Para vector @@ -173,6 +174,9 @@ private: GameState state_ = GameState::FADE_IN; // Estado #ifdef DEBUG bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados + + // Comprueba los eventos en el modo DEBUG + void checkDebugEvents(const SDL_Event &event); #endif // Actualiza el juego @@ -298,9 +302,6 @@ private: // Comprueba si todos los jugadores han terminado de jugar bool allPlayersAreNotPlaying(); - // Recarga las texturas - void reloadTextures(); - // Actualiza el marcador void updateScoreboard(); diff --git a/source/game_logo.cpp b/source/game_logo.cpp index c2848f5..1f986a4 100644 --- a/source/game_logo.cpp +++ b/source/game_logo.cpp @@ -244,15 +244,6 @@ bool GameLogo::hasFinished() const return post_finished_counter_ == 0; } -// Recarga las texturas -void GameLogo::reLoad() -{ - dust_texture_->reLoad(); - coffee_texture_->reLoad(); - crisis_texture_->reLoad(); - arcade_edition_texture_->reLoad(); -} - // Calcula el desplazamiento vertical inicial int GameLogo::getInitialVerticalDesp() { diff --git a/source/game_logo.h b/source/game_logo.h index c9a3c11..daaec08 100644 --- a/source/game_logo.h +++ b/source/game_logo.h @@ -94,7 +94,4 @@ public: // Indica si ha terminado la animación bool hasFinished() const; - - // Recarga las texturas - void reLoad(); }; \ No newline at end of file diff --git a/source/global_events.cpp b/source/global_events.cpp index e69de29..fa036d0 100644 --- a/source/global_events.cpp +++ b/source/global_events.cpp @@ -0,0 +1,32 @@ +#include "global_events.h" +#include "section.h" +#include "mouse.h" +#include "resource.h" + +namespace globalEvents +{ + // Comprueba los eventos que se pueden producir en cualquier sección del juego + void check(const SDL_Event &event) + { + switch (event.type) + { + case SDL_QUIT: // Evento de salida de la aplicación + section::name = section::Name::QUIT; + section::options = section::Options::QUIT_FROM_EVENT; + return; + case SDL_RENDER_DEVICE_RESET: + case SDL_RENDER_TARGETS_RESET: + Resource::get()->reloadTextures(); + break; + case SDL_WINDOWEVENT: + if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) + { + Resource::get()->reloadTextures(); + } + break; + default: + break; + } + Mouse::handleEvent(event); + } +} \ No newline at end of file diff --git a/source/global_events.h b/source/global_events.h index e69de29..8e0751f 100644 --- a/source/global_events.h +++ b/source/global_events.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace globalEvents +{ + // Comprueba los eventos que se pueden producir en cualquier sección del juego + void check(const SDL_Event &event); +} \ No newline at end of file diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 6b997ae..5c7aba4 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -15,7 +15,7 @@ #include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state #include "lang.h" // Para getText #include "manage_hiscore_table.h" // Para HiScoreEntry -#include "mouse.h" // Para handleEvent +#include "global_events.h" // Para handleEvent #include "options.h" // Para Options, OptionsGame, options #include "param.h" // Para Param, param, ParamGame, ParamFade #include "path_sprite.h" // Para PathSprite, Path, PathType @@ -152,37 +152,13 @@ void HiScoreTable::render() Screen::get()->render(); } -// Recarga todas las texturas -void HiScoreTable::reloadTextures() -{ -} - // Comprueba los eventos void HiScoreTable::checkEvents() { - // Comprueba los eventos que hay en la cola SDL_Event event; while (SDL_PollEvent(&event)) { - // Evento de salida de la aplicación - if (event.type == SDL_QUIT) - { - section::name = section::Name::QUIT; - section::options = section::Options::QUIT_FROM_EVENT; - break; - } - - // Comprueba si se ha cambiado el tamaño de la ventana - else if (event.type == SDL_WINDOWEVENT) - { - if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) - { - reloadTextures(); - } - } - - // Comprueba el cursor - Mouse::handleEvent(event); + globalEvents::check(event); } } diff --git a/source/hiscore_table.h b/source/hiscore_table.h index 545bc5c..1b4661b 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -67,9 +67,6 @@ private: // Dibuja los sprites en la textura void fillTexture(); - // Recarga todas las texturas - void reloadTextures(); - // Gestiona el fade void updateFade(); diff --git a/source/instructions.cpp b/source/instructions.cpp index 4b8a3e6..4e712de 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -20,7 +20,7 @@ #include "texture.h" // Para Texture #include "tiled_bg.h" // Para TiledBG, TiledBGMode #include "utils.h" // Para Color, shdw_txt_color, Zone, no_color -#include "mouse.h" +#include "global_events.h" #include #include @@ -236,20 +236,20 @@ void Instructions::update() view_.y = std::max(0, param.game.height - counter_ + 100); // Verifica si view_.y == 0 y gestiona el temporizador - if (view_.y == 0) - { - if (!start_delay_triggered_) - { - // Activa el temporizador si no ha sido activado - start_delay_triggered_ = true; - start_delay_time_ = SDL_GetTicks(); - } - else if (SDL_GetTicks() - start_delay_time_ >= 4000) - { - // Han pasado tres segundos, mover líneas - all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5); - } - } + if (view_.y == 0) + { + if (!start_delay_triggered_) + { + // Activa el temporizador si no ha sido activado + start_delay_triggered_ = true; + start_delay_time_ = SDL_GetTicks(); + } + else if (SDL_GetTicks() - start_delay_time_ >= 4000) + { + // Han pasado tres segundos, mover líneas + all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5); + } + } // Actualiza el mosaico de fondo tiled_bg_->update(); @@ -293,43 +293,13 @@ void Instructions::render() Screen::get()->render(); } -// Recarga todas las texturas -void Instructions::reloadTextures() -{ - for (auto &texture : item_textures_) - { - texture->reLoad(); - } - text_->reLoadTexture(); - fillTexture(); -} - // Comprueba los eventos void Instructions::checkEvents() { - // Comprueba los eventos que hay en la cola SDL_Event event; while (SDL_PollEvent(&event)) { - // Evento de salida de la aplicación - if (event.type == SDL_QUIT) - { - section::name = section::Name::QUIT; - section::options = section::Options::QUIT_FROM_EVENT; - break; - } - - // Comprueba si se ha cambiado el tamaño de la ventana - else if (event.type == SDL_WINDOWEVENT) - { - if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) - { - reloadTextures(); - } - } - - // Comprueba el cursor - Mouse::handleEvent(event); + globalEvents::check(event); } } diff --git a/source/instructions.h b/source/instructions.h index f82c116..452702a 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -87,9 +87,6 @@ private: // Actualiza los sprites void updateSprites(); - // Recarga todas las texturas - void reloadTextures(); - // Método para inicializar las líneas std::vector initializeLines(int height); diff --git a/source/intro.cpp b/source/intro.cpp index 558f580..43269f5 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -16,7 +16,7 @@ #include "texture.h" // Para Texture #include "utils.h" // Para Zone, BLOCK, Color, bg_color #include "writer.h" // Para Writer -#include "mouse.h" +#include "global_events.h" #include // Constructor @@ -154,34 +154,9 @@ Intro::Intro() void Intro::checkEvents() { SDL_Event event; - - // Comprueba los eventos que hay en la cola while (SDL_PollEvent(&event)) { - switch (event.type) - { - case SDL_QUIT: - { - section::name = section::Name::QUIT; - section::options = section::Options::QUIT_FROM_EVENT; - break; - } - - case SDL_WINDOWEVENT: - { - if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) - { - // reloadTextures(); - } - break; - } - - default: - break; - } - - // Comprueba el cursor - Mouse::handleEvent(event); + globalEvents::check(event); } } diff --git a/source/logo.cpp b/source/logo.cpp index 366d7c6..7b90b95 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -14,7 +14,7 @@ #include "sprite.h" // Para Sprite #include "texture.h" // Para Texture #include "utils.h" // Para Color, Zone -#include "mouse.h" +#include "global_events.h" // Constructor Logo::Logo() @@ -63,39 +63,13 @@ Logo::~Logo() JA_StopChannel(-1); } -// Recarga todas las texturas -void Logo::reloadTextures() -{ - jail_texture_->reLoad(); - since_texture_->reLoad(); -} - // Comprueba el manejador de eventos void Logo::checkEvents() { SDL_Event event; - // Comprueba los eventos que hay en la cola while (SDL_PollEvent(&event)) { - // Evento de salida de la aplicación - if (event.type == SDL_QUIT) - { - section::name = section::Name::QUIT; - section::options = section::Options::QUIT_FROM_EVENT; - break; - } - - // Comprueba si se ha cambiado el tamaño de la ventana - else if (event.type == SDL_WINDOWEVENT) - { - if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) - { - reloadTextures(); - } - } - - // Comprueba el cursor - Mouse::handleEvent(event); + globalEvents::check(event); } } @@ -239,7 +213,6 @@ void Logo::render() break; case LogoState::RETROWEEKEND: - renderRETROWEEKEND(); break; default: @@ -277,118 +250,4 @@ void Logo::renderJAILGAMES() { since_sprite_->render(); } -} - -// Renderiza el logo de RETROWEEKEND -void Logo::renderRETROWEEKEND() -{ - // SDL_RenderCopy(Screen::get()->getRenderer(), mi_textura, nullptr, nullptr); - - // SDL_RenderCopy(Screen::get()->getRenderer(), Resource::get()->getTexture("logo_retroweekend.png")->getSDLTexture(), nullptr, nullptr); - // Dibujar y evaporar los píxeles - renderAndEvaporate(Screen::get()->getRenderer(), pixels_); -} - -std::vector Logo::extractPixels(SDL_Texture *texture) -{ - std::vector pixels; - - // Obtener el formato y tamaño de la textura - Uint32 format; - int access, width, height; - SDL_QueryTexture(texture, &format, &access, &width, &height); - - // Imprimir el nombre del formato de la textura - std::cout << "Texture format: " << SDL_GetPixelFormatName(format) << std::endl; - - // Crear una superficie temporal para leer los píxeles - SDL_Surface *temp_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, format); - if (!temp_surface) - { - std::cout << "Error: SDL_CreateRGBSurfaceWithFormat failed - " << SDL_GetError() << std::endl; - return pixels; - } - - SDL_Renderer *renderer = Screen::get()->getRenderer(); - SDL_SetRenderTarget(renderer, nullptr); // Dibujar en pantalla principal - SDL_RenderClear(renderer); // Limpiar pantalla - SDL_RenderCopy(renderer, texture, nullptr, nullptr); - SDL_RenderPresent(renderer); // Mostrar en pantalla - - std::cout << "Se ha dibujado la textura en pantalla." << std::endl; - - if (SDL_RenderReadPixels(Screen::get()->getRenderer(), nullptr, format, temp_surface->pixels, temp_surface->pitch) != 0) - { - std::cout << "Error: SDL_RenderReadPixels failed - " << SDL_GetError() << std::endl; - SDL_FreeSurface(temp_surface); - return pixels; - } - else - { - std::cout << "SDL_RenderReadPixels se ejecutó correctamente." << std::endl; - } - - // Leer los píxeles de la textura - if (SDL_RenderReadPixels(Screen::get()->getRenderer(), nullptr, format, temp_surface->pixels, temp_surface->pitch) != 0) - { - std::cout << "Error: SDL_RenderReadPixels failed - " << SDL_GetError() << std::endl; - SDL_FreeSurface(temp_surface); - return pixels; - } - - // Extraer los píxeles y almacenarlos en el vector - SDL_PixelFormat *pixel_format = SDL_AllocFormat(format); - Uint8 r, g, b, a; - /*for (int y = 0; y < height; ++y) - { - for (int x = 0; x < width; ++x) - { - Uint32 pixel_value = ((Uint32 *)temp_surface->pixels)[y * (temp_surface->pitch / 4) + x]; - SDL_GetRGBA(pixel_value, pixel_format, &r, &g, &b, &a); - if (a > 0) - { - pixels.push_back({x, y, r, g, b, a}); - } - } - }*/ - - for (int y = 0; y < height; ++y) - { - for (int x = 0; x < width; ++x) - { - Uint32 pixel_value = ((Uint32 *)temp_surface->pixels)[y * (temp_surface->pitch / 4) + x]; - SDL_GetRGBA(pixel_value, pixel_format, &r, &g, &b, &a); - - // Imprimir algunos píxeles para depuración - if (x < 5 && y < 5) - { - std::cout << "Pixel (" << x << "," << y << ") - RGBA(" - << (int)r << "," << (int)g << "," << (int)b << "," << (int)a << ")" << std::endl; - } - - // No filtrar por alfa por ahora - pixels.push_back({x, y, r, g, b, a}); - } - } - - std::cout << "Cantidad de píxeles a renderizar: " << pixels.size() << std::endl; - - // Liberar recursos - SDL_FreeFormat(pixel_format); - SDL_FreeSurface(temp_surface); - - return pixels; -} - -void Logo::renderAndEvaporate(SDL_Renderer *renderer, std::vector &pixels) -{ - for (auto &pixel : pixels) - { - // Establecer el color para el píxel actual - SDL_SetRenderDrawColor(renderer, pixel.r, pixel.g, pixel.b, pixel.a); - // Dibujar el píxel - SDL_RenderDrawPoint(renderer, pixel.x, pixel.y); - // Evaporar el píxel - // pixel.evaporate(); - } -} +} \ No newline at end of file diff --git a/source/logo.h b/source/logo.h index 196ef18..fa3165c 100644 --- a/source/logo.h +++ b/source/logo.h @@ -62,7 +62,6 @@ private: SDL_Point dest_; // Posición X donde dibujar el logo LogoState state_ = LogoState::JAILGAMES; // El estado indica qué logo se está procesando Uint32 ticks_start_ = 0; // Almacena el valor actual de los ticks de SDL - std::vector pixels_; // Vector con los pixels que forman el logo de "RETROWEEKEND" // Actualiza las variables void update(); @@ -91,13 +90,6 @@ private: // Gestiona el color de las texturas void updateTextureColors(); - // Recarga todas las texturas - void reloadTextures(); - - std::vector extractPixels(SDL_Texture *texture); - - void renderAndEvaporate(SDL_Renderer *renderer, std::vector &pixels); - public: // Constructor Logo(); diff --git a/source/text.cpp b/source/text.cpp index 1a7888a..d51e621 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -275,12 +275,6 @@ int Text::getCharacterSize() const return box_width_; } -// Recarga la textura -void Text::reLoadTexture() -{ - sprite_->getTexture()->reLoad(); -} - // Establece si se usa un tamaño fijo de letra void Text::setFixedWidth(bool value) { diff --git a/source/text.h b/source/text.h index 3ec7b97..d66af00 100644 --- a/source/text.h +++ b/source/text.h @@ -76,9 +76,6 @@ public: // Devuelve el valor de la variable int getCharacterSize() const; - // Recarga la textura - void reLoadTexture(); - // Establece si se usa un tamaño fijo de letra void setFixedWidth(bool value); diff --git a/source/tiled_bg.cpp b/source/tiled_bg.cpp index 6ce8970..ab5ed8a 100644 --- a/source/tiled_bg.cpp +++ b/source/tiled_bg.cpp @@ -90,10 +90,4 @@ void TiledBG::update() default: break; } -} - -// Recarga las texturas -void TiledBG::reLoad() -{ - fillTexture(); } \ No newline at end of file diff --git a/source/tiled_bg.h b/source/tiled_bg.h index 6536093..b0cde03 100644 --- a/source/tiled_bg.h +++ b/source/tiled_bg.h @@ -52,7 +52,4 @@ public: // Actualiza la lógica de la clase void update(); - - // Recarga las texturas - void reLoad(); }; \ No newline at end of file diff --git a/source/title.cpp b/source/title.cpp index a9e1027..f77be07 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -12,7 +12,7 @@ #include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_R... #include "jail_audio.h" // Para JA_GetMusicState, JA_FadeOutMusic, JA_... #include "lang.h" // Para getText -#include "mouse.h" // Para handleEvent +#include "global_events.h" // Para handleEvent #include "notifier.h" // Para Notifier #include "options.h" // Para OptionsController, Options, options #include "param.h" // Para Param, param, ParamGame, ParamTitle @@ -213,71 +213,51 @@ void Title::render() // Comprueba los eventos void Title::checkEvents() { - // Comprueba el input para el resto de objetos - define_buttons_->checkEvents(); - - // Si define_buttons_ está habilitado, es él quien gestiona los eventos - if (!define_buttons_->isEnabled()) + SDL_Event event; + while (SDL_PollEvent(&event)) { - SDL_Event event; - while (SDL_PollEvent(&event)) + if (event.type == SDL_KEYDOWN && event.key.repeat == 0) { - // Evento de salida de la aplicación - if (event.type == SDL_QUIT) + bool should_reset = false; + + switch (event.key.keysym.sym) { - section::name = section::Name::QUIT; - section::options = section::Options::QUIT_FROM_EVENT; + case SDLK_1: // Redefine los botones del mando #0 + should_reset = define_buttons_->enable(0); + break; + + case SDLK_2: // Redefine los botones del mando #1 + should_reset = define_buttons_->enable(1); + break; + + case SDLK_3: // Intercambia los mandos entre los dos jugadores + swapControllers(); + should_reset = true; + break; + + case SDLK_4: // Intercambia la asignación del teclado + swapKeyboard(); + should_reset = true; + break; + + case SDLK_5: // Muestra la asignación de mandos y teclado + showControllers(); + should_reset = true; + break; + + default: break; } - // Recarga las texturas - else if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET) + // Resetear el contador si es necesario + if (should_reset) { - reLoadTextures(); + resetCounter(); } - - else if (event.type == SDL_KEYDOWN && event.key.repeat == 0) - { - switch (event.key.keysym.sym) - { - case SDLK_1: // Redefine los botones del mando #0 - { - if (define_buttons_->enable(0)) - resetCounter(); - break; - } - case SDLK_2: // Redefine los botones del mando #1 - { - if (define_buttons_->enable(1)) - resetCounter(); - break; - } - case SDLK_3: // Intercambia los mandos entre los dos jugadores - { - swapControllers(); - resetCounter(); - break; - } - case SDLK_4: // Intercambia la asignación del teclado - { - swapKeyboard(); - resetCounter(); - break; - } - case SDLK_5: // Muestra la asignacion de mandos y teclado - { - showControllers(); - resetCounter(); - break; - } - default: - break; - } - } - - // Comprueba el cursor - Mouse::handleEvent(event); } + + globalEvents::check(event); + define_buttons_->checkEvents(event); } } @@ -350,13 +330,6 @@ void Title::run() } } -// Recarga las texturas -void Title::reLoadTextures() -{ - game_logo_->reLoad(); - tiled_bg_->reLoad(); -} - // Reinicia el contador interno void Title::resetCounter() { counter_ = 0; } diff --git a/source/title.h b/source/title.h index 2bd89f1..f0cf3a5 100644 --- a/source/title.h +++ b/source/title.h @@ -72,9 +72,6 @@ private: // Comprueba las entradas void checkInput(); - // Recarga las texturas - void reLoadTextures(); - // Reinicia el contador interno void resetCounter();