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:
@@ -95,7 +95,7 @@ bool Asset::check() const
|
||||
if (any)
|
||||
{
|
||||
#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
|
||||
|
||||
for (auto f : file_list_)
|
||||
@@ -146,43 +146,43 @@ bool Asset::checkFile(std::string path) const
|
||||
}
|
||||
|
||||
// Devuelve el nombre del tipo de recurso
|
||||
std::string Asset::getTypeName(int type) const
|
||||
std::string Asset::getTypeName(AssetType type) const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case static_cast<int>(AssetType::BITMAP):
|
||||
case AssetType::BITMAP:
|
||||
return "BITMAP";
|
||||
break;
|
||||
|
||||
case static_cast<int>(AssetType::MUSIC):
|
||||
case AssetType::MUSIC:
|
||||
return "MUSIC";
|
||||
break;
|
||||
|
||||
case static_cast<int>(AssetType::SOUND):
|
||||
case AssetType::SOUND:
|
||||
return "SOUND";
|
||||
break;
|
||||
|
||||
case static_cast<int>(AssetType::FONT):
|
||||
case AssetType::FONT:
|
||||
return "FONT";
|
||||
break;
|
||||
|
||||
case static_cast<int>(AssetType::LANG):
|
||||
case AssetType::LANG:
|
||||
return "LANG";
|
||||
break;
|
||||
|
||||
case static_cast<int>(AssetType::DATA):
|
||||
case AssetType::DATA:
|
||||
return "DATA";
|
||||
break;
|
||||
|
||||
case static_cast<int>(AssetType::ANIMATION):
|
||||
case AssetType::ANIMATION:
|
||||
return "ANIMATION";
|
||||
break;
|
||||
|
||||
case static_cast<int>(AssetType::PALETTE):
|
||||
case AssetType::PALETTE:
|
||||
return "PALETTE";
|
||||
break;
|
||||
|
||||
case static_cast<int>(AssetType::ITEM):
|
||||
case AssetType::ITEM:
|
||||
return "ITEM";
|
||||
break;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
|
||||
enum class AssetType
|
||||
enum class AssetType : int
|
||||
{
|
||||
BITMAP,
|
||||
MUSIC,
|
||||
@@ -42,7 +42,7 @@ private:
|
||||
bool checkFile(std::string executable_path) const;
|
||||
|
||||
// Devuelve el nombre del tipo de recurso
|
||||
std::string getTypeName(int type) const;
|
||||
std::string getTypeName(AssetType type) const;
|
||||
|
||||
// Constructor
|
||||
Asset(std::string path);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "lang.h" // for getText
|
||||
#include "options.h" // for options
|
||||
#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 "utils.h" // for OptionsController, Options, Param, ParamGame
|
||||
|
||||
@@ -103,8 +103,8 @@ void DefineButtons::checkInput()
|
||||
{
|
||||
case SDL_QUIT:
|
||||
{
|
||||
section::name = section::NAME_QUIT;
|
||||
section::options = section::OPTIONS_QUIT_NORMAL;
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = section::Options::QUIT_NORMAL;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "options.h" // for options, loadOptionsFile, saveO...
|
||||
#include "param.h" // for param, loadParamsFromFile
|
||||
#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 "utils.h" // for MusicFile, SoundFile, opt...
|
||||
#include <memory>
|
||||
@@ -44,12 +44,12 @@
|
||||
Director::Director(int argc, char *argv[])
|
||||
{
|
||||
#ifdef RECORDING
|
||||
section::name = section::NAME_GAME;
|
||||
section::options = section::OPTIONS_GAME_PLAY_1P;
|
||||
section::name = section::Name::GAME;
|
||||
section::options = section::Options::GAME_PLAY_1P;
|
||||
#elif DEBUG
|
||||
section::name = section::NAME_LOGO;
|
||||
section::name = section::Name::LOGO;
|
||||
#else
|
||||
section::name = section::NAME_LOGO;
|
||||
section::name = section::Name::LOGO;
|
||||
#endif
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
@@ -631,7 +631,7 @@ void Director::runTitle()
|
||||
// Ejecuta la sección donde se juega al juego
|
||||
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;
|
||||
auto game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, getMusic(musics_, "playing.ogg"));
|
||||
game->run();
|
||||
@@ -667,39 +667,39 @@ void Director::runDemoGame()
|
||||
int Director::run()
|
||||
{
|
||||
// Bucle principal
|
||||
while (section::name != section::NAME_QUIT)
|
||||
while (section::name != section::Name::QUIT)
|
||||
{
|
||||
switch (section::name)
|
||||
{
|
||||
case section::NAME_INIT:
|
||||
section::name = section::NAME_LOGO;
|
||||
case section::Name::INIT:
|
||||
section::name = section::Name::LOGO;
|
||||
break;
|
||||
|
||||
case section::NAME_LOGO:
|
||||
case section::Name::LOGO:
|
||||
runLogo();
|
||||
break;
|
||||
|
||||
case section::NAME_INTRO:
|
||||
case section::Name::INTRO:
|
||||
runIntro();
|
||||
break;
|
||||
|
||||
case section::NAME_TITLE:
|
||||
case section::Name::TITLE:
|
||||
runTitle();
|
||||
break;
|
||||
|
||||
case section::NAME_GAME:
|
||||
case section::Name::GAME:
|
||||
runGame();
|
||||
break;
|
||||
|
||||
case section::NAME_HI_SCORE_TABLE:
|
||||
case section::Name::HI_SCORE_TABLE:
|
||||
runHiScoreTable();
|
||||
break;
|
||||
|
||||
case section::NAME_GAME_DEMO:
|
||||
case section::Name::GAME_DEMO:
|
||||
runDemoGame();
|
||||
break;
|
||||
|
||||
case section::NAME_INSTRUCTIONS:
|
||||
case section::Name::INSTRUCTIONS:
|
||||
runInstructions();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ void Fade::update()
|
||||
if (counter_ % fade_random_squares_delay_ == 0)
|
||||
{
|
||||
// Dibuja sobre el backbuffer_
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||
|
||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_NONE);
|
||||
@@ -154,7 +154,7 @@ void Fade::update()
|
||||
if (square_.back().h < param.fade.venetian_size)
|
||||
{
|
||||
// Dibuja sobre el backbuffer_
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, a_);
|
||||
@@ -299,9 +299,9 @@ bool Fade::hasEnded() const
|
||||
}
|
||||
|
||||
// Establece el tipo de fade
|
||||
void Fade::setType(FadeType type_)
|
||||
void Fade::setType(FadeType type)
|
||||
{
|
||||
type_ = type_;
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
// Establece el modo de fade
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <vector> // for vector
|
||||
|
||||
// Tipos de fundido
|
||||
enum class FadeType
|
||||
enum class FadeType : Uint8
|
||||
{
|
||||
FULLSCREEN = 0,
|
||||
CENTER = 1,
|
||||
@@ -15,7 +15,7 @@ enum class FadeType
|
||||
};
|
||||
|
||||
// Modos de fundido
|
||||
enum class FadeMode
|
||||
enum class FadeMode : Uint8
|
||||
{
|
||||
IN = 0,
|
||||
OUT = 1,
|
||||
@@ -26,25 +26,25 @@ class Fade
|
||||
{
|
||||
private:
|
||||
// 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
|
||||
|
||||
// Variables
|
||||
FadeType type_; // Tipo de fade a realizar
|
||||
FadeMode mode_; // Modo de fade a realizar
|
||||
Uint16 counter_; // Contador interno
|
||||
bool enabled_; // Indica si el fade está activo
|
||||
bool finished_; // Indica si ha terminado la transición
|
||||
Uint8 r_, g_, b_, a_; // Colores para el fade
|
||||
SDL_Rect rect1_; // 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_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
|
||||
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 post_duration_; // Duración posterior del fade tras finalizar
|
||||
int post_counter_; // Contador para la duración posterior
|
||||
FadeType type_; // Tipo de fade a realizar
|
||||
FadeMode mode_; // Modo de fade a realizar
|
||||
Uint16 counter_; // Contador interno
|
||||
bool enabled_; // Indica si el fade está activo
|
||||
bool finished_; // Indica si ha terminado la transición
|
||||
Uint8 r_, g_, b_, a_; // Colores para el fade
|
||||
SDL_Rect rect1_; // 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_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
|
||||
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 post_duration_; // Duración posterior del fade tras finalizar
|
||||
int post_counter_; // Contador para la duración posterior
|
||||
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "scoreboard.h" // for Scoreboard, scoreboard_modes_e
|
||||
#include "screen.h" // for Screen
|
||||
#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 "dbgtxt.h"
|
||||
struct JA_Music_t;
|
||||
@@ -197,8 +197,8 @@ void Game::init(int playerID)
|
||||
paused = false;
|
||||
gameCompleted = false;
|
||||
gameCompletedCounter = 0;
|
||||
section::name = section::NAME_GAME;
|
||||
section::options = section::OPTIONS_GAME_PLAY_1P;
|
||||
section::name = section::Name::GAME;
|
||||
section::options = section::Options::GAME_PLAY_1P;
|
||||
currentPower = 0;
|
||||
menaceCurrent = 0;
|
||||
menaceThreshold = 0;
|
||||
@@ -883,7 +883,7 @@ void Game::updateGameOver()
|
||||
|
||||
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
|
||||
if (fade->hasEnded())
|
||||
{
|
||||
section::name = section::NAME_HI_SCORE_TABLE;
|
||||
section::name = section::Name::HI_SCORE_TABLE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1772,7 +1772,7 @@ void Game::update()
|
||||
// Si se ha llenado el vector con datos, sale del programa
|
||||
else
|
||||
{
|
||||
section::name = section::NAME_QUIT;
|
||||
section::name = section::Name::QUIT;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -2019,7 +2019,7 @@ void Game::checkInput()
|
||||
// Si se pulsa cualquier tecla, se sale del modo demo
|
||||
if (input->checkAnyButtonPressed())
|
||||
{
|
||||
section::name = section::NAME_TITLE;
|
||||
section::name = section::Name::TITLE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2214,7 +2214,7 @@ void Game::renderMessages()
|
||||
{
|
||||
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)
|
||||
@@ -2250,13 +2250,13 @@ void Game::renderMessages()
|
||||
|
||||
if (!gameCompleted)
|
||||
{ // 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
|
||||
{ // Escribe el texto de juego completado
|
||||
text = lang::getText(50);
|
||||
textNokiaBig2->writeDX(TXT_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);
|
||||
textNokiaBig2->writeDX(TEXT_CENTER, param.game.play_area.center_x, stageBitmapPath[stageBitmapCounter], text, -2, 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
|
||||
void Game::run()
|
||||
{
|
||||
while (section::name == section::NAME_GAME)
|
||||
while (section::name == section::Name::GAME)
|
||||
{
|
||||
#ifndef RECORDING
|
||||
checkInput();
|
||||
@@ -2419,8 +2419,8 @@ void Game::updateGameCompleted()
|
||||
|
||||
if (gameCompletedCounter == GAME_COMPLETED_END)
|
||||
{
|
||||
section::name = section::NAME_TITLE;
|
||||
section::options = section::OPTIONS_TITLE_1;
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2487,7 +2487,7 @@ void Game::checkEvents()
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::NAME_QUIT;
|
||||
section::name = section::Name::QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "section.h" // for options_e
|
||||
#include "section.h" // for SectionOptions
|
||||
#include "utils.h" // for DemoKeys, Color, HiScoreEntry
|
||||
#include <memory>
|
||||
#include "asset.h" // lines 11-11
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "options.h" // for options
|
||||
#include "on_screen_help.h"
|
||||
#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
|
||||
|
||||
namespace globalInputs
|
||||
@@ -26,11 +26,11 @@ namespace globalInputs
|
||||
}
|
||||
|
||||
// Termina
|
||||
void quit(section::options_e code)
|
||||
void quit(section::Options code)
|
||||
{
|
||||
if (Screen::get()->notificationsAreActive())
|
||||
{
|
||||
section::name = section::NAME_QUIT;
|
||||
section::name = section::Name::QUIT;
|
||||
section::options = code;
|
||||
}
|
||||
else
|
||||
@@ -42,7 +42,7 @@ namespace globalInputs
|
||||
// Reinicia
|
||||
void reset()
|
||||
{
|
||||
section::name = section::NAME_INIT;
|
||||
section::name = section::Name::INIT;
|
||||
Screen::get()->showNotification("Reset");
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace globalInputs
|
||||
// Comprueba si se sale con el teclado
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace globalInputs
|
||||
// Comprueba si se sale con el mando
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "options.h" // for options
|
||||
#include "param.h" // for param
|
||||
#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
|
||||
|
||||
// Constructor
|
||||
@@ -35,7 +35,7 @@ HiScoreTable::HiScoreTable(JA_Music_t *music)
|
||||
SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Inicializa variables
|
||||
section::name = section::NAME_HI_SCORE_TABLE;
|
||||
section::name = section::Name::HI_SCORE_TABLE;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
counter = 0;
|
||||
@@ -115,13 +115,13 @@ void HiScoreTable::fillTexture()
|
||||
const auto firstLine = (param.game.height - size) / 2;
|
||||
|
||||
// Pinta en el backbuffer el texto y los sprites
|
||||
auto *temp = SDL_GetRenderTarget(renderer);
|
||||
auto temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, backbuffer);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// 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
|
||||
for (int i = 0; i < maxNames; ++i)
|
||||
@@ -136,7 +136,7 @@ void HiScoreTable::fillTexture()
|
||||
dots = dots + ".";
|
||||
}
|
||||
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
|
||||
@@ -184,7 +184,7 @@ void HiScoreTable::checkEvents()
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::NAME_QUIT;
|
||||
section::name = section::Name::QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -206,8 +206,8 @@ void HiScoreTable::checkInput()
|
||||
if (Input::get()->checkAnyButtonPressed())
|
||||
{
|
||||
JA_StopMusic();
|
||||
section::name = section::NAME_TITLE;
|
||||
section::options = section::OPTIONS_TITLE_1;
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ void HiScoreTable::checkInput()
|
||||
// Bucle para la pantalla de instrucciones
|
||||
void HiScoreTable::run()
|
||||
{
|
||||
while (section::name == section::NAME_HI_SCORE_TABLE)
|
||||
while (section::name == section::Name::HI_SCORE_TABLE)
|
||||
{
|
||||
checkInput();
|
||||
update();
|
||||
@@ -244,7 +244,7 @@ void HiScoreTable::updateFade()
|
||||
|
||||
if (fade->hasEnded() && fadeMode == FadeMode::OUT)
|
||||
{
|
||||
section::name = section::NAME_INSTRUCTIONS;
|
||||
section::name = section::Name::INSTRUCTIONS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <memory>
|
||||
#include <string> // for string
|
||||
#include "fade.h"
|
||||
#include "section.h" // for options_e
|
||||
#include "section.h" // for SectionOptions
|
||||
#include "background.h"
|
||||
#include "text.h"
|
||||
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
||||
JA_Music_t *music; // Musica de fondo
|
||||
|
||||
|
||||
std::unique_ptr<Fade> fade; // Objeto para renderizar fades
|
||||
std::unique_ptr<Background> background; // Objeto para dibujar el fondo del juego
|
||||
std::unique_ptr<SDL_Event> eventHandler; // Manejador de eventos
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
#include "lang.h" // for getText
|
||||
#include "param.h" // for param
|
||||
#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 "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 "tiled_bg.h" // for Tiledbg, TILED_MODE_STATIC
|
||||
#include "utils.h" // for Param, ParamGame, Color, shdwT...
|
||||
@@ -43,7 +43,7 @@ Instructions::Instructions(JA_Music_t *music)
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Inicializa variables
|
||||
section::name = section::NAME_INSTRUCTIONS;
|
||||
section::name = section::Name::INSTRUCTIONS;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
counter = 0;
|
||||
@@ -168,17 +168,17 @@ void Instructions::fillTexture()
|
||||
const int anchorItem = (param.game.width - (lenght + despX)) / 2;
|
||||
|
||||
// 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;
|
||||
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(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(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(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 + 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 * 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 + 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 * 3, lang::getText(15), 1, no_color, 1, shdw_txt_color);
|
||||
|
||||
// Escribe el texto de los objetos y sus puntos
|
||||
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 anchor4 = anchor3 + ((param.game.item_size + text->getCharacterSize()) / 2);
|
||||
@@ -251,8 +251,8 @@ void Instructions::update()
|
||||
// Comprueba si el contador ha llegado al final
|
||||
if (counter == counterEnd)
|
||||
{
|
||||
section::name = section::NAME_TITLE;
|
||||
section::options = section::OPTIONS_TITLE_1;
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,7 +304,7 @@ void Instructions::checkEvents()
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::NAME_QUIT;
|
||||
section::name = section::Name::QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -326,8 +326,8 @@ void Instructions::checkInput()
|
||||
if (Input::get()->checkAnyButtonPressed())
|
||||
{
|
||||
JA_StopMusic();
|
||||
section::name = section::NAME_TITLE;
|
||||
section::options = section::OPTIONS_TITLE_1;
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -341,7 +341,7 @@ void Instructions::checkInput()
|
||||
// Bucle para la pantalla de instrucciones
|
||||
void Instructions::run()
|
||||
{
|
||||
while (section::name == section::NAME_INSTRUCTIONS)
|
||||
while (section::name == section::Name::INSTRUCTIONS)
|
||||
{
|
||||
checkInput();
|
||||
update();
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "lang.h" // for getText
|
||||
#include "param.h" // for param
|
||||
#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 "text.h" // for Text
|
||||
#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);
|
||||
|
||||
// Inicializa variables
|
||||
section::name = section::NAME_INTRO;
|
||||
section::options = section::OPTIONS_NULL;
|
||||
section::name = section::Name::INTRO;
|
||||
section::options = section::Options::NONE;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
scene = 1;
|
||||
@@ -172,7 +172,7 @@ void Intro::checkEvents()
|
||||
{
|
||||
case SDL_QUIT:
|
||||
{
|
||||
section::name = section::NAME_QUIT;
|
||||
section::name = section::Name::QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -198,8 +198,8 @@ void Intro::checkInput()
|
||||
if (Input::get()->checkAnyButtonPressed())
|
||||
{
|
||||
JA_StopMusic();
|
||||
section::name = section::NAME_TITLE;
|
||||
section::options = section::OPTIONS_TITLE_1;
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -355,8 +355,8 @@ void Intro::updateScenes()
|
||||
bitmaps[5]->setEnabled(false);
|
||||
texts[8]->setEnabled(false);
|
||||
JA_StopMusic();
|
||||
section::name = section::NAME_TITLE;
|
||||
section::options = section::OPTIONS_TITLE_1;
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -422,7 +422,7 @@ void Intro::run()
|
||||
{
|
||||
JA_PlayMusic(music, 0);
|
||||
|
||||
while (section::name == section::NAME_INTRO)
|
||||
while (section::name == section::Name::INTRO)
|
||||
{
|
||||
checkInput();
|
||||
update();
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "jail_audio.h" // for JA_StopMusic
|
||||
#include "param.h" // for param
|
||||
#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 "texture.h" // for Texture
|
||||
|
||||
@@ -26,7 +26,7 @@ Logo::Logo()
|
||||
|
||||
// Inicializa variables
|
||||
counter = 0;
|
||||
section::name = section::NAME_LOGO;
|
||||
section::name = section::Name::LOGO;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
showSinceSprite_cm = 70;
|
||||
@@ -80,7 +80,7 @@ void Logo::checkEvents()
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::NAME_QUIT;
|
||||
section::name = section::Name::QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -102,8 +102,8 @@ void Logo::checkInput()
|
||||
if (Input::get()->checkAnyButtonPressed())
|
||||
{
|
||||
JA_StopMusic();
|
||||
section::name = section::NAME_TITLE;
|
||||
section::options = section::OPTIONS_TITLE_1;
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ void Logo::update()
|
||||
// Comprueba si ha terminado el logo
|
||||
if (counter == endLogo_cm + postLogoDuration)
|
||||
{
|
||||
section::name = section::NAME_INTRO;
|
||||
section::name = section::Name::INTRO;
|
||||
}
|
||||
|
||||
// Comprueba si se ha de mostrar el sprite
|
||||
@@ -233,7 +233,7 @@ void Logo::run()
|
||||
// Detiene la música
|
||||
JA_StopMusic();
|
||||
|
||||
while (section::name == section::NAME_LOGO)
|
||||
while (section::name == section::Name::LOGO)
|
||||
{
|
||||
checkInput();
|
||||
update();
|
||||
|
||||
@@ -92,7 +92,7 @@ void OnScreenHelp::render()
|
||||
void OnScreenHelp::fillTexture()
|
||||
{
|
||||
// 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);
|
||||
|
||||
// Crea el objeto para el texto
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
namespace section
|
||||
{
|
||||
name_e name;
|
||||
options_e options;
|
||||
Name name;
|
||||
Options options;
|
||||
}
|
||||
@@ -3,31 +3,31 @@
|
||||
namespace section
|
||||
{
|
||||
// Secciones del programa
|
||||
enum name_e
|
||||
enum class Name
|
||||
{
|
||||
NAME_INIT = 0,
|
||||
NAME_LOGO = 1,
|
||||
NAME_INTRO = 2,
|
||||
NAME_TITLE = 3,
|
||||
NAME_GAME = 4,
|
||||
NAME_HI_SCORE_TABLE = 5,
|
||||
NAME_GAME_DEMO = 6,
|
||||
NAME_INSTRUCTIONS = 7,
|
||||
NAME_QUIT = 8,
|
||||
INIT = 0,
|
||||
LOGO = 1,
|
||||
INTRO = 2,
|
||||
TITLE = 3,
|
||||
GAME = 4,
|
||||
HI_SCORE_TABLE = 5,
|
||||
GAME_DEMO = 6,
|
||||
INSTRUCTIONS = 7,
|
||||
QUIT = 8,
|
||||
};
|
||||
|
||||
// Opciones para la sección
|
||||
enum options_e
|
||||
enum class Options
|
||||
{
|
||||
OPTIONS_GAME_PLAY_1P = 0,
|
||||
OPTIONS_GAME_PLAY_2P = 1,
|
||||
OPTIONS_TITLE_1 = 2,
|
||||
OPTIONS_TITLE_2 = 3,
|
||||
OPTIONS_QUIT_NORMAL = 4,
|
||||
OPTIONS_QUIT_SHUTDOWN = 5,
|
||||
OPTIONS_NULL = 6,
|
||||
GAME_PLAY_1P = 0,
|
||||
GAME_PLAY_2P = 1,
|
||||
TITLE_1 = 2,
|
||||
TITLE_2 = 3,
|
||||
QUIT_NORMAL = 4,
|
||||
QUIT_SHUTDOWN = 5,
|
||||
NONE = 6,
|
||||
};
|
||||
|
||||
extern name_e name;
|
||||
extern options_e options;
|
||||
extern Name name;
|
||||
extern Options options;
|
||||
}
|
||||
158
source/text.cpp
158
source/text.cpp
@@ -5,10 +5,10 @@
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for Color
|
||||
|
||||
// Llena una estructuta textFile_t desde un fichero
|
||||
textFile_t LoadTextFile(std::string file)
|
||||
// Llena una estructuta TextFile desde un fichero
|
||||
TextFile LoadTextFile(std::string file_path)
|
||||
{
|
||||
textFile_t tf;
|
||||
TextFile tf;
|
||||
|
||||
// Inicializa a cero el vector con las coordenadas
|
||||
for (int i = 0; i < 128; ++i)
|
||||
@@ -19,26 +19,26 @@ textFile_t LoadTextFile(std::string file)
|
||||
}
|
||||
|
||||
// Abre el fichero para leer los valores
|
||||
const std::string filename = file.substr(file.find_last_of("\\/") + 1).c_str();
|
||||
std::ifstream rfile(file);
|
||||
const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1).c_str();
|
||||
std::ifstream file(file_path);
|
||||
|
||||
if (rfile.is_open() && rfile.good())
|
||||
if (file.is_open() && file.good())
|
||||
{
|
||||
std::string buffer;
|
||||
|
||||
// Lee los dos primeros valores del fichero
|
||||
std::getline(rfile, buffer);
|
||||
std::getline(rfile, buffer);
|
||||
tf.boxWidth = std::stoi(buffer);
|
||||
std::getline(file, buffer);
|
||||
std::getline(file, buffer);
|
||||
tf.box_width = std::stoi(buffer);
|
||||
|
||||
std::getline(rfile, buffer);
|
||||
std::getline(rfile, buffer);
|
||||
tf.boxHeight = std::stoi(buffer);
|
||||
std::getline(file, buffer);
|
||||
std::getline(file, buffer);
|
||||
tf.box_height = std::stoi(buffer);
|
||||
|
||||
// lee el resto de datos del fichero
|
||||
int index = 32;
|
||||
int line_read = 0;
|
||||
while (std::getline(rfile, buffer))
|
||||
auto index = 32;
|
||||
auto line_read = 0;
|
||||
while (std::getline(file, buffer))
|
||||
{
|
||||
// Almacena solo las lineas impares
|
||||
if (line_read % 2 == 1)
|
||||
@@ -53,133 +53,133 @@ textFile_t LoadTextFile(std::string file)
|
||||
|
||||
// Cierra el fichero
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Text loaded: " << filename.c_str() << std::endl;
|
||||
std::cout << "Text loaded: " << file_name.c_str() << std::endl;
|
||||
#endif
|
||||
rfile.close();
|
||||
file.close();
|
||||
}
|
||||
|
||||
// El fichero no se puede abrir
|
||||
else
|
||||
{
|
||||
#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
|
||||
}
|
||||
|
||||
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||
for (int i = 32; i < 128; ++i)
|
||||
{
|
||||
tf.offset[i].x = ((i - 32) % 15) * tf.boxWidth;
|
||||
tf.offset[i].y = ((i - 32) / 15) * tf.boxHeight;
|
||||
tf.offset[i].x = ((i - 32) % 15) * tf.box_width;
|
||||
tf.offset[i].y = ((i - 32) / 15) * tf.box_height;
|
||||
}
|
||||
|
||||
return tf;
|
||||
}
|
||||
|
||||
// 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
|
||||
textFile_t tf = LoadTextFile(textFile);
|
||||
auto tf = LoadTextFile(text_file);
|
||||
|
||||
// Inicializa variables desde la estructura
|
||||
boxHeight = tf.boxHeight;
|
||||
boxWidth = tf.boxWidth;
|
||||
box_height_ = tf.box_height;
|
||||
box_width_ = tf.box_width;
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = tf.offset[i].x;
|
||||
offset[i].y = tf.offset[i].y;
|
||||
offset[i].w = tf.offset[i].w;
|
||||
offset_[i].x = tf.offset[i].x;
|
||||
offset_[i].y = tf.offset[i].y;
|
||||
offset_[i].w = tf.offset[i].w;
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
texture = std::make_shared<Texture>(renderer, bitmapFile);
|
||||
sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, boxWidth, boxHeight}, texture);
|
||||
texture_ = std::make_shared<Texture>(renderer, bitmap_file);
|
||||
sprite_ = std::make_unique<Sprite>((SDL_Rect){0, 0, box_width_, box_height_}, texture_);
|
||||
|
||||
// Inicializa variables
|
||||
fixedWidth = false;
|
||||
fixed_width_ = false;
|
||||
}
|
||||
|
||||
// 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
|
||||
textFile_t tf = LoadTextFile(textFile);
|
||||
auto tf = LoadTextFile(text_file);
|
||||
|
||||
// Inicializa variables desde la estructura
|
||||
boxHeight = tf.boxHeight;
|
||||
boxWidth = tf.boxWidth;
|
||||
box_height_ = tf.box_height;
|
||||
box_width_ = tf.box_width;
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = tf.offset[i].x;
|
||||
offset[i].y = tf.offset[i].y;
|
||||
offset[i].w = tf.offset[i].w;
|
||||
offset_[i].x = tf.offset[i].x;
|
||||
offset_[i].y = tf.offset[i].y;
|
||||
offset_[i].w = tf.offset[i].w;
|
||||
}
|
||||
|
||||
// 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
|
||||
fixedWidth = false;
|
||||
fixed_width_ = false;
|
||||
}
|
||||
|
||||
// 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
|
||||
boxHeight = textFile->boxHeight;
|
||||
boxWidth = textFile->boxWidth;
|
||||
box_height_ = text_file->box_height;
|
||||
box_width_ = text_file->box_width;
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
offset[i].x = textFile->offset[i].x;
|
||||
offset[i].y = textFile->offset[i].y;
|
||||
offset[i].w = textFile->offset[i].w;
|
||||
offset_[i].x = text_file->offset[i].x;
|
||||
offset_[i].y = text_file->offset[i].y;
|
||||
offset_[i].w = text_file->offset[i].w;
|
||||
}
|
||||
|
||||
// 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
|
||||
fixedWidth = false;
|
||||
fixed_width_ = false;
|
||||
}
|
||||
|
||||
// Escribe texto en pantalla
|
||||
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||
{
|
||||
int shift = 0;
|
||||
auto shift = 0;
|
||||
|
||||
if (lenght == -1)
|
||||
{
|
||||
lenght = text.length();
|
||||
}
|
||||
|
||||
sprite->setPosY(y);
|
||||
const int width = sprite->getWidth();
|
||||
const int height = sprite->getHeight();
|
||||
sprite_->setPosY(y);
|
||||
const auto width = sprite_->getWidth();
|
||||
const auto height = sprite_->getHeight();
|
||||
for (int i = 0; i < lenght; ++i)
|
||||
{
|
||||
const int index = text[i];
|
||||
sprite->setSpriteClip(offset[index].x, offset[index].y, width, height);
|
||||
sprite->setPosX(x + shift);
|
||||
sprite->render();
|
||||
shift += fixedWidth ? boxWidth : (offset[int(text[i])].w + kerning);
|
||||
const auto index = static_cast<int>(text[i]);
|
||||
sprite_->setSpriteClip(offset_[index].x, offset_[index].y, width, height);
|
||||
sprite_->setPosX(x + shift);
|
||||
sprite_->render();
|
||||
shift += fixed_width_ ? box_width_ : (offset_[int(text[i])].w + kerning);
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe el texto con colores
|
||||
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);
|
||||
sprite->getTexture()->setColor(255, 255, 255);
|
||||
sprite_->getTexture()->setColor(255, 255, 255);
|
||||
}
|
||||
|
||||
// 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);
|
||||
write(x + shadowDistance, y + shadowDistance, text, kerning, lenght);
|
||||
sprite->getTexture()->setColor(255, 255, 255);
|
||||
sprite_->getTexture()->setColor(color.r, color.g, color.b);
|
||||
write(x + shadow_distance, y + shadow_distance, text, kerning, lenght);
|
||||
sprite_->getTexture()->setColor(255, 255, 255);
|
||||
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
|
||||
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 bool shadowed = ((flags & TXT_SHADOW) == TXT_SHADOW);
|
||||
const bool colored = ((flags & TXT_COLOR) == TXT_COLOR);
|
||||
const bool stroked = ((flags & TXT_STROKE) == TXT_STROKE);
|
||||
const auto centered = ((flags & TEXT_CENTER) == TEXT_CENTER);
|
||||
const auto shadowed = ((flags & TEXT_SHADOW) == TEXT_SHADOW);
|
||||
const auto colored = ((flags & TEXT_COLOR) == TEXT_COLOR);
|
||||
const auto stroked = ((flags & TEXT_STROKE) == TEXT_STROKE);
|
||||
|
||||
if (centered)
|
||||
{
|
||||
@@ -205,18 +205,18 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Col
|
||||
|
||||
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)
|
||||
{
|
||||
for (int dist = 1; dist <= shadowDistance; ++dist)
|
||||
for (int dist = 1; dist <= shadow_distance; ++dist)
|
||||
{
|
||||
for (int dy = -dist; dy <= dist; ++dy)
|
||||
{
|
||||
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
|
||||
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)
|
||||
shift += (offset[int(text[i])].w + kerning);
|
||||
{
|
||||
shift += (offset_[int(text[i])].w + kerning);
|
||||
}
|
||||
|
||||
// Descuenta el kerning del último caracter
|
||||
return shift - kerning;
|
||||
@@ -247,29 +249,29 @@ int Text::lenght(std::string text, int kerning)
|
||||
// Devuelve el valor de la variable
|
||||
int Text::getCharacterSize() const
|
||||
{
|
||||
return boxWidth;
|
||||
return box_width_;
|
||||
}
|
||||
|
||||
// Recarga la textura
|
||||
void Text::reLoadTexture()
|
||||
{
|
||||
sprite->getTexture()->reLoad();
|
||||
sprite_->getTexture()->reLoad();
|
||||
}
|
||||
|
||||
// Establece si se usa un tamaño fijo de letra
|
||||
void Text::setFixedWidth(bool value)
|
||||
{
|
||||
fixedWidth = value;
|
||||
fixed_width_ = value;
|
||||
}
|
||||
|
||||
// Carga una paleta de colores para el texto
|
||||
void Text::addPalette(std::string path)
|
||||
{
|
||||
texture->addPalette(path);
|
||||
texture_->addPalette(path);
|
||||
}
|
||||
|
||||
// Establece una paleta de colores para el texto
|
||||
void Text::setPalette(int index)
|
||||
{
|
||||
texture->setPalette(index);
|
||||
texture_->setPalette(index);
|
||||
}
|
||||
@@ -8,45 +8,45 @@
|
||||
#include "sprite.h"
|
||||
#include "texture.h"
|
||||
|
||||
#define TXT_COLOR 1
|
||||
#define TXT_SHADOW 2
|
||||
#define TXT_CENTER 4
|
||||
#define TXT_STROKE 8
|
||||
constexpr int TEXT_COLOR = 1;
|
||||
constexpr int TEXT_SHADOW = 2;
|
||||
constexpr int TEXT_CENTER = 4;
|
||||
constexpr int TEXT_STROKE = 8;
|
||||
|
||||
struct offset_t
|
||||
struct TextOffset
|
||||
{
|
||||
int x, y, w;
|
||||
};
|
||||
|
||||
struct textFile_t
|
||||
struct TextFile
|
||||
{
|
||||
int boxWidth; // Anchura de la caja de cada caracter en el png
|
||||
int boxHeight; // Altura de la caja de cada caracter en el png
|
||||
offset_t offset[128]; // Vector con las posiciones y ancho de cada letra
|
||||
int box_width; // Anchura de la caja de cada caracter en el png
|
||||
int box_height; // Altura de la caja de cada caracter en el png
|
||||
TextOffset offset[128]; // Vector con las posiciones y ancho de cada letra
|
||||
};
|
||||
|
||||
// Llena una estructuta textFile_t desde un fichero
|
||||
textFile_t LoadTextFile(std::string file);
|
||||
// Llena una estructuta TextFile desde un fichero
|
||||
TextFile LoadTextFile(std::string file);
|
||||
|
||||
// Clase texto. Pinta texto en pantalla a partir de un bitmap
|
||||
class Text
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
std::unique_ptr<Sprite> sprite; // Objeto con los graficos para el texto
|
||||
std::shared_ptr<Texture> texture; // Textura con los bitmaps del texto
|
||||
std::unique_ptr<Sprite> sprite_; // Objeto con los graficos para el texto
|
||||
std::shared_ptr<Texture> texture_; // Textura con los bitmaps del texto
|
||||
|
||||
// Variables
|
||||
int boxWidth; // Anchura de la caja de cada caracter en el png
|
||||
int boxHeight; // 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
|
||||
offset_t offset[128]; // Vector con las posiciones y ancho de cada letra
|
||||
int box_width_; // Anchura de la caja de cada caracter en el png
|
||||
int box_height_; // Altura de la caja de cada caracter en el png
|
||||
bool fixed_width_; // Indica si el texto se ha de escribir con longitud fija en todas las letras
|
||||
TextOffset offset_[128]; // Vector con las posiciones y ancho de cada letra
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer);
|
||||
Text(std::string textFile, std::shared_ptr<Texture> texture);
|
||||
Text(textFile_t *textFile, std::shared_ptr<Texture> texture);
|
||||
Text(std::string bitmap_file, std::string text_file, SDL_Renderer *renderer);
|
||||
Text(std::string text_file, std::shared_ptr<Texture> texture);
|
||||
Text(TextFile *text_file, std::shared_ptr<Texture> texture);
|
||||
|
||||
// Destructor
|
||||
~Text() = default;
|
||||
@@ -58,16 +58,16 @@ public:
|
||||
void writeColored(int x, int y, std::string text, Color color, int kerning = 1, int lenght = -1);
|
||||
|
||||
// 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
|
||||
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
|
||||
|
||||
// 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
|
||||
int lenght(std::string text, int kerning = 1);
|
||||
int lenght(std::string text, int kerning = 1) const;
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
int getCharacterSize() const;
|
||||
|
||||
@@ -56,7 +56,7 @@ Texture::~Texture()
|
||||
// Carga una imagen desde un fichero
|
||||
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 width, height, orig_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
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Image loaded: " << filename.c_str() << std::endl;
|
||||
std::cout << "Image loaded: " << file_name.c_str() << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -265,9 +265,9 @@ void Texture::deleteSurface(Surface surface)
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
return NULL;
|
||||
@@ -303,7 +303,7 @@ Surface Texture::loadSurface(const char *filename)
|
||||
void Texture::flipSurface()
|
||||
{
|
||||
// Limpia la textura
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, texture_);
|
||||
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer_);
|
||||
@@ -327,11 +327,11 @@ void Texture::setPaletteColor(int palette, int index, Uint32 color)
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
FILE *f = fopen(filename, "rb");
|
||||
FILE *f = fopen(file_name, "rb");
|
||||
if (!f)
|
||||
{
|
||||
return palette;
|
||||
|
||||
@@ -39,13 +39,13 @@ private:
|
||||
void deleteSurface(Surface surface);
|
||||
|
||||
// Crea una surface desde un fichero .gif
|
||||
Surface loadSurface(const char *filename);
|
||||
Surface loadSurface(const char *file_name);
|
||||
|
||||
// Vuelca la surface en la textura
|
||||
void flipSurface();
|
||||
|
||||
// Carga una paleta desde un fichero
|
||||
std::vector<Uint32> loadPal(const char *filename);
|
||||
std::vector<Uint32> loadPal(const char *file_name);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Tiledbg::Tiledbg(std::string texturePath, SDL_Rect pos, int mode)
|
||||
: texturePath(texturePath), pos(pos), mode(mode)
|
||||
Tiledbg::Tiledbg(std::string texture_path, SDL_Rect pos, int mode)
|
||||
: texture_path_(texture_path), pos_(pos), mode_(mode)
|
||||
{
|
||||
// Copia los punteros
|
||||
renderer = Screen::get()->getRenderer();
|
||||
renderer_ = Screen::get()->getRenderer();
|
||||
|
||||
// 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
|
||||
init();
|
||||
@@ -23,34 +23,34 @@ Tiledbg::Tiledbg(std::string texturePath, SDL_Rect pos, int mode)
|
||||
// Destructor
|
||||
Tiledbg::~Tiledbg()
|
||||
{
|
||||
SDL_DestroyTexture(canvas);
|
||||
SDL_DestroyTexture(canvas_);
|
||||
}
|
||||
|
||||
// Inicializa las variables
|
||||
void Tiledbg::init()
|
||||
{
|
||||
counter = 0;
|
||||
if (mode == TILED_MODE_RANDOM)
|
||||
counter_ = 0;
|
||||
if (mode_ == TILED_MODE_RANDOM)
|
||||
{
|
||||
mode = rand() % 2;
|
||||
mode_ = rand() % 2;
|
||||
}
|
||||
tileWidth = 64;
|
||||
tileHeight = 64;
|
||||
tile_width_ = 64;
|
||||
tile_height_ = 64;
|
||||
|
||||
// Rellena la textura con el contenido
|
||||
fillTexture();
|
||||
|
||||
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida
|
||||
// con el mosaico que hay pintado en el titulo al iniciar
|
||||
window.x = 128;
|
||||
window.y = 96;
|
||||
window.w = pos.w;
|
||||
window.h = pos.h;
|
||||
window_.x = 128;
|
||||
window_.y = 96;
|
||||
window_.w = pos_.w;
|
||||
window_.h = pos_.h;
|
||||
|
||||
// Inicializa los valores del vector con los valores del seno
|
||||
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()
|
||||
{
|
||||
// Crea los objetos para pintar en la textura de fondo
|
||||
auto bgTileTexture = std::make_shared<Texture>(renderer, texturePath);
|
||||
auto tile = std::make_unique<Sprite>((SDL_Rect){0, 0, tileWidth, tileHeight}, bgTileTexture);
|
||||
auto bg_tile_texture = std::make_shared<Texture>(renderer_, texture_path_);
|
||||
auto tile = std::make_unique<Sprite>((SDL_Rect){0, 0, tile_width_, tile_height_}, bg_tile_texture);
|
||||
|
||||
// Prepara para dibujar sobre la textura
|
||||
auto temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, canvas);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, canvas_);
|
||||
|
||||
// Rellena la textura con el tile
|
||||
const auto iMax = pos.w * 2 / tileWidth;
|
||||
const auto jMax = pos.h * 2 / tileHeight;
|
||||
tile->setSpriteClip(0, 0, tileWidth, tileHeight);
|
||||
for (int i = 0; i < iMax; ++i)
|
||||
const auto i_max = pos_.w * 2 / tile_width_;
|
||||
const auto j_max = pos_.h * 2 / tile_height_;
|
||||
tile->setSpriteClip(0, 0, tile_width_, tile_height_);
|
||||
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->setPosY(j * tileHeight);
|
||||
tile->setPosX(i * tile_width_);
|
||||
tile->setPosY(j * tile_height_);
|
||||
tile->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Vuelve a colocar el renderizador como estaba
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
|
||||
// Libera la memoria utilizada por los objetos
|
||||
bgTileTexture->unload();
|
||||
bg_tile_texture->unload();
|
||||
}
|
||||
|
||||
// Pinta la clase en pantalla
|
||||
void Tiledbg::render()
|
||||
{
|
||||
SDL_RenderCopy(renderer, canvas, &window, &pos);
|
||||
SDL_RenderCopy(renderer_, canvas_, &window_, &pos_);
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
void Tiledbg::update()
|
||||
{
|
||||
if (mode == TILED_MODE_DIAGONAL)
|
||||
if (mode_ == TILED_MODE_DIAGONAL)
|
||||
{ // El tileado de fondo se desplaza en diagonal
|
||||
++window.x %= tileWidth;
|
||||
++window.y %= tileHeight;
|
||||
++window_.x %= tile_width_;
|
||||
++window_.y %= tile_height_;
|
||||
}
|
||||
else if (mode == TILED_MODE_CIRCLE)
|
||||
else if (mode_ == TILED_MODE_CIRCLE)
|
||||
{ // El tileado de fondo se desplaza en circulo
|
||||
++counter %= 360;
|
||||
window.x = 128 + (int(sin[(counter + 270) % 360] * 128));
|
||||
window.y = 96 + (int(sin[(360 - counter) % 360] * 96));
|
||||
++counter_ %= 360;
|
||||
window_.x = 128 + (int(sin_[(counter_ + 270) % 360] * 128));
|
||||
window_.y = 96 + (int(sin_[(360 - counter_) % 360] * 96));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <string> // for string, basic_string
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <string> // for string, basic_string
|
||||
|
||||
// Modos de funcionamiento para el tileado de fondo
|
||||
#define TILED_MODE_CIRCLE 0
|
||||
@@ -21,18 +21,18 @@ class Tiledbg
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
SDL_Rect window; // Ventana visible para la textura de fondo del titulo
|
||||
SDL_Texture *canvas; // Textura donde dibujar el fondo formado por tiles
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
SDL_Rect window_; // Ventana visible para la textura de fondo del titulo
|
||||
SDL_Texture *canvas_; // Textura donde dibujar el fondo formado por tiles
|
||||
|
||||
// Variables
|
||||
std::string texturePath; // Fichero para usar en la textura
|
||||
SDL_Rect pos; // Posición y tamaña del mosaico
|
||||
int counter; // Contador
|
||||
int mode; // Tipo de movimiento del mosaico
|
||||
float sin[360]; // Vector con los valores del seno precalculados
|
||||
int tileWidth; // Ancho del tile
|
||||
int tileHeight; // Alto del tile
|
||||
std::string texture_path_; // Fichero para usar en la textura
|
||||
SDL_Rect pos_; // Posición y tamaña del mosaico
|
||||
int counter_; // Contador
|
||||
int mode_; // Tipo de movimiento del mosaico
|
||||
float sin_[360]; // Vector con los valores del seno precalculados
|
||||
int tile_width_; // Ancho del tile
|
||||
int tile_height_; // Alto del tile
|
||||
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
@@ -42,7 +42,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Tiledbg(std::string texturePath, SDL_Rect pos, int mode);
|
||||
Tiledbg(std::string texture_path, SDL_Rect pos, int mode);
|
||||
|
||||
// Destructor
|
||||
~Tiledbg();
|
||||
|
||||
199
source/title.cpp
199
source/title.cpp
@@ -12,38 +12,36 @@
|
||||
#include "options.h" // for options
|
||||
#include "param.h" // for param
|
||||
#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;
|
||||
|
||||
// Constructor
|
||||
Title::Title(JA_Music_t *music)
|
||||
: music(music)
|
||||
: music_(music)
|
||||
{
|
||||
// Copia las direcciones de los punteros y objetos
|
||||
input = Input::get();
|
||||
asset = Asset::get();
|
||||
screen = Screen::get();
|
||||
SDL_Renderer *renderer = screen->getRenderer();
|
||||
input_ = Input::get();
|
||||
screen_ = Screen::get();
|
||||
SDL_Renderer *renderer = screen_->getRenderer();
|
||||
|
||||
// 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->addPalette(asset->get("smb2_pal1.gif"));
|
||||
text1->setPalette(1);
|
||||
text2 = std::make_unique<Text>(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
|
||||
text1_ = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer);
|
||||
text1_->addPalette(Asset::get()->get("smb2_pal1.gif"));
|
||||
text1_->setPalette(1);
|
||||
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"));
|
||||
miniLogoSprite = std::make_unique<Sprite>(param.game.game_area.center_x - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture);
|
||||
mini_logo_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames_mini.png"));
|
||||
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);
|
||||
gameLogo->enable();
|
||||
game_logo_ = std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position);
|
||||
game_logo_->enable();
|
||||
|
||||
defineButtons = std::make_unique<DefineButtons>(std::move(text2));
|
||||
define_buttons_ = std::make_unique<DefineButtons>(std::move(text2_));
|
||||
|
||||
// Inicializa los valores
|
||||
init();
|
||||
@@ -53,79 +51,79 @@ Title::Title(JA_Music_t *music)
|
||||
void Title::init()
|
||||
{
|
||||
// Inicializa variables
|
||||
section::options = section::OPTIONS_TITLE_1;
|
||||
counter = 0;
|
||||
nextSection.name = section::NAME_GAME;
|
||||
postFade = 0;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
fade->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade->setType(FadeType::RANDOM_SQUARE);
|
||||
fade->setPost(param.fade.post_duration);
|
||||
demo = true;
|
||||
numControllers = input->getNumControllers();
|
||||
section::options = section::Options::TITLE_1;
|
||||
counter_ = 0;
|
||||
next_section_ = section::Name::GAME;
|
||||
post_fade_ = 0;
|
||||
ticks_ = 0;
|
||||
ticks_speed_ = 15;
|
||||
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_->setPost(param.fade.post_duration);
|
||||
demo_ = true;
|
||||
num_controllers_ = input_->getNumControllers();
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void Title::update()
|
||||
{
|
||||
// Calcula la lógica de los objetos
|
||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
// Actualiza el contador de ticks_
|
||||
ticks_ = SDL_GetTicks();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
screen->update();
|
||||
screen_->update();
|
||||
|
||||
// Comprueba el fade y si se ha acabado
|
||||
fade->update();
|
||||
if (fade->hasEnded())
|
||||
// Comprueba el fade_ y si se ha acabado
|
||||
fade_->update();
|
||||
if (fade_->hasEnded())
|
||||
{
|
||||
if (postFade == -1)
|
||||
if (post_fade_ == -1)
|
||||
{
|
||||
section::name = section::NAME_GAME_DEMO;
|
||||
section::name = section::Name::GAME_DEMO;
|
||||
}
|
||||
else
|
||||
{
|
||||
section::name = section::NAME_GAME;
|
||||
section::options = postFade == 1 ? section::OPTIONS_GAME_PLAY_1P : section::OPTIONS_GAME_PLAY_2P;
|
||||
section::name = section::Name::GAME;
|
||||
section::options = post_fade_ == 1 ? section::Options::GAME_PLAY_1P : section::Options::GAME_PLAY_2P;
|
||||
JA_StopMusic();
|
||||
}
|
||||
}
|
||||
|
||||
// Sección 1 - Titulo animandose
|
||||
if (section::options == section::OPTIONS_TITLE_1)
|
||||
if (section::options == section::Options::TITLE_1)
|
||||
{
|
||||
gameLogo->update();
|
||||
if (gameLogo->hasFinished())
|
||||
game_logo_->update();
|
||||
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
|
||||
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
|
||||
counter = defineButtons->isEnabled() ? 0 : counter + 1;
|
||||
counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1;
|
||||
|
||||
// Reproduce la música
|
||||
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
|
||||
gameLogo->update();
|
||||
game_logo_->update();
|
||||
|
||||
// Actualiza el mosaico de fondo
|
||||
tiledbg->update();
|
||||
tiled_bg_->update();
|
||||
|
||||
if (counter == param.title.title_duration)
|
||||
if (counter_ == param.title.title_duration)
|
||||
{
|
||||
fade->activate();
|
||||
postFade = -1;
|
||||
fade_->activate();
|
||||
post_fade_ = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,83 +133,84 @@ void Title::update()
|
||||
void Title::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
screen_->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean(bg_color);
|
||||
screen_->clean(bg_color);
|
||||
|
||||
// Dibuja el mosacico de fondo
|
||||
tiledbg->render();
|
||||
tiled_bg_->render();
|
||||
|
||||
// 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};
|
||||
|
||||
// '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
|
||||
const int pos1 = (param.game.height / 5 * 4) + BLOCK;
|
||||
const int pos2 = pos1 + miniLogoSprite->getHeight() + 3;
|
||||
miniLogoSprite->setPosY(pos1);
|
||||
miniLogoSprite->render();
|
||||
const int pos2 = pos1 + mini_logo_sprite_->getHeight() + 3;
|
||||
mini_logo_sprite_->setPosY(pos1);
|
||||
mini_logo_sprite_->render();
|
||||
|
||||
// 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
|
||||
defineButtons->render();
|
||||
define_buttons_->render();
|
||||
|
||||
// Fade
|
||||
fade->render();
|
||||
fade_->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->blit();
|
||||
screen_->blit();
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
void Title::checkEvents()
|
||||
{
|
||||
// Si defineButtons está habilitado, es él quien gestiona los eventos
|
||||
if (!defineButtons->isEnabled())
|
||||
// Si define_buttons_ está habilitado, es él quien gestiona los eventos
|
||||
if (!define_buttons_->isEnabled())
|
||||
{
|
||||
SDL_Event event;
|
||||
// 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
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::NAME_QUIT;
|
||||
section::name = section::Name::QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
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:
|
||||
{
|
||||
if (defineButtons->enable(0))
|
||||
if (define_buttons_->enable(0))
|
||||
resetCounter();
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_2:
|
||||
{
|
||||
if (defineButtons->enable(1))
|
||||
if (define_buttons_->enable(1))
|
||||
resetCounter();
|
||||
break;
|
||||
}
|
||||
@@ -234,45 +233,45 @@ void Title::checkEvents()
|
||||
void Title::checkInput()
|
||||
{
|
||||
// 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
|
||||
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();
|
||||
postFade = options.controller[0].player_id;
|
||||
fade_->activate();
|
||||
post_fade_ = options.controller[0].player_id;
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
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();
|
||||
return;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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
|
||||
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();
|
||||
postFade = options.controller[i].player_id;
|
||||
fade_->activate();
|
||||
post_fade_ = options.controller[i].player_id;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -281,8 +280,8 @@ void Title::checkInput()
|
||||
}
|
||||
|
||||
// Comprueba el input para el resto de objetos
|
||||
screen->checkInput();
|
||||
defineButtons->checkInput();
|
||||
screen_->checkInput();
|
||||
define_buttons_->checkInput();
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
globalInputs::check();
|
||||
@@ -291,7 +290,7 @@ void Title::checkInput()
|
||||
// Bucle para el titulo del juego
|
||||
void Title::run()
|
||||
{
|
||||
while (section::name == section::NAME_TITLE)
|
||||
while (section::name == section::Name::TITLE)
|
||||
{
|
||||
checkInput();
|
||||
update();
|
||||
@@ -303,27 +302,27 @@ void Title::run()
|
||||
// Recarga las texturas
|
||||
void Title::reLoadTextures()
|
||||
{
|
||||
gameLogo->reLoad();
|
||||
tiledbg->reLoad();
|
||||
game_logo_->reLoad();
|
||||
tiled_bg_->reLoad();
|
||||
}
|
||||
|
||||
// Reinicia el contador interno
|
||||
void Title::resetCounter()
|
||||
{
|
||||
counter = 0;
|
||||
counter_ = 0;
|
||||
}
|
||||
|
||||
// Intercambia la asignación de mandos a los jugadores
|
||||
void Title::swapControllers()
|
||||
{
|
||||
const int numControllers = input->getNumControllers();
|
||||
const int num_controllers_ = input_->getNumControllers();
|
||||
|
||||
if (numControllers == 0)
|
||||
if (num_controllers_ == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
defineButtons->swapControllers();
|
||||
define_buttons_->swapControllers();
|
||||
|
||||
// Crea cadenas de texto vacias para un numero máximo de mandos
|
||||
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();
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "utils.h" // for Section
|
||||
#include "sprite.h"
|
||||
#include "texture.h"
|
||||
#include "section.h"
|
||||
|
||||
class Asset;
|
||||
class Input;
|
||||
@@ -45,30 +46,28 @@ class Title
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
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
|
||||
std::unique_ptr<SDL_Event> eventHandler; // Manejador de eventos
|
||||
std::unique_ptr<Tiledbg> tiledbg; // Objeto para dibujar el mosaico animado de fondo
|
||||
std::unique_ptr<GameLogo> gameLogo; // Objeto para dibujar el logo con el título del juego
|
||||
std::unique_ptr<DefineButtons> defineButtons; // Objeto para definir los botones del joystic
|
||||
std::shared_ptr<Texture> miniLogoTexture; // Textura con el logo de JailGames mini
|
||||
std::unique_ptr<Sprite> miniLogoSprite; // Sprite con el logo de JailGames mini
|
||||
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||
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<GameLogo> game_logo_; // Objeto para dibujar el logo con el título del juego
|
||||
std::unique_ptr<DefineButtons> define_buttons_; // Objeto para definir los botones del joystic
|
||||
std::shared_ptr<Texture> mini_logo_texture_; // Textura con el logo de JailGames mini
|
||||
std::unique_ptr<Sprite> mini_logo_sprite_; // 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> text2; // Objeto de texto para poder escribir textos en pantalla
|
||||
std::unique_ptr<Fade> fade; // Objeto para realizar fundidos 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<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
|
||||
int counter; // Temporizador para la pantalla de titulo
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
bool demo; // Indica si el modo demo estará activo
|
||||
Section nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
int postFade; // Opción a realizar cuando termina el fundido
|
||||
int numControllers; // Número de mandos conectados
|
||||
int counter_; // Temporizador para la pantalla de titulo
|
||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
||||
bool demo_; // Indica si el modo demo estará activo
|
||||
section::Name next_section_; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
||||
int post_fade_; // Opción a realizar cuando termina el fundido
|
||||
int num_controllers_; // Número de mandos conectados
|
||||
|
||||
// Inicializa los valores de las variables
|
||||
void init();
|
||||
|
||||
@@ -47,11 +47,11 @@ enum class NotifyPosition
|
||||
};
|
||||
|
||||
// Estructura para saber la seccion y subseccion del programa
|
||||
struct Section
|
||||
/*struct Section
|
||||
{
|
||||
Uint8 name;
|
||||
Uint8 options;
|
||||
};
|
||||
section::Name name;
|
||||
section::Options options;
|
||||
};*/
|
||||
|
||||
// Estructura para las entradas de la tabla de recirds
|
||||
struct HiScoreEntry
|
||||
|
||||
@@ -5,17 +5,17 @@ Writer::Writer(std::shared_ptr<Text> text)
|
||||
: text_(text)
|
||||
{
|
||||
// Inicializa variables
|
||||
posX_ = 0;
|
||||
posY_ = 0;
|
||||
pos_x_ = 0;
|
||||
pos_y_ = 0;
|
||||
kerning_ = 0;
|
||||
caption_ = "";
|
||||
speed_ = 0;
|
||||
writingCounter_ = 0;
|
||||
writing_counter_ = 0;
|
||||
index_ = 0;
|
||||
lenght_ = 0;
|
||||
completed_ = false;
|
||||
enabled_ = false;
|
||||
enabledCounter_ = 0;
|
||||
enabled_counter_ = 0;
|
||||
finished_ = false;
|
||||
}
|
||||
|
||||
@@ -27,15 +27,14 @@ void Writer::update()
|
||||
if (!completed_)
|
||||
{
|
||||
// No completado
|
||||
if (writingCounter_ > 0)
|
||||
if (writing_counter_ > 0)
|
||||
{
|
||||
writingCounter_--;
|
||||
writing_counter_--;
|
||||
}
|
||||
|
||||
else if (writingCounter_ == 0)
|
||||
else
|
||||
{
|
||||
index_++;
|
||||
writingCounter_ = speed_;
|
||||
writing_counter_ = speed_;
|
||||
}
|
||||
|
||||
if (index_ == lenght_)
|
||||
@@ -43,18 +42,10 @@ void Writer::update()
|
||||
completed_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// Completado
|
||||
if (enabledCounter_ > 0)
|
||||
{
|
||||
enabledCounter_--;
|
||||
}
|
||||
else if (enabledCounter_ == 0)
|
||||
{
|
||||
finished_ = true;
|
||||
}
|
||||
enabled_counter_ > 0 ? enabled_counter_-- : finished_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,20 +55,20 @@ void Writer::render() const
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
text_->write(posX_, posY_, caption_, kerning_, index_);
|
||||
text_->write(pos_x_, pos_y_, caption_, kerning_, index_);
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Writer::setPosX(int value)
|
||||
{
|
||||
posX_ = value;
|
||||
pos_x_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Writer::setPosY(int value)
|
||||
{
|
||||
posY_ = value;
|
||||
pos_y_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
@@ -97,7 +88,7 @@ void Writer::setCaption(std::string text)
|
||||
void Writer::setSpeed(int value)
|
||||
{
|
||||
speed_ = value;
|
||||
writingCounter_ = value;
|
||||
writing_counter_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
@@ -115,7 +106,7 @@ bool Writer::IsEnabled() const
|
||||
// Establece el valor de la variable
|
||||
void Writer::setFinishedCounter(int time)
|
||||
{
|
||||
enabledCounter_ = time;
|
||||
enabled_counter_ = time;
|
||||
}
|
||||
|
||||
// Centra la cadena de texto a un punto X
|
||||
|
||||
@@ -12,17 +12,17 @@ private:
|
||||
std::shared_ptr<Text> text_; // Objeto encargado de escribir el texto
|
||||
|
||||
// Variables
|
||||
int posX_; // 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_x_; // Posicion en el eje X 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
|
||||
std::string caption_; // El texto para escribir
|
||||
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 lenght_; // Longitud de la cadena a escribir
|
||||
bool completed_; // Indica si se ha escrito todo el texto
|
||||
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
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user