Comença a estar tot mes o menos be el desaguisao de les classes Sprite. Encara algunes animacions sembla que van massa ràpides

This commit is contained in:
2024-10-17 19:26:39 +02:00
parent 59de566c5b
commit 50a376e582
12 changed files with 246 additions and 208 deletions

View File

@@ -6,6 +6,10 @@ MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, Rotat
: Sprite(texture, pos),
x_(pos.x),
y_(pos.y),
vx_(0.0f),
vy_(0.0f),
ax_(0.0f),
ay_(0.0f),
rotate_(rotate),
zoom_w_(zoom_w),
zoom_h_(zoom_h),
@@ -15,17 +19,27 @@ MovingSprite::MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos)
: Sprite(texture, pos),
x_(pos.x),
y_(pos.y),
rotate_({false, 0, 0, 0.0f, 0.0f, nullptr}),
vx_(0.0f),
vy_(0.0f),
ax_(0.0f),
ay_(0.0f),
rotate_(Rotate()),
zoom_w_(1.0f),
zoom_h_(1.0f),
flip_(SDL_FLIP_NONE) {}
MovingSprite::MovingSprite(std::shared_ptr<Texture> texture)
: Sprite(texture),
rotate_({false, 0, 0, 0.0f, 0.0f, nullptr}),
x_(0.0f),
y_(0.0f),
vx_(0.0f),
vy_(0.0f),
ax_(0.0f),
ay_(0.0f),
rotate_(Rotate()),
zoom_w_(1.0f),
zoom_h_(1.0f),
flip_(SDL_FLIP_NONE) {}
flip_(SDL_FLIP_NONE) { Sprite::clear(); }
// Reinicia todas las variables
void MovingSprite::clear()
@@ -39,20 +53,14 @@ void MovingSprite::clear()
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
rotate_.enabled = false; // Indica si ha de rotar
rotate_.counter = 0; // Contador
rotate_.speed = 0; // Velocidad de giro
rotate_.angle = 0.0f; // Angulo para dibujarlo
rotate_.amount = 0.0f; // Cantidad de grados a girar en cada iteración
rotate_.center = nullptr; // Centro de rotación
rotate_ = Rotate(); // Inicializa la estructura
zoom_w_ = 1.0f; // Zoom aplicado a la anchura
zoom_h_ = 1.0f; // Zoom aplicado a la altura
flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
setPos((SDL_Rect){0, 0, 0, 0});
setSpriteClip((SDL_Rect){0, 0, 0, 0});
Sprite::clear();
}
// Mueve el sprite
@@ -64,7 +72,8 @@ void MovingSprite::move()
vx_ += ax_;
vy_ += ay_;
syncPos();
pos_.x = static_cast<int>(x_);
pos_.y = static_cast<int>(y_);
}
// Actualiza las variables internas del objeto
@@ -237,8 +246,8 @@ float MovingSprite::getAccelY() const
// Establece la posición y_ el tamaño del objeto
void MovingSprite::setPos(SDL_Rect rect)
{
x_ = (float)rect.x;
y_ = (float)rect.y;
x_ = static_cast<float>(rect.x);
y_ = static_cast<float>(rect.y);
pos_ = rect;
}
@@ -249,21 +258,22 @@ void MovingSprite::setPos(float x, float y)
x_ = x;
y_ = y;
syncPos();
pos_.x = static_cast<int>(x_);
pos_.y = static_cast<int>(y_);
}
// Establece el valor de la variable
void MovingSprite::setPosX(float value)
{
x_ = value;
pos_.x = (int)x_;
pos_.x = static_cast<int>(x_);
}
// Establece el valor de la variable
void MovingSprite::setPosY(float value)
{
y_ = value;
pos_.y = (int)y_;
pos_.y = static_cast<int>(y_);
}
// Establece el valor de la variable
@@ -288,11 +298,4 @@ void MovingSprite::setAccelX(float value)
void MovingSprite::setAccelY(float value)
{
ay_ = value;
}
// Sincroniza la posición
void MovingSprite::syncPos()
{
pos_.x = (int)x_;
pos_.y = (int)y_;
}
}