Afegit global_events.cpp

This commit is contained in:
2025-03-10 23:24:00 +01:00
parent 9d98d3ea6a
commit 482dc3de54
26 changed files with 197 additions and 530 deletions

View File

@@ -226,16 +226,6 @@ void Background::render()
SDL_RenderCopy(renderer_, color_texture_, &src_rect_, &dst_rect_); 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 // Ajusta el valor de la variable
void Background::setCloudsSpeed(float value) void Background::setCloudsSpeed(float value)
{ {

View File

@@ -131,9 +131,6 @@ public:
// Establece la posición del objeto // Establece la posición del objeto
void setPos(SDL_Rect pos); void setPos(SDL_Rect pos);
// Vuelve a cargar las texturas
void reloadTextures();
// Ajusta el valor de la variable // Ajusta el valor de la variable
void setCloudsSpeed(float value); void setCloudsSpeed(float value);

View File

@@ -370,15 +370,6 @@ void BalloonManager::normalColorsToAllBalloons()
} }
} }
// Recarga las texturas
void BalloonManager::reLoad()
{
for (auto &texture : balloon_textures_)
{
texture->reLoad();
}
}
// Crea dos globos gordos // Crea dos globos gordos
void BalloonManager::createTwoBigBalloons() void BalloonManager::createTwoBigBalloons()
{ {

View File

@@ -104,9 +104,6 @@ public:
// Cambia el color de todos los globos // Cambia el color de todos los globos
void normalColorsToAllBalloons(); void normalColorsToAllBalloons();
// Recarga las texturas
void reLoad();
// Crea dos globos gordos // Crea dos globos gordos
void createTwoBigBalloons(); void createTwoBigBalloons();

View File

@@ -15,7 +15,7 @@
#include "input.h" // Para Input #include "input.h" // Para Input
#include "jail_audio.h" // Para JA_GetMusicState, JA_SetMusicVolume #include "jail_audio.h" // Para JA_GetMusicState, JA_SetMusicVolume
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "mouse.h" // Para handleEvent #include "global_events.h" // Para handleEvent
#include "param.h" // Para Param, ParamGame, param #include "param.h" // Para Param, ParamGame, param
#include "player.h" // Para Player, PlayerState #include "player.h" // Para Player, PlayerState
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
@@ -129,20 +129,9 @@ void Credits::render()
void Credits::checkEvents() void Credits::checkEvents()
{ {
SDL_Event event; SDL_Event event;
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
// Evento de salida de la aplicación globalEvents::check(event);
if (event.type == SDL_QUIT)
{
section::name = section::Name::QUIT;
section::options = section::Options::QUIT_FROM_EVENT;
break;
}
// Comprueba el cursor
Mouse::handleEvent(event);
} }
} }

View File

@@ -62,32 +62,11 @@ void DefineButtons::bindButtons()
} }
// Comprueba los eventos // 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); doControllerButtonDown(event.cbutton);
break;
}
default:
break;
}
}
} }
} }

View File

@@ -67,7 +67,7 @@ public:
void render(); void render();
// Comprueba los eventos // Comprueba los eventos
void checkEvents(); void checkEvents(const SDL_Event &event);
// Habilita el objeto // Habilita el objeto
bool enable(int index); bool enable(int index);

View File

