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

@@ -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