Compare commits

...

3 Commits

19 changed files with 147 additions and 76 deletions

View File

@@ -372,3 +372,12 @@ MUSICA COMPOSADA PER
## 124 - CREDITS
EFECTES DE SO
## 125 - NOTIFICACIONES
Torna a polsar per reiniciar
## 126 - NOTIFICACIONES
Torna a polsar per canviar el idioma a
## 127 - NOTIFICACIONES
Idioma canviat a

View File

@@ -372,3 +372,12 @@ MUSIC COMPOSED BY
## 124 - CREDITS
SOUND EFFECTS
## 125 - NOTIFICACIONES
Press again to reset
## 126 - NOTIFICACIONES
Press again to change languaje to
## 127 - NOTIFICACIONES
Language set to

View File

@@ -372,3 +372,12 @@ MUSICA COMPUESTA POR
## 124 - CREDITS
EFECTOS DE SONIDO
## 125 - NOTIFICACIONES
Vuelve a pulsar para reiniciar
## 126 - NOTIFICACIONES
Vuelve a pulsar para cambiar el idioma a
## 127 - NOTIFICACIONES
Idioma cambiado a

View File

@@ -555,7 +555,9 @@ void Director::setFileList()
// Si falta algun fichero, sale del programa
if (!Asset::get()->check())
{
throw std::runtime_error("Falta algun fichero");
}
}
// Comprueba los parametros del programa

View File