@@ -22,7 +22,7 @@
#include "jail_audio.h" // Para JA_PlaySound, JA_GetMusicState #include "jail_audio.h" // Para JA_PlaySound, JA_GetMusicState
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "manage_hiscore_table.h" // Para ManageHiScoreTable, HiScoreEntry #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 "notifier.h" // Para Notifier
#include "param.h" // Para Param, param, ParamGame, ParamFade #include "param.h" // Para Param, param, ParamGame, ParamFade
#include "path_sprite.h" // Para Path, PathSprite, createPath, Path... #include "path_sprite.h" // Para Path, PathSprite, createPath, Path...
@@ -1218,15 +1218,7 @@ void Game::checkEvents()
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
// Evento de salida de la aplicación if (event.type == SDL_WINDOWEVENT)
if (event.type == SDL_QUIT)
{
section::name = section::Name::QUIT;
section::options = section::Options::QUIT_FROM_EVENT;
break;
}
else if (event.type == SDL_WINDOWEVENT)
{ {
switch (event.window.event) switch (event.window.event)
{ {
@@ -1240,111 +1232,19 @@ void Game::checkEvents()
pause(false); pause(false);
break; break;
} }
case SDL_WINDOWEVENT_SIZE_CHANGED:
{
reloadTextures();
break;
}
default: default:
break; break;
} }
} }
#ifdef DEBUG #ifdef DEBUG
else if (event.type == SDL_KEYDOWN && event.key.repeat == 0) checkDebugEvents(event);
{
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;
}
}
#endif #endif
// Comprueba el cursor globalEvents::check(event);
Mouse::handleEvent(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 // Actualiza el marcador
void Game::updateScoreboard() void Game::updateScoreboard()
{ {
@@ -2072,3 +1972,79 @@ void Game::setState(GameState state)
state_ = state; state_ = state;
counter_ = 0; counter_ = 0;
} }
#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

View File

@@ -2,6 +2,7 @@
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture #include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8 #include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
#include <memory> // Para shared_ptr, unique_ptr #include <memory> // Para shared_ptr, unique_ptr
#include <string> // Para string #include <string> // Para string
#include <vector> // Para vector #include <vector> // Para vector
@@ -173,6 +174,9 @@ private:
GameState state_ = GameState::FADE_IN; // Estado GameState state_ = GameState::FADE_IN; // Estado
#ifdef DEBUG #ifdef DEBUG
bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados 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 #endif
// Actualiza el juego // Actualiza el juego
@@ -298,9 +302,6 @@ private:
// Comprueba si todos los jugadores han terminado de jugar // Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreNotPlaying(); bool allPlayersAreNotPlaying();
// Recarga las texturas
void reloadTextures();
// Actualiza el marcador // Actualiza el marcador
void updateScoreboard(); void updateScoreboard();

View File

@@ -244,15 +244,6 @@ bool GameLogo::hasFinished() const
return post_finished_counter_ == 0; 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 // Calcula el desplazamiento vertical inicial
int GameLogo::getInitialVerticalDesp() int GameLogo::getInitialVerticalDesp()
{ {

View File

@@ -94,7 +94,4 @@ public:
// Indica si ha terminado la animación // Indica si ha terminado la animación
bool hasFinished() const; bool hasFinished() const;
// Recarga las texturas
void reLoad();
}; };

View File

@@ -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);
}
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include <SDL2/SDL_events.h>
namespace globalEvents
{
// Comprueba los eventos que se pueden producir en cualquier sección del juego
void check(const SDL_Event &event);
}

View File

@@ -15,7 +15,7 @@
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state #include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "manage_hiscore_table.h" // Para HiScoreEntry #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 "options.h" // Para Options, OptionsGame, options
#include "param.h" // Para Param, param, ParamGame, ParamFade #include "param.h" // Para Param, param, ParamGame, ParamFade
#include "path_sprite.h" // Para PathSprite, Path, PathType #include "path_sprite.h" // Para PathSprite, Path, PathType
@@ -152,37 +152,13 @@ void HiScoreTable::render()
Screen::get()->render(); Screen::get()->render();
} }
// Recarga todas las texturas
void HiScoreTable::reloadTextures()
{
}
// Comprueba los eventos // Comprueba los eventos
void HiScoreTable::checkEvents() void HiScoreTable::checkEvents()
{ {
// Comprueba los eventos que hay en la cola
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
// Evento de salida de la aplicación globalEvents::check(event);
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);
} }
} }

View File

@@ -67,9 +67,6 @@ private:
// Dibuja los sprites en la textura // Dibuja los sprites en la textura
void fillTexture(); void fillTexture();
// Recarga todas las texturas
void reloadTextures();
// Gestiona el fade // Gestiona el fade
void updateFade(); void updateFade();

View File

