Files
aee-arcade/source/core/rendering/sprite/moving_sprite.cpp
T
JailDesignerandClaude Opus 4.7 da66a7c03f refactor(core/rendering): netejar ctors de Sprite/MovingSprite (INC-06 + INC-07)
- MovingSprite: el ctor delegat Sprite(surface, pos) ja assigna pos_;
  el Sprite::pos_ = pos; manual que seguia era redundant (INC-06).
- Sprite(surface) usava initializer posicional {0.0F, 0.0F, ...} mentre
  la resta del projecte usa designated initializers ({.x = ..., .y = ...}).
  Unificat (INC-07).

INC-05 (el static_cast<int> de pos_.x a MovingSprite::move i setters)
es marca WONTFIX al document: és snap intencional a píxel per al
pixel-art, divergent només al setter per SDL_FRect que es reserva per
a posicionament directe sense arrodoniment.

Build + smoke 5s xvfb OK (exit 124).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 09:57:17 +02:00

75 lines
1.7 KiB
C++

#include "core/rendering/sprite/moving_sprite.hpp"
#include <utility>
#include "core/rendering/surface.hpp"
MovingSprite::MovingSprite() { Sprite::clear(); }
MovingSprite::MovingSprite(std::shared_ptr<Surface> surface)
: Sprite(std::move(surface)) { Sprite::clear(); }
// pos_ ja queda inicialitzat pel ctor delegat Sprite(surface, pos); només
// cal sincronitzar la posició float x_/y_ (i el flip si ve).
MovingSprite::MovingSprite(std::shared_ptr<Surface> surface, SDL_FRect pos)
: Sprite(std::move(surface), pos),
x_(pos.x),
y_(pos.y) {}
MovingSprite::MovingSprite(std::shared_ptr<Surface> surface, SDL_FRect pos, SDL_FlipMode flip)
: Sprite(std::move(surface), pos),
x_(pos.x),
y_(pos.y),
flip_(flip) {}
void MovingSprite::clear() {
x_ = 0.0F;
y_ = 0.0F;
vx_ = 0.0F;
vy_ = 0.0F;
ax_ = 0.0F;
ay_ = 0.0F;
flip_ = SDL_FLIP_NONE;
Sprite::clear();
}
void MovingSprite::move(float delta_time) {
vx_ += ax_ * delta_time;
vy_ += ay_ * delta_time;
x_ += vx_ * delta_time;
y_ += vy_ * delta_time;
pos_.x = static_cast<int>(x_);
pos_.y = static_cast<int>(y_);
}
void MovingSprite::update(float delta_time) {
move(delta_time);
}
void MovingSprite::render() {
surface_->render(static_cast<int>(pos_.x), static_cast<int>(pos_.y), &clip_, flip_);
}
void MovingSprite::setPos(SDL_FRect rect) {
x_ = rect.x;
y_ = rect.y;
pos_ = rect;
}
void MovingSprite::setPos(float x, float y) {
x_ = x;
y_ = y;
pos_.x = static_cast<int>(x_);
pos_.y = static_cast<int>(y_);
}
void MovingSprite::setPosX(float value) {
x_ = value;
pos_.x = static_cast<int>(x_);
}
void MovingSprite::setPosY(float value) {
y_ = value;
pos_.y = static_cast<int>(y_);
}