Redistribuits els .cpp en carpetes

Actualitzat cmake
Modificats els include de SDL2 a SDL3
This commit is contained in:
2025-10-15 08:28:57 +02:00
parent c3415fd106
commit 78c5333144
86 changed files with 6757 additions and 7610 deletions

View File

@@ -0,0 +1,102 @@
#include "s_moving_sprite.h"
#include "surface.h" // Para Surface
// Constructor
SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface, SDL_Rect pos, SDL_RendererFlip flip)
: SSprite(surface, pos),
x_(pos.x),
y_(pos.y),
flip_(flip) { SSprite::pos_ = pos; }
SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface, SDL_Rect pos)
: SSprite(surface, pos),
x_(pos.x),
y_(pos.y),
flip_(SDL_FLIP_NONE) { SSprite::pos_ = pos; }
SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface)
: SSprite(surface),
x_(0.0f),
y_(0.0f),
flip_(SDL_FLIP_NONE) { SSprite::clear(); }
// Reinicia todas las variables
void SMovingSprite::clear()
{
x_ = 0.0f; // Posición en el eje X
y_ = 0.0f; // Posición en el eje Y
vx_ = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
vy_ = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
ax_ = 0.0f; // Aceleración en el eje X. Variación de la velocidad
ay_ = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
SSprite::clear();
}
// Mueve el sprite
void SMovingSprite::move()
{
x_ += vx_;
y_ += vy_;
vx_ += ax_;
vy_ += ay_;
pos_.x = static_cast<int>(x_);
pos_.y = static_cast<int>(y_);
}
// Actualiza las variables internas del objeto
void SMovingSprite::update()
{
move();
}
// Muestra el sprite por pantalla
void SMovingSprite::render()
{
surface_->render(pos_.x, pos_.y, &clip_, flip_);
}
// Muestra el sprite por pantalla
void SMovingSprite::render(Uint8 source_color, Uint8 target_color)
{
surface_->renderWithColorReplace(pos_.x, pos_.y, source_color, target_color, &clip_, flip_);
}
// Establece la posición y_ el tamaño del objeto
void SMovingSprite::setPos(SDL_Rect rect)
{
x_ = static_cast<float>(rect.x);
y_ = static_cast<float>(rect.y);
pos_ = rect;
}
// Establece el valor de las variables
void SMovingSprite::setPos(float x, float y)
{
x_ = x;
y_ = y;
pos_.x = static_cast<int>(x_);
pos_.y = static_cast<int>(y_);
}
// Establece el valor de la variable
void SMovingSprite::setPosX(float value)
{
x_ = value;
pos_.x = static_cast<int>(x_);
}
// Establece el valor de la variable
void SMovingSprite::setPosY(float value)
{
y_ = value;
pos_.y = static_cast<int>(y_);
}