Menudo puto lio de renamar coses, a vore si tot va quedant al lloc que els structs i els enums estan revolant i duplicats per tots llocs

This commit is contained in:
2024-10-11 20:12:50 +02:00
parent a9ca23138d
commit 3a6950f3a4
28 changed files with 445 additions and 454 deletions

View File

@@ -95,7 +95,7 @@ bool Asset::check() const
if (any) if (any)
{ {
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl; std::cout << "\n>> " << getTypeName(static_cast<AssetType>(type)).c_str() << " FILES" << std::endl;
#endif #endif
for (auto f : file_list_) for (auto f : file_list_)
@@ -146,43 +146,43 @@ bool Asset::checkFile(std::string path) const
} }
// Devuelve el nombre del tipo de recurso // Devuelve el nombre del tipo de recurso
std::string Asset::getTypeName(int type) const std::string Asset::getTypeName(AssetType type) const
{ {
switch (type) switch (type)
{ {
case static_cast<int>(AssetType::BITMAP): case AssetType::BITMAP:
return "BITMAP"; return "BITMAP";
break; break;
case static_cast<int>(AssetType::MUSIC): case AssetType::MUSIC:
return "MUSIC"; return "MUSIC";
break; break;
case static_cast<int>(AssetType::SOUND): case AssetType::SOUND:
return "SOUND"; return "SOUND";
break; break;
case static_cast<int>(AssetType::FONT): case AssetType::FONT:
return "FONT"; return "FONT";
break; break;
case static_cast<int>(AssetType::LANG): case AssetType::LANG:
return "LANG"; return "LANG";
break; break;
case static_cast<int>(AssetType::DATA): case AssetType::DATA:
return "DATA"; return "DATA";
break; break;
case static_cast<int>(AssetType::ANIMATION): case AssetType::ANIMATION:
return "ANIMATION"; return "ANIMATION";
break; break;
case static_cast<int>(AssetType::PALETTE): case AssetType::PALETTE:
return "PALETTE"; return "PALETTE";
break; break;
case static_cast<int>(AssetType::ITEM): case AssetType::ITEM:
return "ITEM"; return "ITEM";
break; break;

View File

@@ -3,7 +3,7 @@
#include <string> // for string, basic_string #include <string> // for string, basic_string
#include <vector> // for vector #include <vector> // for vector
enum class AssetType enum class AssetType : int
{ {
BITMAP, BITMAP,
MUSIC, MUSIC,
@@ -42,7 +42,7 @@ private:
bool checkFile(std::string executable_path) const; bool checkFile(std::string executable_path) const;
// Devuelve el nombre del tipo de recurso // Devuelve el nombre del tipo de recurso
std::string getTypeName(int type) const; std::string getTypeName(AssetType type) const;
// Constructor // Constructor
Asset(std::string path); Asset(std::string path);

View File

@@ -2,7 +2,7 @@
#include "lang.h" // for getText #include "lang.h" // for getText
#include "options.h" // for options #include "options.h" // for options
#include "param.h" // for param #include "param.h" // for param
#include "section.h" // for name, name_e, options, options_e #include "section.h" // for name, SectionName, options, SectionOptions
#include "text.h" // for Text #include "text.h" // for Text
#include "utils.h" // for OptionsController, Options, Param, ParamGame #include "utils.h" // for OptionsController, Options, Param, ParamGame
@@ -103,8 +103,8 @@ void DefineButtons::checkInput()
{ {
case SDL_QUIT: case SDL_QUIT:
{ {
section::name = section::NAME_QUIT; section::name = section::Name::QUIT;
section::options = section::OPTIONS_QUIT_NORMAL; section::options = section::Options::QUIT_NORMAL;
break; break;
} }

View File

@@ -31,7 +31,7 @@
#include "options.h" // for options, loadOptionsFile, saveO... #include "options.h" // for options, loadOptionsFile, saveO...
#include "param.h" // for param, loadParamsFromFile #include "param.h" // for param, loadParamsFromFile
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "section.h" // for name_e, name, options, options_e #include "section.h" // for SectionName, name, options, SectionOptions
#include "title.h" // for Title #include "title.h" // for Title
#include "utils.h" // for MusicFile, SoundFile, opt... #include "utils.h" // for MusicFile, SoundFile, opt...
#include <memory> #include <memory>
@@ -44,12 +44,12 @@
Director::Director(int argc, char *argv[]) Director::Director(int argc, char *argv[])
{ {
#ifdef RECORDING #ifdef RECORDING
section::name = section::NAME_GAME; section::name = section::Name::GAME;
section::options = section::OPTIONS_GAME_PLAY_1P; section::options = section::Options::GAME_PLAY_1P;
#elif DEBUG #elif DEBUG
section::name = section::NAME_LOGO; section::name = section::Name::LOGO;
#else #else
section::name = section::NAME_LOGO; section::name = section::Name::LOGO;
#endif #endif
// Comprueba los parametros del programa // Comprueba los parametros del programa
@@ -631,7 +631,7 @@ void Director::runTitle()
// Ejecuta la sección donde se juega al juego // Ejecuta la sección donde se juega al juego
void Director::runGame() void Director::runGame()
{ {
const auto playerID = section::options == section::OPTIONS_GAME_PLAY_1P ? 1 : 2; const auto playerID = section::options == section::Options::GAME_PLAY_1P ? 1 : 2;
constexpr auto currentStage = 0; constexpr auto currentStage = 0;
auto game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, getMusic(musics_, "playing.ogg")); auto game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, getMusic(musics_, "playing.ogg"));
game->run(); game->run();
@@ -667,39 +667,39 @@ void Director::runDemoGame()
int Director::run() int Director::run()
{ {
// Bucle principal // Bucle principal
while (section::name != section::NAME_QUIT) while (section::name != section::Name::QUIT)
{ {
switch (section::name) switch (section::name)
{ {
case section::NAME_INIT: case section::Name::INIT:
section::name = section::NAME_LOGO; section::name = section::Name::LOGO;
break; break;
case section::NAME_LOGO: case section::Name::LOGO:
runLogo(); runLogo();
break; break;
case section::NAME_INTRO: case section::Name::INTRO:
runIntro(); runIntro();
break; break;
case section::NAME_TITLE: case section::Name::TITLE:
runTitle(); runTitle();
break; break;
case section::NAME_GAME: case section::Name::GAME:
runGame(); runGame();
break; break;
case section::NAME_HI_SCORE_TABLE: case section::Name::HI_SCORE_TABLE:
runHiScoreTable(); runHiScoreTable();
break; break;
case section::NAME_GAME_DEMO: case section::Name::GAME_DEMO:
runDemoGame(); runDemoGame();
break; break;
case section::NAME_INSTRUCTIONS: case section::Name::INSTRUCTIONS:
runInstructions(); runInstructions();
break; break;
@@ -708,7 +708,7 @@ int Director::run()
} }
} }
const int returnCode = section::options == section::OPTIONS_QUIT_NORMAL ? 0 : 1; const int returnCode = section::options == section::Options::QUIT_NORMAL ? 0 : 1;
return returnCode; return returnCode;
} }

View File

@@ -119,7 +119,7 @@ void Fade::update()
if (counter_ % fade_random_squares_delay_ == 0) if (counter_ % fade_random_squares_delay_ == 0)
{ {
// Dibuja sobre el backbuffer_ // Dibuja sobre el backbuffer_
auto *temp = SDL_GetRenderTarget(renderer_); auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_); SDL_SetRenderTarget(renderer_, backbuffer_);
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_NONE);
@@ -154,7 +154,7 @@ void Fade::update()
if (square_.back().h < param.fade.venetian_size) if (square_.back().h < param.fade.venetian_size)
{ {
// Dibuja sobre el backbuffer_ // Dibuja sobre el backbuffer_
auto *temp = SDL_GetRenderTarget(renderer_); auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_); SDL_SetRenderTarget(renderer_, backbuffer_);
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, a_); SDL_SetRenderDrawColor(renderer_, r_, g_, b_, a_);
@@ -299,9 +299,9 @@ bool Fade::hasEnded() const
} }
// Establece el tipo de fade // Establece el tipo de fade
void Fade::setType(FadeType type_) void Fade::setType(FadeType type)
{ {
type_ = type_; type_ = type;
} }
// Establece el modo de fade // Establece el modo de fade

View File

@@ -6,7 +6,7 @@
#include <vector> // for vector #include <vector> // for vector
// Tipos de fundido // Tipos de fundido
enum class FadeType enum class FadeType : Uint8
{ {
FULLSCREEN = 0, FULLSCREEN = 0,
CENTER = 1, CENTER = 1,
@@ -15,7 +15,7 @@ enum class FadeType
}; };
// Modos de fundido // Modos de fundido
enum class FadeMode enum class FadeMode : Uint8
{ {
IN = 0, IN = 0,
OUT = 1, OUT = 1,
@@ -26,25 +26,25 @@ class Fade
{ {
private: private:
// Objetos y punteros // Objetos y punteros
SDL_Renderer *renderer_; // El renderizador de la ventana SDL_Renderer *renderer_; // El renderizador de la ventana
SDL_Texture *backbuffer_; // Textura para usar como backbuffer con SDL_TEXTUREACCESS_TARGET SDL_Texture *backbuffer_; // Textura para usar como backbuffer con SDL_TEXTUREACCESS_TARGET
// Variables // Variables
FadeType type_; // Tipo de fade a realizar FadeType type_; // Tipo de fade a realizar
FadeMode mode_; // Modo de fade a realizar FadeMode mode_; // Modo de fade a realizar
Uint16 counter_; // Contador interno Uint16 counter_; // Contador interno
bool enabled_; // Indica si el fade está activo bool enabled_; // Indica si el fade está activo
bool finished_; // Indica si ha terminado la transición bool finished_; // Indica si ha terminado la transición
Uint8 r_, g_, b_, a_; // Colores para el fade Uint8 r_, g_, b_, a_; // Colores para el fade
SDL_Rect rect1_; // Rectangulo usado para crear los efectos de transición SDL_Rect rect1_; // Rectangulo usado para crear los efectos de transición
SDL_Rect rect2_; // Rectangulo usado para crear los efectos de transición SDL_Rect rect2_; // Rectangulo usado para crear los efectos de transición
int num_squares_width_; // Cantidad total de cuadraditos en horizontal para el FadeType::RANDOM_SQUARE int num_squares_width_; // Cantidad total de cuadraditos en horizontal para el FadeType::RANDOM_SQUARE
int num_squares_height_; // Cantidad total de cuadraditos en vertical para el FadeType::RANDOM_SQUARE int num_squares_height_; // Cantidad total de cuadraditos en vertical para el FadeType::RANDOM_SQUARE
std::vector<SDL_Rect> square_; // Vector con los indices de los cuadrados para el FadeType::RANDOM_SQUARE std::vector<SDL_Rect> square_; // Vector con los indices de los cuadrados para el FadeType::RANDOM_SQUARE
int fade_random_squares_delay_; // Duración entre cada pintado de cuadrados int fade_random_squares_delay_; // Duración entre cada pintado de cuadrados
int fade_random_squares_mult_; // Cantidad de cuadrados que se pintaran cada vez int fade_random_squares_mult_; // Cantidad de cuadrados que se pintaran cada vez
int post_duration_; // Duración posterior del fade tras finalizar int post_duration_; // Duración posterior del fade tras finalizar
int post_counter_; // Contador para la duración posterior int post_counter_; // Contador para la duración posterior
// Inicializa las variables // Inicializa las variables
void init(); void init();

View File

@@ -28,7 +28,7 @@
#include "scoreboard.h" // for Scoreboard, scoreboard_modes_e #include "scoreboard.h" // for Scoreboard, scoreboard_modes_e
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "smart_sprite.h" // for SmartSprite #include "smart_sprite.h" // for SmartSprite
#include "text.h" // for Text, TXT_CENTER #include "text.h" // for Text, TEXT_CENTER
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "dbgtxt.h" #include "dbgtxt.h"
struct JA_Music_t; struct JA_Music_t;
@@ -197,8 +197,8 @@ void Game::init(int playerID)
paused = false; paused = false;
gameCompleted = false; gameCompleted = false;
gameCompletedCounter = 0; gameCompletedCounter = 0;
section::name = section::NAME_GAME; section::name = section::Name::GAME;
section::options = section::OPTIONS_GAME_PLAY_1P; section::options = section::Options::GAME_PLAY_1P;
currentPower = 0; currentPower = 0;
menaceCurrent = 0; menaceCurrent = 0;
menaceThreshold = 0; menaceThreshold = 0;
@@ -883,7 +883,7 @@ void Game::updateGameOver()
if (fade->hasEnded()) if (fade->hasEnded())
{ {
section::name = section::NAME_HI_SCORE_TABLE; section::name = section::Name::HI_SCORE_TABLE;
} }
} }
} }
@@ -1754,7 +1754,7 @@ void Game::update()
// Si ha terminado el fundido, cambia de sección // Si ha terminado el fundido, cambia de sección
if (fade->hasEnded()) if (fade->hasEnded())
{ {
section::name = section::NAME_HI_SCORE_TABLE; section::name = section::Name::HI_SCORE_TABLE;
return; return;
} }
} }
@@ -1772,7 +1772,7 @@ void Game::update()
// Si se ha llenado el vector con datos, sale del programa // Si se ha llenado el vector con datos, sale del programa
else else
{ {
section::name = section::NAME_QUIT; section::name = section::Name::QUIT;
return; return;
} }
#endif #endif
@@ -2019,7 +2019,7 @@ void Game::checkInput()
// Si se pulsa cualquier tecla, se sale del modo demo // Si se pulsa cualquier tecla, se sale del modo demo
if (input->checkAnyButtonPressed()) if (input->checkAnyButtonPressed())
{ {
section::name = section::NAME_TITLE; section::name = section::Name::TITLE;
return; return;
} }
} }
@@ -2214,7 +2214,7 @@ void Game::renderMessages()
{ {
if (timeStoppedCounter > 100 || timeStoppedCounter % 10 > 4) if (timeStoppedCounter > 100 || timeStoppedCounter % 10 > 4)
{ {
textNokia2->writeDX(TXT_CENTER, param.game.play_area.center_x, param.game.play_area.first_quarter_y, lang::getText(36) + std::to_string(timeStoppedCounter / 10), -1, no_color, 1, shdw_txt_color); textNokia2->writeDX(TEXT_CENTER, param.game.play_area.center_x, param.game.play_area.first_quarter_y, lang::getText(36) + std::to_string(timeStoppedCounter / 10), -1, no_color, 1, shdw_txt_color);
} }
if (timeStoppedCounter > 100) if (timeStoppedCounter > 100)
@@ -2250,13 +2250,13 @@ void Game::renderMessages()
if (!gameCompleted) if (!gameCompleted)
{ // Escribe el número de fases restantes { // Escribe el número de fases restantes
textNokiaBig2->writeDX(TXT_CENTER, param.game.play_area.center_x, stageBitmapPath[stageBitmapCounter], text, -2, no_color, 2, shdw_txt_color); textNokiaBig2->writeDX(TEXT_CENTER, param.game.play_area.center_x, stageBitmapPath[stageBitmapCounter], text, -2, no_color, 2, shdw_txt_color);
} }
else else
{ // Escribe el texto de juego completado { // Escribe el texto de juego completado
text = lang::getText(50); text = lang::getText(50);
textNokiaBig2->writeDX(TXT_CENTER, param.game.play_area.center_x, stageBitmapPath[stageBitmapCounter], text, -2, no_color, 1, shdw_txt_color); textNokiaBig2->writeDX(TEXT_CENTER, param.game.play_area.center_x, stageBitmapPath[stageBitmapCounter], text, -2, no_color, 1, shdw_txt_color);
textNokia2->writeDX(TXT_CENTER, param.game.play_area.center_x, stageBitmapPath[stageBitmapCounter] + textNokiaBig2->getCharacterSize() + 2, lang::getText(76), -1, no_color, 1, shdw_txt_color); textNokia2->writeDX(TEXT_CENTER, param.game.play_area.center_x, stageBitmapPath[stageBitmapCounter] + textNokiaBig2->getCharacterSize() + 2, lang::getText(76), -1, no_color, 1, shdw_txt_color);
} }
} }
} }
@@ -2299,7 +2299,7 @@ void Game::checkMusicStatus()
// Bucle para el juego // Bucle para el juego
void Game::run() void Game::run()
{ {
while (section::name == section::NAME_GAME) while (section::name == section::Name::GAME)
{ {
#ifndef RECORDING #ifndef RECORDING
checkInput(); checkInput();
@@ -2419,8 +2419,8 @@ void Game::updateGameCompleted()
if (gameCompletedCounter == GAME_COMPLETED_END) if (gameCompletedCounter == GAME_COMPLETED_END)
{ {
section::name = section::NAME_TITLE; section::name = section::Name::TITLE;
section::options = section::OPTIONS_TITLE_1; section::options = section::Options::TITLE_1;
} }
} }
@@ -2487,7 +2487,7 @@ void Game::checkEvents()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
{ {
section::name = section::NAME_QUIT; section::name = section::Name::QUIT;
break; break;
} }

View File

@@ -5,7 +5,7 @@
#include <SDL2/SDL_stdinc.h> // for Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <string> // for string #include <string> // for string
#include <vector> // for vector #include <vector> // for vector
#include "section.h" // for options_e #include "section.h" // for SectionOptions
#include "utils.h" // for DemoKeys, Color, HiScoreEntry #include "utils.h" // for DemoKeys, Color, HiScoreEntry
#include <memory> #include <memory>
#include "asset.h" // lines 11-11 #include "asset.h" // lines 11-11

View File

@@ -6,7 +6,7 @@
#include "options.h" // for options #include "options.h" // for options
#include "on_screen_help.h" #include "on_screen_help.h"
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "section.h" // for options_e, name, name_e, options #include "section.h" // for SectionOptions, name, SectionName, options
#include "utils.h" // for OptionsAudio, Options, OptionsMusic, boolToOnOff #include "utils.h" // for OptionsAudio, Options, OptionsMusic, boolToOnOff
namespace globalInputs namespace globalInputs
@@ -26,11 +26,11 @@ namespace globalInputs
} }
// Termina // Termina
void quit(section::options_e code) void quit(section::Options code)
{ {
if (Screen::get()->notificationsAreActive()) if (Screen::get()->notificationsAreActive())
{ {
section::name = section::NAME_QUIT; section::name = section::Name::QUIT;
section::options = code; section::options = code;
} }
else else
@@ -42,7 +42,7 @@ namespace globalInputs
// Reinicia // Reinicia
void reset() void reset()
{ {
section::name = section::NAME_INIT; section::name = section::Name::INIT;
Screen::get()->showNotification("Reset"); Screen::get()->showNotification("Reset");
} }
@@ -61,7 +61,7 @@ namespace globalInputs
// Comprueba si se sale con el teclado // Comprueba si se sale con el teclado
if (Input::get()->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) if (Input::get()->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{ {
quit(section::OPTIONS_QUIT_NORMAL); quit(section::Options::QUIT_NORMAL);
return; return;
} }
@@ -99,7 +99,7 @@ namespace globalInputs
// Comprueba si se sale con el mando // Comprueba si se sale con el mando
if (Input::get()->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) if (Input::get()->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{ {
quit(section::OPTIONS_QUIT_SHUTDOWN); quit(section::Options::QUIT_SHUTDOWN);
return; return;
} }

View File

@@ -14,7 +14,7 @@
#include "options.h" // for options #include "options.h" // for options
#include "param.h" // for param #include "param.h" // for param
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW, TXT_COLOR #include "text.h" // for Text, TEXT_CENTER, TEXT_SHADOW, TEXT_COLOR
#include "utils.h" // for Param, ParamGame, HiScoreEntry #include "utils.h" // for Param, ParamGame, HiScoreEntry
// Constructor // Constructor
@@ -35,7 +35,7 @@ HiScoreTable::HiScoreTable(JA_Music_t *music)
SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND);
// Inicializa variables // Inicializa variables
section::name = section::NAME_HI_SCORE_TABLE; section::name = section::Name::HI_SCORE_TABLE;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
counter = 0; counter = 0;
@@ -115,13 +115,13 @@ void HiScoreTable::fillTexture()
const auto firstLine = (param.game.height - size) / 2; const auto firstLine = (param.game.height - size) / 2;
// Pinta en el backbuffer el texto y los sprites // Pinta en el backbuffer el texto y los sprites
auto *temp = SDL_GetRenderTarget(renderer); auto temp = SDL_GetRenderTarget(renderer);
SDL_SetRenderTarget(renderer, backbuffer); SDL_SetRenderTarget(renderer, backbuffer);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
// Escribe el texto: Mejores puntuaciones // Escribe el texto: Mejores puntuaciones
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.center_x, firstLine, lang::getText(42), 1, orange_color, 1, shdw_txt_color); text->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, firstLine, lang::getText(42), 1, orange_color, 1, shdw_txt_color);
// Escribe los nombres de la tabla de puntuaciones // Escribe los nombres de la tabla de puntuaciones
for (int i = 0; i < maxNames; ++i) for (int i = 0; i < maxNames; ++i)
@@ -136,7 +136,7 @@ void HiScoreTable::fillTexture()
dots = dots + "."; dots = dots + ".";
} }
const auto line = options.game.hi_score_table[i].name + dots + score; const auto line = options.game.hi_score_table[i].name + dots + score;
text->writeDX(TXT_CENTER | TXT_SHADOW, param.game.game_area.center_x, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orange_color, 1, shdw_txt_color); text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orange_color, 1, shdw_txt_color);
} }
// Cambia el destino de renderizado // Cambia el destino de renderizado
@@ -184,7 +184,7 @@ void HiScoreTable::checkEvents()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section::name = section::NAME_QUIT; section::name = section::Name::QUIT;
break; break;
} }
@@ -206,8 +206,8 @@ void HiScoreTable::checkInput()
if (Input::get()->checkAnyButtonPressed()) if (Input::get()->checkAnyButtonPressed())
{ {
JA_StopMusic(); JA_StopMusic();
section::name = section::NAME_TITLE; section::name = section::Name::TITLE;
section::options = section::OPTIONS_TITLE_1; section::options = section::Options::TITLE_1;
return; return;
} }
@@ -221,7 +221,7 @@ void HiScoreTable::checkInput()
// Bucle para la pantalla de instrucciones // Bucle para la pantalla de instrucciones
void HiScoreTable::run() void HiScoreTable::run()
{ {
while (section::name == section::NAME_HI_SCORE_TABLE) while (section::name == section::Name::HI_SCORE_TABLE)
{ {
checkInput(); checkInput();
update(); update();
@@ -244,7 +244,7 @@ void HiScoreTable::updateFade()
if (fade->hasEnded() && fadeMode == FadeMode::OUT) if (fade->hasEnded() && fadeMode == FadeMode::OUT)
{ {
section::name = section::NAME_INSTRUCTIONS; section::name = section::Name::INSTRUCTIONS;
} }
} }

View File

@@ -7,7 +7,7 @@
#include <memory> #include <memory>
#include <string> // for string #include <string> // for string
#include "fade.h" #include "fade.h"
#include "section.h" // for options_e #include "section.h" // for SectionOptions
#include "background.h" #include "background.h"
#include "text.h" #include "text.h"

View File

@@ -13,9 +13,9 @@
#include "lang.h" // for getText #include "lang.h" // for getText
#include "param.h" // for param #include "param.h" // for param
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "section.h" // for name, name_e, options, options_e #include "section.h" // for name, SectionName, options, SectionOptions
#include "sprite.h" // for Sprite #include "sprite.h" // for Sprite
#include "text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_SHADOW #include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR, TEXT_SHADOW
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "tiled_bg.h" // for Tiledbg, TILED_MODE_STATIC #include "tiled_bg.h" // for Tiledbg, TILED_MODE_STATIC
#include "utils.h" // for Param, ParamGame, Color, shdwT... #include "utils.h" // for Param, ParamGame, Color, shdwT...
@@ -43,7 +43,7 @@ Instructions::Instructions(JA_Music_t *music)
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
// Inicializa variables // Inicializa variables
section::name = section::NAME_INSTRUCTIONS; section::name = section::Name::INSTRUCTIONS;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
counter = 0; counter = 0;
@@ -168,17 +168,17 @@ void Instructions::fillTexture()
const int anchorItem = (param.game.width - (lenght + despX)) / 2; const int anchorItem = (param.game.width - (lenght + despX)) / 2;
// Escribe el texto de las instrucciones // Escribe el texto de las instrucciones
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.center_x, firstLine, lang::getText(11), 1, orange_color, 1, shdw_txt_color); text->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, firstLine, lang::getText(11), 1, orange_color, 1, shdw_txt_color);
const int anchor1 = firstLine + spacePostHeader; const int anchor1 = firstLine + spacePostHeader;
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.center_x, anchor1 + spaceBetweenLines * 0, lang::getText(12), 1, no_color, 1, shdw_txt_color); text->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + spaceBetweenLines * 0, lang::getText(12), 1, no_color, 1, shdw_txt_color);
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.center_x, anchor1 + spaceBetweenLines * 1, lang::getText(13), 1, no_color, 1, shdw_txt_color); text->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + spaceBetweenLines * 1, lang::getText(13), 1, no_color, 1, shdw_txt_color);
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.center_x, anchor1 + spaceNewParagraph + spaceBetweenLines * 2, lang::getText(14), 1, no_color, 1, shdw_txt_color); text->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + spaceNewParagraph + spaceBetweenLines * 2, lang::getText(14), 1, no_color, 1, shdw_txt_color);
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.center_x, anchor1 + spaceNewParagraph + spaceBetweenLines * 3, lang::getText(15), 1, no_color, 1, shdw_txt_color); text->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + spaceNewParagraph + spaceBetweenLines * 3, lang::getText(15), 1, no_color, 1, shdw_txt_color);
// Escribe el texto de los objetos y sus puntos // Escribe el texto de los objetos y sus puntos
const int anchor2 = anchor1 + spacePreHeader + spaceNewParagraph + spaceBetweenLines * 3; const int anchor2 = anchor1 + spacePreHeader + spaceNewParagraph + spaceBetweenLines * 3;
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.center_x, anchor2, lang::getText(16), 1, orange_color, 1, shdw_txt_color); text->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor2, lang::getText(16), 1, orange_color, 1, shdw_txt_color);
const int anchor3 = anchor2 + spacePostHeader; const int anchor3 = anchor2 + spacePostHeader;
// const int anchor4 = anchor3 + ((param.game.item_size + text->getCharacterSize()) / 2); // const int anchor4 = anchor3 + ((param.game.item_size + text->getCharacterSize()) / 2);
@@ -251,8 +251,8 @@ void Instructions::update()
// Comprueba si el contador ha llegado al final // Comprueba si el contador ha llegado al final
if (counter == counterEnd) if (counter == counterEnd)
{ {
section::name = section::NAME_TITLE; section::name = section::Name::TITLE;
section::options = section::OPTIONS_TITLE_1; section::options = section::Options::TITLE_1;
} }
} }
} }
@@ -304,7 +304,7 @@ void Instructions::checkEvents()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (eventHandler->type == SDL_QUIT)
{ {
section::name = section::NAME_QUIT; section::name = section::Name::QUIT;
break; break;
} }
@@ -326,8 +326,8 @@ void Instructions::checkInput()
if (Input::get()->checkAnyButtonPressed()) if (Input::get()->checkAnyButtonPressed())
{ {
JA_StopMusic(); JA_StopMusic();
section::name = section::NAME_TITLE; section::name = section::Name::TITLE;
section::options = section::OPTIONS_TITLE_1; section::options = section::Options::TITLE_1;
return; return;
} }
@@ -341,7 +341,7 @@ void Instructions::checkInput()
// Bucle para la pantalla de instrucciones // Bucle para la pantalla de instrucciones
void Instructions::run() void Instructions::run()
{ {
while (section::name == section::NAME_INSTRUCTIONS) while (section::name == section::Name::INSTRUCTIONS)
{ {
checkInput(); checkInput();
update(); update();

View File

@@ -10,7 +10,7 @@
#include "lang.h" // for getText #include "lang.h" // for getText
#include "param.h" // for param #include "param.h" // for param
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "section.h" // for name, name_e, options, options_e #include "section.h" // for name, SectionName, options, SectionOptions
#include "smart_sprite.h" // for SmartSprite #include "smart_sprite.h" // for SmartSprite
#include "text.h" // for Text #include "text.h" // for Text
#include "texture.h" // for Texture #include "texture.h" // for Texture
@@ -30,8 +30,8 @@ Intro::Intro(JA_Music_t *music)
text = std::make_shared<Text>(Asset::get()->get("nokia.png"), Asset::get()->get("nokia.txt"), renderer); text = std::make_shared<Text>(Asset::get()->get("nokia.png"), Asset::get()->get("nokia.txt"), renderer);
// Inicializa variables // Inicializa variables
section::name = section::NAME_INTRO; section::name = section::Name::INTRO;
section::options = section::OPTIONS_NULL; section::options = section::Options::NONE;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
scene = 1; scene = 1;
@@ -172,7 +172,7 @@ void Intro::checkEvents()
{ {
case SDL_QUIT: case SDL_QUIT:
{ {
section::name = section::NAME_QUIT; section::name = section::Name::QUIT;
break; break;
} }
@@ -198,8 +198,8 @@ void Intro::checkInput()
if (Input::get()->checkAnyButtonPressed()) if (Input::get()->checkAnyButtonPressed())
{ {
JA_StopMusic(); JA_StopMusic();
section::name = section::NAME_TITLE; section::name = section::Name::TITLE;
section::options = section::OPTIONS_TITLE_1; section::options = section::Options::TITLE_1;
return; return;
} }
@@ -355,8 +355,8 @@ void Intro::updateScenes()
bitmaps[5]->setEnabled(false); bitmaps[5]->setEnabled(false);
texts[8]->setEnabled(false); texts[8]->setEnabled(false);
JA_StopMusic(); JA_StopMusic();
section::name = section::NAME_TITLE; section::name = section::Name::TITLE;
section::options = section::OPTIONS_TITLE_1; section::options = section::Options::TITLE_1;
} }
break; break;
@@ -422,7 +422,7 @@ void Intro::run()
{ {
JA_PlayMusic(music, 0); JA_PlayMusic(music, 0);
while (section::name == section::NAME_INTRO) while (section::name == section::Name::INTRO)
{ {
checkInput(); checkInput();
update(); update();

View File

@@ -9,7 +9,7 @@
#include "jail_audio.h" // for JA_StopMusic #include "jail_audio.h" // for JA_StopMusic
#include "param.h" // for param #include "param.h" // for param
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "section.h" // for name, name_e, options, options_e #include "section.h" // for name, SectionName, options, SectionOptions
#include "sprite.h" // for Sprite #include "sprite.h" // for Sprite
#include "texture.h" // for Texture #include "texture.h" // for Texture
@@ -26,7 +26,7 @@ Logo::Logo()
// Inicializa variables // Inicializa variables
counter = 0; counter = 0;
section::name = section::NAME_LOGO; section::name = section::Name::LOGO;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
showSinceSprite_cm = 70; showSinceSprite_cm = 70;
@@ -80,7 +80,7 @@ void Logo::checkEvents()
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
{ {
section::name = section::NAME_QUIT; section::name = section::Name::QUIT;
break; break;
} }
@@ -102,8 +102,8 @@ void Logo::checkInput()
if (Input::get()->checkAnyButtonPressed()) if (Input::get()->checkAnyButtonPressed())
{ {
JA_StopMusic(); JA_StopMusic();
section::name = section::NAME_TITLE; section::name = section::Name::TITLE;
section::options = section::OPTIONS_TITLE_1; section::options = section::Options::TITLE_1;
return; return;
} }
@@ -196,7 +196,7 @@ void Logo::update()
// Comprueba si ha terminado el logo // Comprueba si ha terminado el logo
if (counter == endLogo_cm + postLogoDuration) if (counter == endLogo_cm + postLogoDuration)
{ {
section::name = section::NAME_INTRO; section::name = section::Name::INTRO;
} }
// Comprueba si se ha de mostrar el sprite // Comprueba si se ha de mostrar el sprite
@@ -233,7 +233,7 @@ void Logo::run()
// Detiene la música // Detiene la música
JA_StopMusic(); JA_StopMusic();
while (section::name == section::NAME_LOGO) while (section::name == section::Name::LOGO)
{ {
checkInput(); checkInput();
update(); update();

View File

@@ -92,7 +92,7 @@ void OnScreenHelp::render()
void OnScreenHelp::fillTexture() void OnScreenHelp::fillTexture()
{ {
// Cambia el renderizador a la textura // Cambia el renderizador a la textura
auto *temp = SDL_GetRenderTarget(Screen::get()->getRenderer()); auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture); SDL_SetRenderTarget(Screen::get()->getRenderer(), texture);
// Crea el objeto para el texto // Crea el objeto para el texto

View File

@@ -2,6 +2,6 @@
namespace section namespace section
{ {
name_e name; Name name;
options_e options; Options options;
} }

View File

@@ -3,31 +3,31 @@
namespace section namespace section
{ {
// Secciones del programa // Secciones del programa
enum name_e enum class Name
{ {
NAME_INIT = 0, INIT = 0,
NAME_LOGO = 1, LOGO = 1,
NAME_INTRO = 2, INTRO = 2,
NAME_TITLE = 3, TITLE = 3,
NAME_GAME = 4, GAME = 4,
NAME_HI_SCORE_TABLE = 5, HI_SCORE_TABLE = 5,
NAME_GAME_DEMO = 6, GAME_DEMO = 6,
NAME_INSTRUCTIONS = 7, INSTRUCTIONS = 7,
NAME_QUIT = 8, QUIT = 8,
}; };
// Opciones para la sección // Opciones para la sección
enum options_e enum class Options
{ {
OPTIONS_GAME_PLAY_1P = 0, GAME_PLAY_1P = 0,
OPTIONS_GAME_PLAY_2P = 1, GAME_PLAY_2P = 1,
OPTIONS_TITLE_1 = 2, TITLE_1 = 2,
OPTIONS_TITLE_2 = 3, TITLE_2 = 3,
OPTIONS_QUIT_NORMAL = 4, QUIT_NORMAL = 4,
OPTIONS_QUIT_SHUTDOWN = 5, QUIT_SHUTDOWN = 5,
OPTIONS_NULL = 6, NONE = 6,
}; };
extern name_e name; extern Name name;
extern options_e options; extern Options options;
} }

View File

@@ -5,10 +5,10 @@
#include "texture.h" // for Texture #include "texture.h" // for Texture
#include "utils.h" // for Color #include "utils.h" // for Color
// Llena una estructuta textFile_t desde un fichero // Llena una estructuta TextFile desde un fichero
textFile_t LoadTextFile(std::string file) TextFile LoadTextFile(std::string file_path)
{ {
textFile_t tf; TextFile tf;
// Inicializa a cero el vector con las coordenadas // Inicializa a cero el vector con las coordenadas
for (int i = 0; i < 128; ++i) for (int i = 0; i < 128; ++i)
@@ -19,26 +19,26 @@ textFile_t LoadTextFile(std::string file)
} }
// Abre el fichero para leer los valores // Abre el fichero para leer los valores
const std::string filename = file.substr(file.find_last_of("\\/") + 1).c_str(); const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1).c_str();
std::ifstream rfile(file); std::ifstream file(file_path);
if (rfile.is_open() && rfile.good()) if (file.is_open() && file.good())
{ {
std::string buffer; std::string buffer;
// Lee los dos primeros valores del fichero // Lee los dos primeros valores del fichero
std::getline(rfile, buffer); std::getline(file, buffer);
std::getline(rfile, buffer); std::getline(file, buffer);
tf.boxWidth = std::stoi(buffer); tf.box_width = std::stoi(buffer);
std::getline(rfile, buffer); std::getline(file, buffer);
std::getline(rfile, buffer); std::getline(file, buffer);
tf.boxHeight = std::stoi(buffer); tf.box_height = std::stoi(buffer);
// lee el resto de datos del fichero // lee el resto de datos del fichero
int index = 32; auto index = 32;
int line_read = 0; auto line_read = 0;
while (std::getline(rfile, buffer)) while (std::getline(file, buffer))
{ {
// Almacena solo las lineas impares // Almacena solo las lineas impares
if (line_read % 2 == 1) if (line_read % 2 == 1)
@@ -53,133 +53,133 @@ textFile_t LoadTextFile(std::string file)
// Cierra el fichero // Cierra el fichero
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Text loaded: " << filename.c_str() << std::endl; std::cout << "Text loaded: " << file_name.c_str() << std::endl;
#endif #endif
rfile.close(); file.close();
} }
// El fichero no se puede abrir // El fichero no se puede abrir
else else
{ {
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl;
#endif #endif
} }
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho // Establece las coordenadas para cada caracter ascii de la cadena y su ancho
for (int i = 32; i < 128; ++i) for (int i = 32; i < 128; ++i)
{ {
tf.offset[i].x = ((i - 32) % 15) * tf.boxWidth; tf.offset[i].x = ((i - 32) % 15) * tf.box_width;
tf.offset[i].y = ((i - 32) / 15) * tf.boxHeight; tf.offset[i].y = ((i - 32) / 15) * tf.box_height;
} }
return tf; return tf;
} }
// Constructor // Constructor
Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer) Text::Text(std::string bitmap_file, std::string text_file, SDL_Renderer *renderer)
{ {
// Carga los offsets desde el fichero // Carga los offsets desde el fichero
textFile_t tf = LoadTextFile(textFile); auto tf = LoadTextFile(text_file);
// Inicializa variables desde la estructura // Inicializa variables desde la estructura
boxHeight = tf.boxHeight; box_height_ = tf.box_height;
boxWidth = tf.boxWidth; box_width_ = tf.box_width;
for (int i = 0; i < 128; ++i) for (int i = 0; i < 128; ++i)
{ {
offset[i].x = tf.offset[i].x; offset_[i].x = tf.offset[i].x;
offset[i].y = tf.offset[i].y; offset_[i].y = tf.offset[i].y;
offset[i].w = tf.offset[i].w; offset_[i].w = tf.offset[i].w;
} }
// Crea los objetos // Crea los objetos
texture = std::make_shared<Texture>(renderer, bitmapFile); texture_ = std::make_shared<Texture>(renderer, bitmap_file);
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight}, texture); sprite_ = std::make_unique<Sprite>((SDL_Rect){0, 0, box_width_, box_height_}, texture_);
// Inicializa variables // Inicializa variables
fixedWidth = false; fixed_width_ = false;
} }
// Constructor // Constructor
Text::Text(std::string textFile, std::shared_ptr<Texture> texture) Text::Text(std::string text_file, std::shared_ptr<Texture> texture)
{ {
// Carga los offsets desde el fichero // Carga los offsets desde el fichero
textFile_t tf = LoadTextFile(textFile); auto tf = LoadTextFile(text_file);
// Inicializa variables desde la estructura // Inicializa variables desde la estructura
boxHeight = tf.boxHeight; box_height_ = tf.box_height;
boxWidth = tf.boxWidth; box_width_ = tf.box_width;
for (int i = 0; i < 128; ++i) for (int i = 0; i < 128; ++i)
{ {
offset[i].x = tf.offset[i].x; offset_[i].x = tf.offset[i].x;
offset[i].y = tf.offset[i].y; offset_[i].y = tf.offset[i].y;
offset[i].w = tf.offset[i].w; offset_[i].w = tf.offset[i].w;
} }
// Crea los objetos // Crea los objetos
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight}, texture); sprite_ = std::make_unique<Sprite>((SDL_Rect){0, 0, box_width_, box_height_}, texture);
// Inicializa variables // Inicializa variables
fixedWidth = false; fixed_width_ = false;
} }
// Constructor // Constructor
Text::Text(textFile_t *textFile, std::shared_ptr<Texture> texture) Text::Text(TextFile *text_file, std::shared_ptr<Texture> texture)
{ {
// Inicializa variables desde la estructura // Inicializa variables desde la estructura
boxHeight = textFile->boxHeight; box_height_ = text_file->box_height;
boxWidth = textFile->boxWidth; box_width_ = text_file->box_width;
for (int i = 0; i < 128; ++i) for (int i = 0; i < 128; ++i)
{ {
offset[i].x = textFile->offset[i].x; offset_[i].x = text_file->offset[i].x;
offset[i].y = textFile->offset[i].y; offset_[i].y = text_file->offset[i].y;
offset[i].w = textFile->offset[i].w; offset_[i].w = text_file->offset[i].w;
} }
// Crea los objetos // Crea los objetos
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight}, texture); sprite_ = std::make_unique<Sprite>((SDL_Rect){0, 0, box_width_, box_height_}, texture);
// Inicializa variables // Inicializa variables
fixedWidth = false; fixed_width_ = false;
} }
// Escribe texto en pantalla // Escribe texto en pantalla
void Text::write(int x, int y, std::string text, int kerning, int lenght) void Text::write(int x, int y, std::string text, int kerning, int lenght)
{ {
int shift = 0; auto shift = 0;
if (lenght == -1) if (lenght == -1)
{ {
lenght = text.length(); lenght = text.length();
} }
sprite->setPosY(y); sprite_->setPosY(y);
const int width = sprite->getWidth(); const auto width = sprite_->getWidth();
const int height = sprite->getHeight(); const auto height = sprite_->getHeight();
for (int i = 0; i < lenght; ++i) for (int i = 0; i < lenght; ++i)
{ {
const int index = text[i]; const auto index = static_cast<int>(text[i]);
sprite->setSpriteClip(offset[index].x, offset[index].y, width, height); sprite_->setSpriteClip(offset_[index].x, offset_[index].y, width, height);
sprite->setPosX(x + shift); sprite_->setPosX(x + shift);
sprite->render(); sprite_->render();
shift += fixedWidth ? boxWidth : (offset[int(text[i])].w + kerning); shift += fixed_width_ ? box_width_ : (offset_[int(text[i])].w + kerning);
} }
} }
// Escribe el texto con colores // Escribe el texto con colores
void Text::writeColored(int x, int y, std::string text, Color color, int kerning, int lenght) void Text::writeColored(int x, int y, std::string text, Color color, int kerning, int lenght)
{ {
sprite->getTexture()->setColor(color.r, color.g, color.b); sprite_->getTexture()->setColor(color.r, color.g, color.b);
write(x, y, text, kerning, lenght); write(x, y, text, kerning, lenght);
sprite->getTexture()->setColor(255, 255, 255); sprite_->getTexture()->setColor(255, 255, 255);
} }
// Escribe el texto con sombra // Escribe el texto con sombra
void Text::writeShadowed(int x, int y, std::string text, Color color, Uint8 shadowDistance, int kerning, int lenght) void Text::writeShadowed(int x, int y, std::string text, Color color, Uint8 shadow_distance, int kerning, int lenght)
{ {
sprite->getTexture()->setColor(color.r, color.g, color.b); sprite_->getTexture()->setColor(color.r, color.g, color.b);
write(x + shadowDistance, y + shadowDistance, text, kerning, lenght); write(x + shadow_distance, y + shadow_distance, text, kerning, lenght);
sprite->getTexture()->setColor(255, 255, 255); sprite_->getTexture()->setColor(255, 255, 255);
write(x, y, text, kerning, lenght); write(x, y, text, kerning, lenght);
} }
@@ -191,12 +191,12 @@ void Text::writeCentered(int x, int y, std::string text, int kerning, int lenght
} }
// Escribe texto con extras // Escribe texto con extras
void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Color textColor, Uint8 shadowDistance, Color shadowColor, int lenght) void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght)
{ {
const bool centered = ((flags & TXT_CENTER) == TXT_CENTER); const auto centered = ((flags & TEXT_CENTER) == TEXT_CENTER);
const bool shadowed = ((flags & TXT_SHADOW) == TXT_SHADOW); const auto shadowed = ((flags & TEXT_SHADOW) == TEXT_SHADOW);
const bool colored = ((flags & TXT_COLOR) == TXT_COLOR); const auto colored = ((flags & TEXT_COLOR) == TEXT_COLOR);
const bool stroked = ((flags & TXT_STROKE) == TXT_STROKE); const auto stroked = ((flags & TEXT_STROKE) == TEXT_STROKE);
if (centered) if (centered)
{ {
@@ -205,18 +205,18 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Col
if (shadowed) if (shadowed)
{ {
writeColored(x + shadowDistance, y + shadowDistance, text, shadowColor, kerning, lenght); writeColored(x + shadow_distance, y + shadow_distance, text, shadow_color, kerning, lenght);
} }
if (stroked) if (stroked)
{ {
for (int dist = 1; dist <= shadowDistance; ++dist) for (int dist = 1; dist <= shadow_distance; ++dist)
{ {
for (int dy = -dist; dy <= dist; ++dy) for (int dy = -dist; dy <= dist; ++dy)
{ {
for (int dx = -dist; dx <= dist; ++dx) for (int dx = -dist; dx <= dist; ++dx)
{ {
writeColored(x + dx, y + dy, text, shadowColor, kerning, lenght); writeColored(x + dx, y + dy, text, shadow_color, kerning, lenght);
} }
} }
} }
@@ -233,12 +233,14 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Col
} }
// Obtiene la longitud en pixels de una cadena // Obtiene la longitud en pixels de una cadena
int Text::lenght(std::string text, int kerning) int Text::lenght(std::string text, int kerning) const
{ {
int shift = 0; auto shift = 0;
for (int i = 0; i < (int)text.length(); ++i) for (int i = 0; i < (int)text.length(); ++i)
shift += (offset[int(text[i])].w + kerning); {
shift += (offset_[int(text[i])].w + kerning);
}
// Descuenta el kerning del último caracter // Descuenta el kerning del último caracter
return shift - kerning; return shift - kerning;
@@ -247,29 +249,29 @@ int Text::lenght(std::string text, int kerning)
// Devuelve el valor de la variable // Devuelve el valor de la variable
int Text::getCharacterSize() const int Text::getCharacterSize() const
{ {
return boxWidth; return box_width_;
} }
// Recarga la textura // Recarga la textura
void Text::reLoadTexture() void Text::reLoadTexture()
{ {
sprite->getTexture()->reLoad(); 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)
{ {
fixedWidth = value; fixed_width_ = value;
} }
// Carga una paleta de colores para el texto // Carga una paleta de colores para el texto
void Text::addPalette(std::string path) void Text::addPalette(std::string path)
{ {
texture->addPalette(path); texture_->addPalette(path);
} }
// Establece una paleta de colores para el texto // Establece una paleta de colores para el texto
void Text::setPalette(int index) void Text::setPalette(int index)
{ {
texture->setPalette(index); texture_->setPalette(index);
} }

View File

@@ -8,45 +8,45 @@
#include "sprite.h" #include "sprite.h"
#include "texture.h" #include "texture.h"
#define TXT_COLOR 1 constexpr int TEXT_COLOR = 1;
#define TXT_SHADOW 2 constexpr int TEXT_SHADOW = 2;
#define TXT_CENTER 4 constexpr int TEXT_CENTER = 4;
#define TXT_STROKE 8 constexpr int TEXT_STROKE = 8;
struct offset_t struct TextOffset
{ {
int x, y, w; int x, y, w;
}; };
struct textFile_t struct TextFile
{ {
int boxWidth; // Anchura de la caja de cada caracter en el png int box_width; // Anchura de la caja de cada caracter en el png
int boxHeight; // Altura de la caja de cada caracter en el png int box_height; // Altura de la caja de cada caracter en el png
offset_t offset[128]; // Vector con las posiciones y ancho de cada letra TextOffset offset[128]; // Vector con las posiciones y ancho de cada letra
}; };
// Llena una estructuta textFile_t desde un fichero // Llena una estructuta TextFile desde un fichero
textFile_t LoadTextFile(std::string file); TextFile LoadTextFile(std::string file);
// Clase texto. Pinta texto en pantalla a partir de un bitmap // Clase texto. Pinta texto en pantalla a partir de un bitmap
class Text class Text
{ {
private: private:
// Objetos y punteros // Objetos y punteros
std::unique_ptr<Sprite> sprite; // Objeto con los graficos para el texto std::unique_ptr<Sprite> sprite_; // Objeto con los graficos para el texto
std::shared_ptr<Texture> texture; // Textura con los bitmaps del texto std::shared_ptr<Texture> texture_; // Textura con los bitmaps del texto
// Variables // Variables
int boxWidth; // Anchura de la caja de cada caracter en el png int box_width_; // Anchura de la caja de cada caracter en el png
int boxHeight; // Altura de la caja de cada caracter en el png int box_height_; // Altura de la caja de cada caracter en el png
bool fixedWidth; // Indica si el texto se ha de escribir con longitud fija en todas las letras bool fixed_width_; // Indica si el texto se ha de escribir con longitud fija en todas las letras
offset_t offset[128]; // Vector con las posiciones y ancho de cada letra TextOffset offset_[128]; // Vector con las posiciones y ancho de cada letra
public: public:
// Constructor // Constructor
Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer); Text(std::string bitmap_file, std::string text_file, SDL_Renderer *renderer);
Text(std::string textFile, std::shared_ptr<Texture> texture); Text(std::string text_file, std::shared_ptr<Texture> texture);
Text(textFile_t *textFile, std::shared_ptr<Texture> texture); Text(TextFile *text_file, std::shared_ptr<Texture> texture);
// Destructor // Destructor
~Text() = default; ~Text() = default;
@@ -58,16 +58,16 @@ public:
void writeColored(int x, int y, std::string text, Color color, int kerning = 1, int lenght = -1); void writeColored(int x, int y, std::string text, Color color, int kerning = 1, int lenght = -1);
// Escribe el texto con sombra // Escribe el texto con sombra
void writeShadowed(int x, int y, std::string text, Color color, Uint8 shadowDistance = 1, int kerning = 1, int lenght = -1); void writeShadowed(int x, int y, std::string text, Color color, Uint8 shadow_distance = 1, int kerning = 1, int lenght = -1);
// Escribe el texto centrado en un punto x // Escribe el texto centrado en un punto x
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1); void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
// Escribe texto con extras // Escribe texto con extras
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, Color textColor = {255, 255, 255}, Uint8 shadowDistance = 1, Color shadowColor = {0, 0, 0}, int lenght = -1); void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, Color textColor = {255, 255, 255}, Uint8 shadow_distance = 1, Color shadow_color = {0, 0, 0}, int lenght = -1);
// Obtiene la longitud en pixels de una cadena // Obtiene la longitud en pixels de una cadena
int lenght(std::string text, int kerning = 1); int lenght(std::string text, int kerning = 1) const;
// Devuelve el valor de la variable // Devuelve el valor de la variable
int getCharacterSize() const; int getCharacterSize() const;

View File

@@ -56,7 +56,7 @@ Texture::~Texture()
// Carga una imagen desde un fichero // Carga una imagen desde un fichero
bool Texture::loadFromFile(std::string path) bool Texture::loadFromFile(std::string path)
{ {
const std::string filename = path.substr(path.find_last_of("\\/") + 1); const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
int req_format = STBI_rgb_alpha; int req_format = STBI_rgb_alpha;
int width, height, orig_format; int width, height, orig_format;
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format); unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
@@ -70,7 +70,7 @@ bool Texture::loadFromFile(std::string path)
else else
{ {
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Image loaded: " << filename.c_str() << std::endl; std::cout << "Image loaded: " << file_name.c_str() << std::endl;
#endif #endif
} }
@@ -265,9 +265,9 @@ void Texture::deleteSurface(Surface surface)
} }
// Crea una surface desde un fichero .gif // Crea una surface desde un fichero .gif
Surface Texture::loadSurface(const char *filename) Surface Texture::loadSurface(const char *file_name)
{ {
FILE *f = fopen(filename, "rb"); FILE *f = fopen(file_name, "rb");
if (!f) if (!f)
{ {
return NULL; return NULL;
@@ -303,7 +303,7 @@ Surface Texture::loadSurface(const char *filename)
void Texture::flipSurface() void Texture::flipSurface()
{ {
// Limpia la textura // Limpia la textura
auto *temp = SDL_GetRenderTarget(renderer_); auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, texture_); SDL_SetRenderTarget(renderer_, texture_);
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0); SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer_);
@@ -327,11 +327,11 @@ void Texture::setPaletteColor(int palette, int index, Uint32 color)
} }
// Carga una paleta desde un fichero // Carga una paleta desde un fichero
std::vector<Uint32> Texture::loadPal(const char *filename) std::vector<Uint32> Texture::loadPal(const char *file_name)
{ {
std::vector<Uint32> palette; std::vector<Uint32> palette;
FILE *f = fopen(filename, "rb"); FILE *f = fopen(file_name, "rb");
if (!f) if (!f)
{ {
return palette; return palette;

View File

@@ -39,13 +39,13 @@ private:
void deleteSurface(Surface surface); void deleteSurface(Surface surface);
// Crea una surface desde un fichero .gif // Crea una surface desde un fichero .gif
Surface loadSurface(const char *filename); Surface loadSurface(const char *file_name);
// Vuelca la surface en la textura // Vuelca la surface en la textura
void flipSurface(); void flipSurface();
// Carga una paleta desde un fichero // Carga una paleta desde un fichero
std::vector<Uint32> loadPal(const char *filename); std::vector<Uint32> loadPal(const char *file_name);
public: public:
// Constructor // Constructor

View File

@@ -7,14 +7,14 @@
#include "texture.h" // for Texture #include "texture.h" // for Texture
// Constructor // Constructor
Tiledbg::Tiledbg(std::string texturePath, SDL_Rect pos, int mode) Tiledbg::Tiledbg(std::string texture_path, SDL_Rect pos, int mode)
: texturePath(texturePath), pos(pos), mode(mode) : texture_path_(texture_path), pos_(pos), mode_(mode)
{ {
// Copia los punteros // Copia los punteros
renderer = Screen::get()->getRenderer(); renderer_ = Screen::get()->getRenderer();
// Crea la textura para el mosaico de fondo // Crea la textura para el mosaico de fondo
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, pos.w * 2, pos.h * 2); canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, pos_.w * 2, pos_.h * 2);
// Inicializa las variables // Inicializa las variables
init(); init();
@@ -23,34 +23,34 @@ Tiledbg::Tiledbg(std::string texturePath, SDL_Rect pos, int mode)
// Destructor // Destructor
Tiledbg::~Tiledbg() Tiledbg::~Tiledbg()
{ {
SDL_DestroyTexture(canvas); SDL_DestroyTexture(canvas_);
} }
// Inicializa las variables // Inicializa las variables
void Tiledbg::init() void Tiledbg::init()
{ {
counter = 0; counter_ = 0;
if (mode == TILED_MODE_RANDOM) if (mode_ == TILED_MODE_RANDOM)
{ {
mode = rand() % 2; mode_ = rand() % 2;
} }
tileWidth = 64; tile_width_ = 64;
tileHeight = 64; tile_height_ = 64;
// Rellena la textura con el contenido // Rellena la textura con el contenido
fillTexture(); fillTexture();
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida // Coloca la ventana que recorre el mosaico de fondo de manera que coincida
// con el mosaico que hay pintado en el titulo al iniciar // con el mosaico que hay pintado en el titulo al iniciar
window.x = 128; window_.x = 128;
window.y = 96; window_.y = 96;
window.w = pos.w; window_.w = pos_.w;
window.h = pos.h; window_.h = pos_.h;
// Inicializa los valores del vector con los valores del seno // Inicializa los valores del vector con los valores del seno
for (int i = 0; i < 360; ++i) for (int i = 0; i < 360; ++i)
{ {
sin[i] = SDL_sinf((float)i * 3.14f / 180.0f); sin_[i] = SDL_sinf((float)i * 3.14f / 180.0f);
} }
} }
@@ -58,53 +58,53 @@ void Tiledbg::init()
void Tiledbg::fillTexture() void Tiledbg::fillTexture()
{ {
// Crea los objetos para pintar en la textura de fondo // Crea los objetos para pintar en la textura de fondo
auto bgTileTexture = std::make_shared<Texture>(renderer, texturePath); auto bg_tile_texture = std::make_shared<Texture>(renderer_, texture_path_);
auto tile = std::make_unique<Sprite>((SDL_Rect){0, 0, tileWidth, tileHeight}, bgTileTexture); auto tile = std::make_unique<Sprite>((SDL_Rect){0, 0, tile_width_, tile_height_}, bg_tile_texture);
// Prepara para dibujar sobre la textura // Prepara para dibujar sobre la textura
auto temp = SDL_GetRenderTarget(renderer); auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer, canvas); SDL_SetRenderTarget(renderer_, canvas_);
// Rellena la textura con el tile // Rellena la textura con el tile
const auto iMax = pos.w * 2 / tileWidth; const auto i_max = pos_.w * 2 / tile_width_;
const auto jMax = pos.h * 2 / tileHeight; const auto j_max = pos_.h * 2 / tile_height_;
tile->setSpriteClip(0, 0, tileWidth, tileHeight); tile->setSpriteClip(0, 0, tile_width_, tile_height_);
for (int i = 0; i < iMax; ++i) for (int i = 0; i < i_max; ++i)
{ {
for (int j = 0; j < jMax; ++j) for (int j = 0; j < j_max; ++j)
{ {
tile->setPosX(i * tileWidth); tile->setPosX(i * tile_width_);
tile->setPosY(j * tileHeight); tile->setPosY(j * tile_height_);
tile->render(); tile->render();
} }
} }
// Vuelve a colocar el renderizador como estaba // Vuelve a colocar el renderizador como estaba
SDL_SetRenderTarget(renderer, temp); SDL_SetRenderTarget(renderer_, temp);
// Libera la memoria utilizada por los objetos // Libera la memoria utilizada por los objetos
bgTileTexture->unload(); bg_tile_texture->unload();
} }
// Pinta la clase en pantalla // Pinta la clase en pantalla
void Tiledbg::render() void Tiledbg::render()
{ {
SDL_RenderCopy(renderer, canvas, &window, &pos); SDL_RenderCopy(renderer_, canvas_, &window_, &pos_);
} }
// Actualiza la lógica de la clase // Actualiza la lógica de la clase
void Tiledbg::update() void Tiledbg::update()
{ {
if (mode == TILED_MODE_DIAGONAL) if (mode_ == TILED_MODE_DIAGONAL)
{ // El tileado de fondo se desplaza en diagonal { // El tileado de fondo se desplaza en diagonal
++window.x %= tileWidth; ++window_.x %= tile_width_;
++window.y %= tileHeight; ++window_.y %= tile_height_;
} }
else if (mode == TILED_MODE_CIRCLE) else if (mode_ == TILED_MODE_CIRCLE)
{ // El tileado de fondo se desplaza en circulo { // El tileado de fondo se desplaza en circulo
++counter %= 360; ++counter_ %= 360;
window.x = 128 + (int(sin[(counter + 270) % 360] * 128)); window_.x = 128 + (int(sin_[(counter_ + 270) % 360] * 128));
window.y = 96 + (int(sin[(360 - counter) % 360] * 96)); window_.y = 96 + (int(sin_[(360 - counter_) % 360] * 96));
} }
} }

View File

@@ -1,8 +1,8 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture #include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
#include <string> // for string, basic_string #include <string> // for string, basic_string
// Modos de funcionamiento para el tileado de fondo // Modos de funcionamiento para el tileado de fondo
#define TILED_MODE_CIRCLE 0 #define TILED_MODE_CIRCLE 0
@@ -21,18 +21,18 @@ class Tiledbg
{ {
private: private:
// Objetos y punteros // Objetos y punteros
SDL_Renderer *renderer; // El renderizador de la ventana SDL_Renderer *renderer_; // El renderizador de la ventana
SDL_Rect window; // Ventana visible para la textura de fondo del titulo SDL_Rect window_; // Ventana visible para la textura de fondo del titulo
SDL_Texture *canvas; // Textura donde dibujar el fondo formado por tiles SDL_Texture *canvas_; // Textura donde dibujar el fondo formado por tiles
// Variables // Variables
std::string texturePath; // Fichero para usar en la textura std::string texture_path_; // Fichero para usar en la textura
SDL_Rect pos; // Posición y tamaña del mosaico SDL_Rect pos_; // Posición y tamaña del mosaico
int counter; // Contador int counter_; // Contador
int mode; // Tipo de movimiento del mosaico int mode_; // Tipo de movimiento del mosaico
float sin[360]; // Vector con los valores del seno precalculados float sin_[360]; // Vector con los valores del seno precalculados
int tileWidth; // Ancho del tile int tile_width_; // Ancho del tile
int tileHeight; // Alto del tile int tile_height_; // Alto del tile
// Inicializa las variables // Inicializa las variables
void init(); void init();
@@ -42,7 +42,7 @@ private:
public: public:
// Constructor // Constructor
Tiledbg(std::string texturePath, SDL_Rect pos, int mode); Tiledbg(std::string texture_path, SDL_Rect pos, int mode);
// Destructor // Destructor
~Tiledbg(); ~Tiledbg();

View File

@@ -12,38 +12,36 @@
#include "options.h" // for options #include "options.h" // for options
#include "param.h" // for param #include "param.h" // for param
#include "screen.h" // for Screen #include "screen.h" // for Screen
#include "section.h" // for options_e, options, name_e, name #include "section.h" // for SectionOptions, options, SectionName, name
struct JA_Music_t; struct JA_Music_t;
// Constructor // Constructor
Title::Title(JA_Music_t *music) Title::Title(JA_Music_t *music)
: music(music) : music_(music)
{ {
// Copia las direcciones de los punteros y objetos // Copia las direcciones de los punteros y objetos
input = Input::get(); input_ = Input::get();
asset = Asset::get(); screen_ = Screen::get();
screen = Screen::get(); SDL_Renderer *renderer = screen_->getRenderer();
SDL_Renderer *renderer = screen->getRenderer();
// Reserva memoria y crea los objetos // Reserva memoria y crea los objetos
eventHandler = std::make_unique<SDL_Event>(); fade_ = std::make_unique<Fade>(renderer);
fade = std::make_unique<Fade>(renderer);
text1 = std::make_unique<Text>(asset->get("smb2.gif"), asset->get("smb2.txt"), renderer); text1_ = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer);
text1->addPalette(asset->get("smb2_pal1.gif")); text1_->addPalette(Asset::get()->get("smb2_pal1.gif"));
text1->setPalette(1); text1_->setPalette(1);
text2 = std::make_unique<Text>(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer); text2_ = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer);
miniLogoTexture = std::make_shared<Texture>(renderer, asset->get("logo_jailgames_mini.png")); mini_logo_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames_mini.png"));
miniLogoSprite = std::make_unique<Sprite>(param.game.game_area.center_x - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture); mini_logo_sprite_ = std::make_unique<Sprite>(param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight(), mini_logo_texture_);
tiledbg = std::make_unique<Tiledbg>(asset->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM); tiled_bg_ = std::make_unique<Tiledbg>(Asset::get()->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM);
gameLogo = std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position); game_logo_ = std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position);
gameLogo->enable(); game_logo_->enable();
defineButtons = std::make_unique<DefineButtons>(std::move(text2)); define_buttons_ = std::make_unique<DefineButtons>(std::move(text2_));
// Inicializa los valores // Inicializa los valores
init(); init();
@@ -53,79 +51,79 @@ Title::Title(JA_Music_t *music)
void Title::init() void Title::init()
{ {
// Inicializa variables // Inicializa variables
section::options = section::OPTIONS_TITLE_1; section::options = section::Options::TITLE_1;
counter = 0; counter_ = 0;
nextSection.name = section::NAME_GAME; next_section_ = section::Name::GAME;
postFade = 0; post_fade_ = 0;
ticks = 0; ticks_ = 0;
ticksSpeed = 15; ticks_speed_ = 15;
fade->setColor(fade_color.r, fade_color.g, fade_color.b); fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
fade->setType(FadeType::RANDOM_SQUARE); fade_->setType(FadeType::RANDOM_SQUARE);
fade->setPost(param.fade.post_duration); fade_->setPost(param.fade.post_duration);
demo = true; demo_ = true;
numControllers = input->getNumControllers(); num_controllers_ = input_->getNumControllers();
} }
// Actualiza las variables del objeto // Actualiza las variables del objeto
void Title::update() void Title::update()
{ {
// Calcula la lógica de los objetos // Calcula la lógica de los objetos
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks_ > ticks_speed_)
{ {
// Actualiza el contador de ticks // Actualiza el contador de ticks_
ticks = SDL_GetTicks(); ticks_ = SDL_GetTicks();
// Actualiza el objeto screen // Actualiza el objeto screen
screen->update(); screen_->update();
// Comprueba el fade y si se ha acabado // Comprueba el fade_ y si se ha acabado
fade->update(); fade_->update();
if (fade->hasEnded()) if (fade_->hasEnded())
{ {
if (postFade == -1) if (post_fade_ == -1)
{ {
section::name = section::NAME_GAME_DEMO; section::name = section::Name::GAME_DEMO;
} }
else else
{ {
section::name = section::NAME_GAME; section::name = section::Name::GAME;
section::options = postFade == 1 ? section::OPTIONS_GAME_PLAY_1P : section::OPTIONS_GAME_PLAY_2P; section::options = post_fade_ == 1 ? section::Options::GAME_PLAY_1P : section::Options::GAME_PLAY_2P;
JA_StopMusic(); JA_StopMusic();
} }
} }
// Sección 1 - Titulo animandose // Sección 1 - Titulo animandose
if (section::options == section::OPTIONS_TITLE_1) if (section::options == section::Options::TITLE_1)
{ {
gameLogo->update(); game_logo_->update();
if (gameLogo->hasFinished()) if (game_logo_->hasFinished())
{ {
section::options = section::OPTIONS_TITLE_2; section::options = section::Options::TITLE_2;
} }
} }
// Sección 2 - La pantalla con el titulo, el fondo animado y la música // Sección 2 - La pantalla con el titulo, el fondo animado y la música
else if (section::options == section::OPTIONS_TITLE_2) else if (section::options == section::Options::TITLE_2)
{ {
// El contador solo sube si no estamos definiendo botones // El contador solo sube si no estamos definiendo botones
counter = defineButtons->isEnabled() ? 0 : counter + 1; counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1;
// Reproduce la música // Reproduce la música
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{ {
JA_PlayMusic(music); JA_PlayMusic(music_);
} }
// Actualiza el logo con el título del juego // Actualiza el logo con el título del juego
gameLogo->update(); game_logo_->update();
// Actualiza el mosaico de fondo // Actualiza el mosaico de fondo
tiledbg->update(); tiled_bg_->update();
if (counter == param.title.title_duration) if (counter_ == param.title.title_duration)
{ {
fade->activate(); fade_->activate();
postFade = -1; post_fade_ = -1;
} }
} }
} }
@@ -135,83 +133,84 @@ void Title::update()
void Title::render() void Title::render()
{ {
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
screen->start(); screen_->start();
// Limpia la pantalla // Limpia la pantalla
screen->clean(bg_color); screen_->clean(bg_color);
// Dibuja el mosacico de fondo // Dibuja el mosacico de fondo
tiledbg->render(); tiled_bg_->render();
// Dibuja el logo con el título del juego // Dibuja el logo con el título del juego
gameLogo->render(); game_logo_->render();
if (section::options == section::OPTIONS_TITLE_2) if (section::options == section::Options::TITLE_2)
{ {
constexpr Color shadow = {0x14, 0x87, 0xc4}; constexpr Color shadow = {0x14, 0x87, 0xc4};
// 'PRESS TO PLAY' // 'PRESS TO PLAY'
if (counter % 50 > 14 && !defineButtons->isEnabled()) if (counter_ % 50 > 14 && !define_buttons_->isEnabled())
{ {
text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow); text1_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow);
} }
// Mini logo // Mini logo
const int pos1 = (param.game.height / 5 * 4) + BLOCK; const int pos1 = (param.game.height / 5 * 4) + BLOCK;
const int pos2 = pos1 + miniLogoSprite->getHeight() + 3; const int pos2 = pos1 + mini_logo_sprite_->getHeight() + 3;
miniLogoSprite->setPosY(pos1); mini_logo_sprite_->setPosY(pos1);
miniLogoSprite->render(); mini_logo_sprite_->render();
// Texto con el copyright // Texto con el copyright
text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, no_color, 1, shadow); text1_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, no_color, 1, shadow);
} }
// Define Buttons // Define Buttons
defineButtons->render(); define_buttons_->render();
// Fade // Fade
fade->render(); fade_->render();
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen->blit(); screen_->blit();
} }
// Comprueba los eventos // Comprueba los eventos
void Title::checkEvents() void Title::checkEvents()
{ {
// Si defineButtons está habilitado, es él quien gestiona los eventos // Si define_buttons_ está habilitado, es él quien gestiona los eventos
if (!defineButtons->isEnabled()) if (!define_buttons_->isEnabled())
{ {
SDL_Event event;
// Comprueba los eventos que hay en la cola // Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler.get()) != 0) while (SDL_PollEvent(&event))
{ {
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT) if (event.type == SDL_QUIT)
{ {
section::name = section::NAME_QUIT; section::name = section::Name::QUIT;
break; break;
} }
// Recarga las texturas // Recarga las texturas
else if (eventHandler->type == SDL_RENDER_DEVICE_RESET || eventHandler->type == SDL_RENDER_TARGETS_RESET) else if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET)
{ {
reLoadTextures(); reLoadTextures();
} }
else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) else if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
{ {
switch (eventHandler->key.keysym.sym) switch (event.key.keysym.sym)
{ {
case SDLK_1: case SDLK_1:
{ {
if (defineButtons->enable(0)) if (define_buttons_->enable(0))
resetCounter(); resetCounter();
break; break;
} }
case SDLK_2: case SDLK_2:
{ {
if (defineButtons->enable(1)) if (define_buttons_->enable(1))
resetCounter(); resetCounter();
break; break;
} }
@@ -234,45 +233,45 @@ void Title::checkEvents()
void Title::checkInput() void Title::checkInput()
{ {
// Comprueba los controladores solo si no se estan definiendo los botones // Comprueba los controladores solo si no se estan definiendo los botones
if (!defineButtons->isEnabled()) if (!define_buttons_->isEnabled())
{ {
// Comprueba el teclado para empezar a jugar // Comprueba el teclado para empezar a jugar
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) if (input_->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{ {
if (section::options == section::OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP) if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
{ {
fade->activate(); fade_->activate();
postFade = options.controller[0].player_id; post_fade_ = options.controller[0].player_id;
} }
} }
// Comprueba los mandos // Comprueba los mandos
for (int i = 0; i < input->getNumControllers(); ++i) for (int i = 0; i < input_->getNumControllers(); ++i)
{ {
// Comprueba si se va a intercambiar la asignación de mandos a jugadores // Comprueba si se va a intercambiar la asignación de mandos a jugadores
if (input->checkModInput(input_service, input_swap_controllers, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) if (input_->checkModInput(input_service, input_swap_controllers, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{ {
swapControllers(); swapControllers();
return; return;
} }
// Comprueba si algun mando quiere ser configurado // Comprueba si algun mando quiere ser configurado
if (input->checkModInput(input_service, input_config, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) if (input_->checkModInput(input_service, input_config, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{ {
defineButtons->enable(i); define_buttons_->enable(i);
return; return;
} }
// Comprueba el botón de START de los mandos // Comprueba el botón de START de los mandos
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) if (input_->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{ {
// Si no está el botón de servicio activo // Si no está el botón de servicio activo
if (!input->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) if (!input_->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{ {
if (section::options == section::OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP) if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
{ {
fade->activate(); fade_->activate();
postFade = options.controller[i].player_id; post_fade_ = options.controller[i].player_id;
return; return;
} }
} }
@@ -281,8 +280,8 @@ void Title::checkInput()
} }
// Comprueba el input para el resto de objetos // Comprueba el input para el resto de objetos
screen->checkInput(); screen_->checkInput();
defineButtons->checkInput(); define_buttons_->checkInput();
// Comprueba los inputs que se pueden introducir en cualquier sección del juego // Comprueba los inputs que se pueden introducir en cualquier sección del juego
globalInputs::check(); globalInputs::check();
@@ -291,7 +290,7 @@ void Title::checkInput()
// Bucle para el titulo del juego // Bucle para el titulo del juego
void Title::run() void Title::run()
{ {
while (section::name == section::NAME_TITLE) while (section::name == section::Name::TITLE)
{ {
checkInput(); checkInput();
update(); update();
@@ -303,27 +302,27 @@ void Title::run()
// Recarga las texturas // Recarga las texturas
void Title::reLoadTextures() void Title::reLoadTextures()
{ {
gameLogo->reLoad(); game_logo_->reLoad();
tiledbg->reLoad(); tiled_bg_->reLoad();
} }
// Reinicia el contador interno // Reinicia el contador interno
void Title::resetCounter() void Title::resetCounter()
{ {
counter = 0; counter_ = 0;
} }
// Intercambia la asignación de mandos a los jugadores // Intercambia la asignación de mandos a los jugadores
void Title::swapControllers() void Title::swapControllers()
{ {
const int numControllers = input->getNumControllers(); const int num_controllers_ = input_->getNumControllers();
if (numControllers == 0) if (num_controllers_ == 0)
{ {
return; return;
} }
defineButtons->swapControllers(); define_buttons_->swapControllers();
// Crea cadenas de texto vacias para un numero máximo de mandos // Crea cadenas de texto vacias para un numero máximo de mandos
constexpr int MAX_CONTROLLERS = 2; constexpr int MAX_CONTROLLERS = 2;
@@ -351,7 +350,7 @@ void Title::swapControllers()
} }
} }
screen->showNotification(text[0], text[1]); screen_->showNotification(text[0], text[1]);
resetCounter(); resetCounter();
} }

View File

@@ -11,6 +11,7 @@
#include "utils.h" // for Section #include "utils.h" // for Section
#include "sprite.h" #include "sprite.h"
#include "texture.h" #include "texture.h"
#include "section.h"
class Asset; class Asset;
class Input; class Input;
@@ -45,30 +46,28 @@ class Title
{ {
private: private:
// Objetos y punteros // Objetos y punteros
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen_; // Objeto encargado de dibujar en pantalla
Asset *asset; // Objeto que gestiona todos los ficheros de recursos Input *input_; // Objeto para leer las entradas de teclado o mando
Input *input; // Objeto para leer las entradas de teclado o mando std::unique_ptr<Tiledbg> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
std::unique_ptr<SDL_Event> eventHandler; // Manejador de eventos std::unique_ptr<GameLogo> game_logo_; // Objeto para dibujar el logo con el título del juego
std::unique_ptr<Tiledbg> tiledbg; // Objeto para dibujar el mosaico animado de fondo std::unique_ptr<DefineButtons> define_buttons_; // Objeto para definir los botones del joystic
std::unique_ptr<GameLogo> gameLogo; // Objeto para dibujar el logo con el título del juego std::shared_ptr<Texture> mini_logo_texture_; // Textura con el logo de JailGames mini
std::unique_ptr<DefineButtons> defineButtons; // Objeto para definir los botones del joystic std::unique_ptr<Sprite> mini_logo_sprite_; // Sprite con el logo de JailGames mini
std::shared_ptr<Texture> miniLogoTexture; // Textura con el logo de JailGames mini
std::unique_ptr<Sprite> miniLogoSprite; // Sprite con el logo de JailGames mini
std::unique_ptr<Text> text1; // Objeto de texto para poder escribir textos en pantalla std::unique_ptr<Text> text1_; // Objeto de texto para poder escribir textos en pantalla
std::unique_ptr<Text> text2; // Objeto de texto para poder escribir textos en pantalla std::unique_ptr<Text> text2_; // Objeto de texto para poder escribir textos en pantalla
std::unique_ptr<Fade> fade; // Objeto para realizar fundidos en pantalla std::unique_ptr<Fade> fade_; // Objeto para realizar fundidos en pantalla
JA_Music_t *music; // Musica para el titulo JA_Music_t *music_; // Musica para el titulo
// Variable // Variable
int counter; // Temporizador para la pantalla de titulo int counter_; // Temporizador para la pantalla de titulo
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
bool demo; // Indica si el modo demo estará activo Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
Section nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo bool demo_; // Indica si el modo demo estará activo
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa section::Name next_section_; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
int postFade; // Opción a realizar cuando termina el fundido int post_fade_; // Opción a realizar cuando termina el fundido
int numControllers; // Número de mandos conectados int num_controllers_; // Número de mandos conectados
// Inicializa los valores de las variables // Inicializa los valores de las variables
void init(); void init();

View File

@@ -47,11 +47,11 @@ enum class NotifyPosition
}; };
// Estructura para saber la seccion y subseccion del programa // Estructura para saber la seccion y subseccion del programa
struct Section /*struct Section
{ {
Uint8 name; section::Name name;
Uint8 options; section::Options options;
}; };*/
// Estructura para las entradas de la tabla de recirds // Estructura para las entradas de la tabla de recirds
struct HiScoreEntry struct HiScoreEntry

View File

@@ -5,17 +5,17 @@ Writer::Writer(std::shared_ptr<Text> text)
: text_(text) : text_(text)
{ {
// Inicializa variables // Inicializa variables
posX_ = 0; pos_x_ = 0;
posY_ = 0; pos_y_ = 0;
kerning_ = 0; kerning_ = 0;
caption_ = ""; caption_ = "";
speed_ = 0; speed_ = 0;
writingCounter_ = 0; writing_counter_ = 0;
index_ = 0; index_ = 0;
lenght_ = 0; lenght_ = 0;
completed_ = false; completed_ = false;
enabled_ = false; enabled_ = false;
enabledCounter_ = 0; enabled_counter_ = 0;
finished_ = false; finished_ = false;
} }
@@ -27,15 +27,14 @@ void Writer::update()
if (!completed_) if (!completed_)
{ {
// No completado // No completado
if (writingCounter_ > 0) if (writing_counter_ > 0)
{ {
writingCounter_--; writing_counter_--;
} }
else
else if (writingCounter_ == 0)
{ {
index_++; index_++;
writingCounter_ = speed_; writing_counter_ = speed_;
} }
if (index_ == lenght_) if (index_ == lenght_)
@@ -43,18 +42,10 @@ void Writer::update()
completed_ = true; completed_ = true;
} }
} }
else else
{ {
// Completado // Completado
if (enabledCounter_ > 0) enabled_counter_ > 0 ? enabled_counter_-- : finished_ = true;
{
enabledCounter_--;
}
else if (enabledCounter_ == 0)
{
finished_ = true;
}
} }
} }
} }
@@ -64,20 +55,20 @@ void Writer::render() const
{ {
if (enabled_) if (enabled_)
{ {
text_->write(posX_, posY_, caption_, kerning_, index_); text_->write(pos_x_, pos_y_, caption_, kerning_, index_);
} }
} }
// Establece el valor de la variable // Establece el valor de la variable
void Writer::setPosX(int value) void Writer::setPosX(int value)
{ {
posX_ = value; pos_x_ = value;
} }
// Establece el valor de la variable // Establece el valor de la variable
void Writer::setPosY(int value) void Writer::setPosY(int value)
{ {
posY_ = value; pos_y_ = value;
} }
// Establece el valor de la variable // Establece el valor de la variable
@@ -97,7 +88,7 @@ void Writer::setCaption(std::string text)
void Writer::setSpeed(int value) void Writer::setSpeed(int value)
{ {
speed_ = value; speed_ = value;
writingCounter_ = value; writing_counter_ = value;
} }
// Establece el valor de la variable // Establece el valor de la variable
@@ -115,7 +106,7 @@ bool Writer::IsEnabled() const
// Establece el valor de la variable // Establece el valor de la variable
void Writer::setFinishedCounter(int time) void Writer::setFinishedCounter(int time)
{ {
enabledCounter_ = time; enabled_counter_ = time;
} }
// Centra la cadena de texto a un punto X // Centra la cadena de texto a un punto X

View File

@@ -12,17 +12,17 @@ private:
std::shared_ptr<Text> text_; // Objeto encargado de escribir el texto std::shared_ptr<Text> text_; // Objeto encargado de escribir el texto
// Variables // Variables
int posX_; // Posicion en el eje X donde empezar a escribir el texto int pos_x_; // Posicion en el eje X donde empezar a escribir el texto
int posY_; // Posicion en el eje Y donde empezar a escribir el texto int pos_y_; // Posicion en el eje Y donde empezar a escribir el texto
int kerning_; // Kerning del texto, es decir, espaciado entre caracteres int kerning_; // Kerning del texto, es decir, espaciado entre caracteres
std::string caption_; // El texto para escribir std::string caption_; // El texto para escribir
int speed_; // Velocidad de escritura int speed_; // Velocidad de escritura
int writingCounter_; // Temporizador de escritura para cada caracter int writing_counter_; // Temporizador de escritura para cada caracter
int index_; // Posición del texto que se está escribiendo int index_; // Posición del texto que se está escribiendo
int lenght_; // Longitud de la cadena a escribir int lenght_; // Longitud de la cadena a escribir
bool completed_; // Indica si se ha escrito todo el texto bool completed_; // Indica si se ha escrito todo el texto
bool enabled_; // Indica si el objeto está habilitado bool enabled_; // Indica si el objeto está habilitado
int enabledCounter_; // Temporizador para deshabilitar el objeto int enabled_counter_; // Temporizador para deshabilitar el objeto
bool finished_; // Indica si ya ha terminado bool finished_; // Indica si ya ha terminado
public: public: