Afegit global_events.cpp
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
188
source/game.cpp
188
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;
|
||||
}
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||
#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 <string> // Para string
|
||||
#include <vector> // 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();
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -94,7 +94,4 @@ public:
|
||||
|
||||
// Indica si ha terminado la animación
|
||||
bool hasFinished() const;
|
||||
|
||||
// Recarga las texturas
|
||||
void reLoad();
|
||||
};
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,9 +67,6 @@ private:
|
||||
// Dibuja los sprites en la textura
|
||||
void fillTexture();
|
||||
|
||||
// Recarga todas las texturas
|
||||
void reloadTextures();
|
||||
|
||||
// Gestiona el fade
|
||||
void updateFade();
|
||||
|
||||
|
||||
@@ -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 <SDL2/SDL.h>
|
||||
#include <vector>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Line> initializeLines(int height);
|
||||
|
||||
|
||||
@@ -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 <array>
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
147
source/logo.cpp
147
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<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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Pixel> 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<Pixel> extractPixels(SDL_Texture *texture);
|
||||
|
||||
void renderAndEvaporate(SDL_Renderer *renderer, std::vector<Pixel> &pixels);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Logo();
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -90,10 +90,4 @@ void TiledBG::update()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Recarga las texturas
|
||||
void TiledBG::reLoad()
|
||||
{
|
||||
fillTexture();
|
||||
}
|
||||
@@ -52,7 +52,4 @@ public:
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
void update();
|
||||
|
||||
// Recarga las texturas
|
||||
void reLoad();
|
||||
};
|
||||
101
source/title.cpp
101
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; }
|
||||
|
||||
|
||||
@@ -72,9 +72,6 @@ private:
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
|
||||
// Recarga las texturas
|
||||
void reLoadTextures();
|
||||
|
||||
// Reinicia el contador interno
|
||||
void resetCounter();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user