@@ -20,7 +20,7 @@
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "tiled_bg.h" // Para TiledBG, TiledBGMode #include "tiled_bg.h" // Para TiledBG, TiledBGMode
#include "utils.h" // Para Color, shdw_txt_color, Zone, no_color #include "utils.h" // Para Color, shdw_txt_color, Zone, no_color
#include "mouse.h" #include "global_events.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <vector> #include <vector>
@@ -293,43 +293,13 @@ void Instructions::render()
Screen::get()->render(); Screen::get()->render();
} }
// Recarga todas las texturas
void Instructions::reloadTextures()
{
for (auto &texture : item_textures_)
{
texture->reLoad();
}
text_->reLoadTexture();
fillTexture();
}
// Comprueba los eventos // Comprueba los eventos
void Instructions::checkEvents() void Instructions::checkEvents()
{ {
// Comprueba los eventos que hay en la cola
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
// Evento de salida de la aplicación globalEvents::check(event);
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);
} }
} }

View File

@@ -87,9 +87,6 @@ private:
// Actualiza los sprites // Actualiza los sprites
void updateSprites(); void updateSprites();
// Recarga todas las texturas
void reloadTextures();
// Método para inicializar las líneas // Método para inicializar las líneas
std::vector<Line> initializeLines(int height); std::vector<Line> initializeLines(int height);

View File

@@ -16,7 +16,7 @@
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "utils.h" // Para Zone, BLOCK, Color, bg_color #include "utils.h" // Para Zone, BLOCK, Color, bg_color
#include "writer.h" // Para Writer #include "writer.h" // Para Writer
#include "mouse.h" #include "global_events.h"
#include <array> #include <array>
// Constructor // Constructor
@@ -154,34 +154,9 @@ Intro::Intro()
void Intro::checkEvents() void Intro::checkEvents()
{ {
SDL_Event event; SDL_Event event;
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
switch (event.type) globalEvents::check(event);
{
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);
} }
} }

View File

@@ -14,7 +14,7 @@
#include "sprite.h" // Para Sprite #include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "utils.h" // Para Color, Zone #include "utils.h" // Para Color, Zone
#include "mouse.h" #include "global_events.h"
// Constructor // Constructor
Logo::Logo() Logo::Logo()
@@ -63,39 +63,13 @@ Logo::~Logo()
JA_StopChannel(-1); JA_StopChannel(-1);
} }
// Recarga todas las texturas
void Logo::reloadTextures()
{
jail_texture_->reLoad();
since_texture_->reLoad();
}
// Comprueba el manejador de eventos // Comprueba el manejador de eventos
void Logo::checkEvents() void Logo::checkEvents()
{ {
SDL_Event event; SDL_Event event;
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
// Evento de salida de la aplicación globalEvents::check(event);
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);
} }
} }
@@ -239,7 +213,6 @@ void Logo::render()
break; break;
case LogoState::RETROWEEKEND: case LogoState::RETROWEEKEND:
renderRETROWEEKEND();
break; break;
default: default:
@@ -278,117 +251,3 @@ void Logo::renderJAILGAMES()
since_sprite_->render(); 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<Pixel> Logo::extractPixels(SDL_Texture *texture)
{
std::vector<Pixel> 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<Pixel> &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();
}
}

View File

@@ -62,7 +62,6 @@ private:
SDL_Point dest_; // Posición X donde dibujar el logo SDL_Point dest_; // Posición X donde dibujar el logo
LogoState state_ = LogoState::JAILGAMES; // El estado indica qué logo se está procesando 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 Uint32 ticks_start_ = 0; // Almacena el valor actual de los ticks de SDL
std::vector<Pixel> pixels_; // Vector con los pixels que forman el logo de "RETROWEEKEND"
// Actualiza las variables // Actualiza las variables
void update(); void update();
@@ -91,13 +90,6 @@ private:
// Gestiona el color de las texturas // Gestiona el color de las texturas
void updateTextureColors(); void updateTextureColors();
// Recarga todas las texturas
void reloadTextures();
std::vector<Pixel> extractPixels(SDL_Texture *texture);
void renderAndEvaporate(SDL_Renderer *renderer, std::vector<Pixel> &pixels);
public: public:
// Constructor // Constructor
Logo(); Logo();

View File

