diff --git a/source/instructions.cpp b/source/instructions.cpp index 04cea66..e2a923a 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -31,7 +31,7 @@ Instructions::Instructions() // Crea objetos text_ = std::make_unique(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt")); - tiled_bg_ = std::make_unique((SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_STATIC); + tiled_bg_ = std::make_unique((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::STATIC); fade_ = std::make_unique(); // Crea un backbuffer para el renderizador diff --git a/source/tiled_bg.cpp b/source/tiled_bg.cpp index c8fd6a3..10dd1ab 100644 --- a/source/tiled_bg.cpp +++ b/source/tiled_bg.cpp @@ -9,11 +9,11 @@ #include "texture.h" // for Texture // Constructor -TiledBG::TiledBG(SDL_Rect pos, int mode) +TiledBG::TiledBG(SDL_Rect pos, TiledBGMode mode) : renderer_(Screen::get()->getRenderer()), pos_(pos), counter_(0), - mode_(mode == TILED_MODE_RANDOM ? rand() % 2 : mode) + mode_(mode == TiledBGMode::RANDOM ? static_cast(rand() % 2) : mode) { // Crea la textura para el mosaico de fondo canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, pos_.w * 2, pos_.h * 2); @@ -75,16 +75,23 @@ void TiledBG::render() // Actualiza la lógica de la clase void TiledBG::update() { - if (mode_ == TILED_MODE_DIAGONAL) + switch (mode_) + { + case TiledBGMode::DIAGONAL: { // El tileado de fondo se desplaza en diagonal ++window_.x %= TILE_WIDTH_; ++window_.y %= TILE_HEIGHT_; + break; } - else if (mode_ == TILED_MODE_CIRCLE) + case TiledBGMode::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)); + break; + } + default: + break; } } diff --git a/source/tiled_bg.h b/source/tiled_bg.h index a7089cf..578e2de 100644 --- a/source/tiled_bg.h +++ b/source/tiled_bg.h @@ -5,10 +5,13 @@ #include // for string, basic_string // Modos de funcionamiento para el tileado de fondo -#define TILED_MODE_CIRCLE 0 -#define TILED_MODE_DIAGONAL 1 -#define TILED_MODE_RANDOM 2 -#define TILED_MODE_STATIC 3 +enum class TiledBGMode : int +{ + CIRCLE = 0, + DIAGONAL = 1, + RANDOM = 2, + STATIC = 3, +}; /* Esta clase dibuja un tileado de fondo. Para ello se sirve de una textura "canvas", que rellena con los tiles. @@ -32,7 +35,7 @@ private: // Variables SDL_Rect pos_; // Posición y tamaño del mosaico int counter_; // Contador - int mode_; // Tipo de movimiento del mosaico + TiledBGMode mode_; // Tipo de movimiento del mosaico float sin_[360]; // Vector con los valores del seno precalculados // Rellena la textura con el contenido @@ -40,7 +43,7 @@ private: public: // Constructor - TiledBG(SDL_Rect pos, int mode); + TiledBG(SDL_Rect pos, TiledBGMode mode); // Destructor ~TiledBG(); diff --git a/source/title.cpp b/source/title.cpp index ddcd731..357f526 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -36,7 +36,7 @@ Title::Title() mini_logo_texture_ = Resource::get()->getTexture("logo_jailgames_mini.png"); mini_logo_sprite_ = std::make_unique(mini_logo_texture_, param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight()); - tiled_bg_ = std::make_unique((SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM); + tiled_bg_ = std::make_unique((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::RANDOM); game_logo_ = std::make_unique(param.game.game_area.center_x, param.title.title_c_c_position); game_logo_->enable();