cleanup time-based: elimina base classes frame-based (MovingSprite/SmartSprite/AnimatedSprite/Writer/Fade), MovingSprite::update(dt_s) integra rotacio

This commit is contained in:
2026-05-19 18:38:57 +02:00
parent 635662d65d
commit b558ea0b4c
10 changed files with 44 additions and 210 deletions
+9 -39
View File
@@ -34,26 +34,11 @@ void MovingSprite::clear() {
center_ = nullptr;
rotate_speed_ = 0;
rotate_amount_ = 0.0;
counter_ = 0;
current_flip_ = SDL_FLIP_NONE;
}
// Mueve el sprite
void MovingSprite::move() {
if (enabled_) {
x_prev_ = x_;
y_prev_ = y_;
x_ += vx_;
y_ += vy_;
vx_ += ax_;
vy_ += ay_;
}
}
// Time-based: vx_/vy_ en px/s, ax_/ay_ en px/s^2. Integració d'Euler
// Mueve el sprite. vx_/vy_ en px/s, ax_/ay_ en px/s². Integració d'Euler
// senzilla — suficient per a moviments sense col·lisions sensibles.
void MovingSprite::move(float dt_s) {
if (enabled_) {
@@ -195,17 +180,6 @@ auto MovingSprite::getRotateSpeed() const -> Uint16 {
return rotate_speed_;
}
// Establece la rotacion
void MovingSprite::rotate() {
if (enabled_) {
if (rotate_enabled_) {
if (counter_ % rotate_speed_ == 0) {
incAngle(rotate_amount_);
}
}
}
}
// Establece el valor de la variable
void MovingSprite::setRotate(bool value) {
rotate_enabled_ = value;
@@ -231,20 +205,16 @@ void MovingSprite::disableRotate() {
angle_ = (double)0;
}
// Actualiza las variables internas del objeto
void MovingSprite::update() {
move();
rotate();
if (enabled_) {
++counter_ %= 60000;
}
}
// Time-based: nomes move(dt). La rotacio time-based s'integrara quan
// migrem la escena que la requereix (Game/PowerBall).
// Actualiza les variables internes (move + rotació integrada). La rotació
// frame-based original era `incAngle(rotate_amount_)` cada `rotate_speed_`
// frames a 60Hz, equivalent a velocitat angular constant
// = rotate_amount_ * 60 / rotate_speed_ graus/s.
void MovingSprite::update(float dt_s) {
move(dt_s);
if (enabled_ && rotate_enabled_) {
const double ANGULAR_VELOCITY_DEG_PER_S = rotate_amount_ * 60.0 / static_cast<double>(rotate_speed_);
incAngle(ANGULAR_VELOCITY_DEG_PER_S * dt_s);
}
}
// Cambia el sentido de la rotación