@@ -275,12 +275,6 @@ int Text::getCharacterSize() const
return box_width_; return box_width_;
} }
// Recarga la textura
void Text::reLoadTexture()
{
sprite_->getTexture()->reLoad();
}
// Establece si se usa un tamaño fijo de letra // Establece si se usa un tamaño fijo de letra
void Text::setFixedWidth(bool value) void Text::setFixedWidth(bool value)
{ {

View File

@@ -76,9 +76,6 @@ public:
// Devuelve el valor de la variable // Devuelve el valor de la variable
int getCharacterSize() const; int getCharacterSize() const;
// Recarga la textura
void reLoadTexture();
// Establece si se usa un tamaño fijo de letra // Establece si se usa un tamaño fijo de letra
void setFixedWidth(bool value); void setFixedWidth(bool value);

View File

@@ -91,9 +91,3 @@ void TiledBG::update()
break; break;
} }
} }
// Recarga las texturas
void TiledBG::reLoad()
{
fillTexture();
}

View File

@@ -52,7 +52,4 @@ public:
// Actualiza la lógica de la clase // Actualiza la lógica de la clase
void update(); void update();
// Recarga las texturas
void reLoad();
}; };

View File

@@ -12,7 +12,7 @@
#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_R... #include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_R...
#include "jail_audio.h" // Para JA_GetMusicState, JA_FadeOutMusic, JA_... #include "jail_audio.h" // Para JA_GetMusicState, JA_FadeOutMusic, JA_...
#include "lang.h" // Para getText #include "lang.h" // Para getText
#include "mouse.h" // Para handleEvent #include "global_events.h" // Para handleEvent
#include "notifier.h" // Para Notifier #include "notifier.h" // Para Notifier
#include "options.h" // Para OptionsController, Options, options #include "options.h" // Para OptionsController, Options, options
#include "param.h" // Para Param, param, ParamGame, ParamTitle #include "param.h" // Para Param, param, ParamGame, ParamTitle
@@ -213,71 +213,51 @@ void Title::render()
// Comprueba los eventos // Comprueba los eventos
void Title::checkEvents() 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; SDL_Event event;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
// Evento de salida de la aplicación if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
if (event.type == SDL_QUIT)
{ {
section::name = section::Name::QUIT; bool should_reset = false;
section::options = section::Options::QUIT_FROM_EVENT;
break;
}
// Recarga las texturas
else if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET)
{
reLoadTextures();
}
else if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
{
switch (event.key.keysym.sym) switch (event.key.keysym.sym)
{ {
case SDLK_1: // Redefine los botones del mando #0 case SDLK_1: // Redefine los botones del mando #0
{ should_reset = define_buttons_->enable(0);
if (define_buttons_->enable(0))
resetCounter();
break; break;
}
case SDLK_2: // Redefine los botones del mando #1 case SDLK_2: // Redefine los botones del mando #1
{ should_reset = define_buttons_->enable(1);
if (define_buttons_->enable(1))
resetCounter();
break; break;
}
case SDLK_3: // Intercambia los mandos entre los dos jugadores case SDLK_3: // Intercambia los mandos entre los dos jugadores
{
swapControllers(); swapControllers();
resetCounter(); should_reset = true;
break; break;
}
case SDLK_4: // Intercambia la asignación del teclado case SDLK_4: // Intercambia la asignación del teclado
{
swapKeyboard(); swapKeyboard();
resetCounter(); should_reset = true;
break; break;
}
case SDLK_5: // Muestra la asignacion de mandos y teclado case SDLK_5: // Muestra la asignación de mandos y teclado
{
showControllers(); showControllers();
resetCounter(); should_reset = true;
break; break;
}
default: default:
break; break;
} }
// Resetear el contador si es necesario
if (should_reset)
{
resetCounter();
}
} }
// Comprueba el cursor globalEvents::check(event);
Mouse::handleEvent(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 // Reinicia el contador interno
void Title::resetCounter() { counter_ = 0; } void Title::resetCounter() { counter_ = 0; }

View File

@@ -72,9 +72,6 @@ private:
// Comprueba las entradas // Comprueba las entradas
void checkInput(); void checkInput();
// Recarga las texturas
void reLoadTextures();
// Reinicia el contador interno // Reinicia el contador interno
void resetCounter(); void resetCounter();