@@ -13,7 +13,7 @@ EnterName::EnterName()
void EnterName::init(const std::string &name)
{
// No se pasa ningún nombre
if (name == "")
if (name.empty())
{
name_ = "A";
position_ = 0;
@@ -24,7 +24,7 @@ void EnterName::init(const std::string &name)
{
name_ = name;
position_ = name_.length();
position_overflow_ = position_ >= NAME_LENGHT ? true : false;
position_overflow_ = position_ >= MAX_NAME_LENGHT ? true : false;
}
// Inicializa el vector de indices con el nombre y espacios
@@ -42,15 +42,15 @@ void EnterName::incPosition()
++position_;
if (position_ >= NAME_LENGHT)
if (position_ >= MAX_NAME_LENGHT)
{
position_ = NAME_LENGHT; // Mantenemos en el índice máximo válido.
position_overflow_ = true; // Activamos el flag de overflow.
position_ = MAX_NAME_LENGHT; // Mantenemos en el índice máximo válido.
position_overflow_ = true; // Activamos el flag de overflow.
}
else
{
// Copiamos el índice del carácter anterior si es posible.
if (position_ > 0 && position_ < NAME_LENGHT)
if (position_ > 0 && position_ < MAX_NAME_LENGHT)
{
character_index_[position_] = character_index_[position_ - 1];
}
@@ -71,7 +71,7 @@ void EnterName::decPosition()
{
// Si estaba en overflow, lo desactivamos y mantenemos position_ en el máximo.
position_overflow_ = false;
position_ = NAME_LENGHT - 1;
position_ = MAX_NAME_LENGHT - 1;
}
else
{
@@ -80,7 +80,7 @@ void EnterName::decPosition()
--position_;
// Limpiamos el carácter siguiente si el índice es válido.
if (position_ + 1 < NAME_LENGHT)
if (position_ + 1 < MAX_NAME_LENGHT)
{
character_index_[position_ + 1] = 0;
}
@@ -93,7 +93,7 @@ void EnterName::decPosition()
}
// Si position_ es menor que NAME_LENGHT, aseguramos que el overflow esté desactivado.
if (position_ < NAME_LENGHT)
if (position_ < MAX_NAME_LENGHT)
{
position_overflow_ = false;
}
@@ -102,7 +102,6 @@ void EnterName::decPosition()
updateNameFromCharacterIndex();
}
// Incrementa el índice
void EnterName::incIndex()
{
@@ -139,7 +138,7 @@ void EnterName::decIndex()
void EnterName::updateNameFromCharacterIndex()
{
name_.clear();
for (int i = 0; i < NAME_LENGHT; ++i)
for (int i = 0; i < MAX_NAME_LENGHT; ++i)
{
name_.push_back(character_list_[character_index_[i]]);
}
@@ -150,13 +149,13 @@ void EnterName::updateNameFromCharacterIndex()
void EnterName::initCharacterIndex(const std::string &name)
{
// Rellena de espacios
for (size_t i = 0; i < NAME_LENGHT; ++i)
for (size_t i = 0; i < MAX_NAME_LENGHT; ++i)
{
character_index_[i] = 0;
}
// Coloca los índices en función de los caracteres que forman el nombre
for (size_t i = 0; i < name.substr(0, NAME_LENGHT).size(); ++i)
for (size_t i = 0; i < name.substr(0, MAX_NAME_LENGHT).size(); ++i)
{
character_index_[i] = findIndex(name.at(i));
}
@@ -166,7 +165,11 @@ void EnterName::initCharacterIndex(const std::string &name)
int EnterName::findIndex(char character) const
{
for (size_t i = 0; i < character_list_.size(); ++i)
{
if (character == character_list_.at(i))
{
return i;
}
}
return 0;
}

View File

@@ -3,7 +3,7 @@
#include <string>
#include "utils.h"
constexpr int NAME_LENGHT = 6;
constexpr int MAX_NAME_LENGHT = 6;
/*
Un array, "characterList", contiene la lista de caracteres
@@ -17,11 +17,11 @@ constexpr int NAME_LENGHT = 6;
class EnterName
{
private:
std::string character_list_; // Lista de todos los caracteres permitidos
std::string name_; // Nombre introducido
int position_ = 0; // Posición a editar del nombre
bool position_overflow_ = false; // Indica si hemos incrementado la posición más allá del límite
int character_index_[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
std::string character_list_; // Lista de todos los caracteres permitidos
std::string name_; // Nombre introducido
int position_ = 0; // Posición a editar del nombre
bool position_overflow_ = false; // Indica si hemos incrementado la posición más allá del límite
int character_index_[MAX_NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
// Actualiza el nombre a partir de la lista de índices
void updateNameFromCharacterIndex();

View File

@@ -1268,9 +1268,11 @@ void Game::checkEvents()
case SDLK_3: // Activa el modo para pasar el juego automaticamente
{
auto_pop_balloons_ = !auto_pop_balloons_;
Notifier::get()->showText({"auto advance: " + boolToString(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;
}
@@ -1555,7 +1557,7 @@ void Game::handlePlayersInput()
// Gestiona la continuación del jugador.
handlePlayerContinue(player);
}
else if (player->isEnteringName() || player->isEnteringNameGameCompleted())
else if (player->isEnteringName() || player->isEnteringNameGameCompleted() || player->isShowingName())
{
// Gestiona la introducción del nombre del jugador.
handleNameInput(player);
@@ -1650,7 +1652,11 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
{
if (player->getEnterNamePositionOverflow())
if (player->isShowingName())
{
player->setPlayingState(PlayerState::CONTINUE);
}
else if (player->getEnterNamePositionOverflow())
{
player->setInput(InputType::START);
addScoreToScoreBoard(player);

View File

@@ -21,9 +21,8 @@ namespace globalInputs
// Termina
void quit(section::Options code)
{
const std::string exit_code = "QUIT";
auto code_found = stringInVector(Notifier::get()->getCodes(), exit_code);
if (code_found)
const std::string CODE = "QUIT";
if (Notifier::get()->checkCode(CODE))
{
// Si la notificación de salir está activa, cambia de sección
section::name = section::Name::QUIT;
@@ -33,10 +32,10 @@ namespace globalInputs
{
// Si la notificación de salir no está activa, muestra la notificación
#ifdef ARCADE
const int index = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
Notifier::get()->showText({lang::getText(index), std::string()}, -1, exit_code);
const int INDEX = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
Notifier::get()->showText({lang::getText(INDEX), std::string()}, -1, CODE);
#else
Notifier::get()->showText({lang::getText(94), std::string()}, -1, exit_code);
Notifier::get()->show({lang::getText(94), std::string()}, -1, CODE);
#endif
}
}
@@ -44,8 +43,16 @@ namespace globalInputs
// Reinicia
void reset()
{
section::name = section::Name::INIT;
Notifier::get()->showText({"Reset"});
const std::string CODE = "RESET";
if (Notifier::get()->checkCode(CODE))
{
section::name = section::Name::INIT;
Notifier::get()->show({"Reset"});
}
else
{
Notifier::get()->show({lang::getText(125), std::string()}, -1, CODE);
}
}
// Activa o desactiva el audio
@@ -62,7 +69,7 @@ namespace globalInputs
JA_SetMusicVolume(0);
JA_SetSoundVolume(0);
}
Notifier::get()->showText({"Audio " + boolToOnOff(options.audio.enabled)});
Notifier::get()->show({"Audio " + boolToOnOff(options.audio.enabled)});
}
// Obtiene una fichero a partir de un lang::Code
@@ -88,13 +95,13 @@ namespace globalInputs
switch (code)
{
case lang::Code::ba_BA:
return "ba_BA";
return " \"ba_BA\"";
break;
case lang::Code::es_ES:
return "es_ES";
return " \"es_ES\"";
break;
default:
return "en_UK";
return " \"en_UK\"";
break;
}
}
@@ -102,18 +109,27 @@ namespace globalInputs
// Cambia el idioma
void changeLang()
{
options.game.language = lang::change(options.game.language);
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
section::name = section::Name::INIT;
section::options = section::Options::RELOAD;
Notifier::get()->showText({getLangName(options.game.language)});
const std::string CODE = "LANG";
if (Notifier::get()->checkCode(CODE))
{
options.game.language = lang::getNextLangCode(options.game.language);
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
section::name = section::Name::INIT;
section::options = section::Options::RELOAD;
Notifier::get()->show({lang::getText(127) + getLangName(options.game.language)});
}
else
{
const auto NEXT = lang::getNextLangCode(options.game.language);
Notifier::get()->show({lang::getText(126) + getLangName(NEXT), std::string()}, -1, CODE);
}
}
// Cambia el modo de disparo
void toggleFireMode()
{
options.game.autofire = !options.game.autofire;
Notifier::get()->showText({"Autofire " + boolToOnOff(options.game.autofire)});
Notifier::get()->show({"Autofire " + boolToOnOff(options.game.autofire)});
}
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
@@ -127,7 +143,7 @@ namespace globalInputs
{
Screen::get()->toggleVideoMode();
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
Notifier::get()->showText({mode + " mode"});
Notifier::get()->show({mode + " mode"});
return;
}
@@ -136,7 +152,7 @@ namespace globalInputs
{
Screen::get()->decWindowSize();
const std::string size = std::to_string(options.video.window.size);
Notifier::get()->showText({"Window size x" + size});
Notifier::get()->show({"Window size x" + size});
return;
}
@@ -145,7 +161,7 @@ namespace globalInputs
{
Screen::get()->incWindowSize();
const std::string size = std::to_string(options.video.window.size);
Notifier::get()->showText({"Window size x" + size});
Notifier::get()->show({"Window size x" + size});
return;
}
#endif

View File

@@ -41,10 +41,10 @@ namespace lang
return texts.at(index);
}
// Cambia el idioma seleccionado al siguiente idioma disponible
Code change(Code current_lang)
// Obtiene el codigo del idioma del siguiente idioma
Code getNextLangCode(Code lang)
{
auto index = static_cast<int>(current_lang);
auto index = static_cast<int>(lang);
index = (index + 1) % 3;
return static_cast<Code>(index);
}

View File

@@ -17,6 +17,6 @@ namespace lang
// Obtiene la cadena de texto del indice
std::string getText(int index);
// Cambia el idioma seleccionado al siguiente idioma disponible
Code change(Code current_lang);
// Obtiene el codigo del idioma del siguiente idioma
Code getNextLangCode(Code lang);
}

View File

@@ -3,6 +3,7 @@
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip
#include <memory> // Para shared_ptr
#include <algorithm>
#include "sprite.h" // Para Sprite
class Texture; // lines 8-8

View File

@@ -153,7 +153,7 @@ void Notifier::clearFinishedNotifications()
}
}
void Notifier::showText(std::vector<std::string> texts, int icon, const std::string &code)
void Notifier::show(std::vector<std::string> texts, int icon, const std::string &code)
{
// Si no hay texto, acaba
if (texts.empty())
@@ -164,7 +164,7 @@ void Notifier::showText(std::vector<std::string> texts, int icon, const std::str
// Si las notificaciones no se apilan, elimina las anteriores
if (!stack_)
{
clearNotifications();
clearAllNotifications();
}
// Elimina las cadenas vacías
@@ -298,7 +298,7 @@ void Notifier::showText(std::vector<std::string> texts, int icon, const std::str
bool Notifier::isActive() { return !notifications_.empty(); }
// Finaliza y elimnina todas las notificaciones activas
void Notifier::clearNotifications()
void Notifier::clearAllNotifications()
{
for (auto &notification : notifications_)
{
@@ -318,3 +318,9 @@ std::vector<std::string> Notifier::getCodes()
}
return codes;
}
// Comprueba si hay alguna notificacion con un código
bool Notifier::checkCode(std::string code)
{
return stringInVector(getCodes(), code);
}

View File

@@ -66,7 +66,7 @@ private:
void clearFinishedNotifications();
// Finaliza y elimnina todas las notificaciones activas
void clearNotifications();
void clearAllNotifications();
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos notifier desde fuera
@@ -93,11 +93,14 @@ public:
void update();
// Muestra una notificación de texto por pantalla
void showText(std::vector<std::string> texts, int icon = -1, const std::string &code = std::string());
void show(std::vector<std::string> texts, int icon = -1, const std::string &code = std::string());
// Indica si hay notificaciones activas
bool isActive();
// Obtiene los códigos de las notificaciones
std::vector<std::string> getCodes();
// Comprueba si hay alguna notificacion con un código
bool checkCode(std::string code);
};

View File

@@ -149,6 +149,11 @@ void Player::setInputEnteringName(InputType input)
break;
case InputType::START:
last_enter_name_ = getRecordName();
if (last_enter_name_.empty())
{
const std::array<std::string, 8> NAMES = {"BAL1", "TABE", "DOC", "MON", "SAM1", "JORDI", "JDES", "PEPE"};
last_enter_name_ = NAMES.at(rand() % NAMES.size());
}
break;
default:
break;
@@ -166,9 +171,9 @@ void Player::move()
pos_x_ += vel_x_;
// Si el jugador abandona el area de juego por los laterales, restaura su posición
const float min_x = play_area_.x - 5;
const float max_x = play_area_.w + 5 - WIDTH_;
pos_x_ = std::clamp(pos_x_, min_x, max_x);
const float MIN_X = play_area_.x - 5;
const float MAX_X = play_area_.w + 5 - WIDTH_;
pos_x_ = std::clamp(pos_x_, MIN_X, MAX_X);
shiftSprite();
break;
@@ -176,12 +181,12 @@ void Player::move()
case PlayerState::DYING:
{
// Si el cadaver abandona el area de juego por los laterales lo hace rebotar
const int x = player_sprite_->getPosX();
const int min_x = play_area_.x;
const int max_x = play_area_.x + play_area_.w - WIDTH_;
if ((x < min_x) || (x > max_x))
const int X = player_sprite_->getPosX();
const int MIN_X = play_area_.x;
const int MAX_X = play_area_.x + play_area_.w - WIDTH_;
if ((X < MIN_X) || (X > MAX_X))
{
player_sprite_->setPosX(std::clamp(x, min_x, max_x));
player_sprite_->setPosX(std::clamp(X, MIN_X, MAX_X));
player_sprite_->setVelX(-player_sprite_->getVelX());
playRandomBubbleSound();
}
@@ -287,7 +292,6 @@ void Player::move()
{
pos_x_ = param.game.game_area.rect.w - WIDTH_;
vel_x_ *= -1;
// setInputPlaying(InputType::LEFT);
}
}
else
@@ -297,7 +301,6 @@ void Player::move()
{
pos_x_ = param.game.game_area.rect.x;
vel_x_ *= -1;
// setInputPlaying(InputType::RIGHT);
}
}
@@ -356,17 +359,20 @@ void Player::setAnimation()
// Establece la animación a partir de las cadenas
if (firing_state_ == PlayerState::FIRING_NONE)
{ // No esta disparando
{
// No esta disparando
player_sprite_->setCurrentAnimation(a_walking);
player_sprite_->setFlip(flip_walk);
}
else if (isCooling())
{ // Acaba de disparar
{
// Acaba de disparar
player_sprite_->setCurrentAnimation(a_walking + "-" + a_cooling + "-cooldown");
player_sprite_->setFlip(flip_cooling);
}
else
{ // Está disparando
{
// Está disparando
player_sprite_->setCurrentAnimation(a_walking + "-" + a_firing);
// Si dispara de lado, invierte el sprite segun hacia donde dispara
// Si dispara recto, invierte el sprite segun hacia donde camina

View File

@@ -208,6 +208,7 @@ public:
bool isContinue() const { return playing_state_ == PlayerState::CONTINUE; }
bool isDying() const { return playing_state_ == PlayerState::DYING; }
bool isEnteringName() const { return playing_state_ == PlayerState::ENTERING_NAME; }
bool isShowingName() const { return playing_state_ == PlayerState::SHOWING_NAME; }
bool isEnteringNameGameCompleted() const { return playing_state_ == PlayerState::ENTERING_NAME_GAME_COMPLETED; }
bool isLeavingScreen() const { return playing_state_ == PlayerState::LEAVING_SCREEN; }
bool isGameOver() const { return playing_state_ == PlayerState::GAME_OVER; }

View File

@@ -263,7 +263,7 @@ void Scoreboard::fillPanelTextures()
SDL_Rect rect = {enter_name_pos_.x, enter_name_pos_.y, 5, 7};
// Recorre todos los slots de letras del nombre
for (size_t j = 0; j < NAME_LENGHT; ++j)
for (size_t j = 0; j < MAX_NAME_LENGHT; ++j)
{
// Selecciona el color
const Color color = j < selector_pos_[i] ? orange_soft_color.lighten() : Color(0xFF, 0xFF, 0xEB);
@@ -380,7 +380,7 @@ void Scoreboard::recalculateAnchors()
slot4_4_ = {col, row4};
// Primer cuadrado para poner el nombre de record
const int enter_name_lenght = text_scoreboard_->lenght(std::string(NAME_LENGHT, 'A'));
const int enter_name_lenght = text_scoreboard_->lenght(std::string(MAX_NAME_LENGHT, 'A'));
enter_name_pos_.x = col - (enter_name_lenght / 2);
enter_name_pos_.y = row4;

View File

@@ -337,7 +337,7 @@ void Screen::toggleShaders()
options.video.shaders = !options.video.shaders;
setVideoMode(options.video.mode);
const std::string value = options.video.shaders ? "on" : "off";
Notifier::get()->showText({"Shaders " + value});
Notifier::get()->show({"Shaders " + value});
}
// Activa / desactiva la información de debug

View File

@@ -34,7 +34,7 @@ public:
void update() override;
// Dibuja el sprite
void render();
void render() override;
// Getters
int getDestX() const { return dest_x_; }

View File

@@ -375,7 +375,7 @@ void Title::swapKeyboard()
{
swapOptionsKeyboard();
std::string text = lang::getText(100) + std::to_string(getPlayerWhoUsesKeyboard()) + ": " + lang::getText(69);
Notifier::get()->showText({text});
Notifier::get()->show({text});
}
// Muestra información sobre los controles y los jugadores
@@ -404,5 +404,5 @@ void Title::showControllers()
}
// Muestra la notificación
Notifier::get()->showText({text.at(0), text.at(1)});
Notifier::get()->show({text.at(0), text.at(1)});
}