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

@@ -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));
}
}