Eliminats els últimes defines i passats a enum class

This commit is contained in:
2024-10-20 12:07:55 +02:00
parent 8bca5095da
commit cbc9b3f071
4 changed files with 22 additions and 12 deletions

View File

@@ -31,7 +31,7 @@ Instructions::Instructions()
// Crea objetos // Crea objetos
text_ = std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt")); text_ = std::make_unique<Text>(Resource::get()->getTexture("smb2.gif"), Resource::get()->getTextFile("smb2.txt"));
tiled_bg_ = std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_STATIC); tiled_bg_ = std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::STATIC);
fade_ = std::make_unique<Fade>(); fade_ = std::make_unique<Fade>();
// Crea un backbuffer para el renderizador // Crea un backbuffer para el renderizador

View File

@@ -9,11 +9,11 @@
#include "texture.h" // for Texture #include "texture.h" // for Texture
// Constructor // Constructor
TiledBG::TiledBG(SDL_Rect pos, int mode) TiledBG::TiledBG(SDL_Rect pos, TiledBGMode mode)
: renderer_(Screen::get()->getRenderer()), : renderer_(Screen::get()->getRenderer()),
pos_(pos), pos_(pos),
counter_(0), counter_(0),
mode_(mode == TILED_MODE_RANDOM ? rand() % 2 : mode) mode_(mode == TiledBGMode::RANDOM ? static_cast<TiledBGMode>(rand() % 2) : mode)
{ {
// 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);
@@ -75,16 +75,23 @@ void TiledBG::render()
// 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) switch (mode_)
{
case TiledBGMode::DIAGONAL:
{ // El tileado de fondo se desplaza en diagonal { // El tileado de fondo se desplaza en diagonal
++window_.x %= TILE_WIDTH_; ++window_.x %= TILE_WIDTH_;
++window_.y %= TILE_HEIGHT_; ++window_.y %= TILE_HEIGHT_;
break;
} }
else if (mode_ == TILED_MODE_CIRCLE) case TiledBGMode::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));
break;
}
default:
break;
} }
} }

View File

@@ -5,10 +5,13 @@
#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 enum class TiledBGMode : int
#define TILED_MODE_DIAGONAL 1 {
#define TILED_MODE_RANDOM 2 CIRCLE = 0,
#define TILED_MODE_STATIC 3 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. 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 // Variables
SDL_Rect pos_; // Posición y tamaño del mosaico SDL_Rect pos_; // Posición y tamaño del mosaico
int counter_; // Contador 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 float sin_[360]; // Vector con los valores del seno precalculados
// Rellena la textura con el contenido // Rellena la textura con el contenido
@@ -40,7 +43,7 @@ private:
public: public:
// Constructor // Constructor
TiledBG(SDL_Rect pos, int mode); TiledBG(SDL_Rect pos, TiledBGMode mode);
// Destructor // Destructor
~TiledBG(); ~TiledBG();

View File

@@ -36,7 +36,7 @@ Title::Title()
mini_logo_texture_ = Resource::get()->getTexture("logo_jailgames_mini.png"); mini_logo_texture_ = Resource::get()->getTexture("logo_jailgames_mini.png");
mini_logo_sprite_ = std::make_unique<Sprite>(mini_logo_texture_, param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight()); mini_logo_sprite_ = std::make_unique<Sprite>(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<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM); tiled_bg_ = std::make_unique<TiledBG>((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::RANDOM);
game_logo_ = 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);
game_logo_->enable(); game_logo_->enable();