treball en curs: correccions de tidy
This commit is contained in:
@@ -5,187 +5,187 @@
|
||||
// Constructor
|
||||
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer)
|
||||
: Sprite(0, 0, w, h, texture, renderer),
|
||||
x(x),
|
||||
y(y),
|
||||
xPrev(x),
|
||||
yPrev(y),
|
||||
vx(velx),
|
||||
vy(vely),
|
||||
ax(accelx),
|
||||
ay(accely) {
|
||||
x_(x),
|
||||
y_(y),
|
||||
x_prev_(x),
|
||||
y_prev_(y),
|
||||
vx_(velx),
|
||||
vy_(vely),
|
||||
ax_(accelx),
|
||||
ay_(accely) {
|
||||
}
|
||||
|
||||
// Reinicia todas las variables
|
||||
void MovingSprite::clear() {
|
||||
x = 0.0F; // Posición en el eje X
|
||||
y = 0.0F; // Posición en el eje Y
|
||||
x_ = 0.0F;
|
||||
y_ = 0.0F;
|
||||
|
||||
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
|
||||
vx_ = 0.0F;
|
||||
vy_ = 0.0F;
|
||||
|
||||
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
|
||||
ax_ = 0.0F;
|
||||
ay_ = 0.0F;
|
||||
|
||||
zoomW = 1.0F; // Zoom aplicado a la anchura
|
||||
zoomH = 1.0F; // Zoom aplicado a la altura
|
||||
zoom_w_ = 1.0F;
|
||||
zoom_h_ = 1.0F;
|
||||
|
||||
angle = 0.0; // Angulo para dibujarlo
|
||||
rotateEnabled = false; // Indica si ha de rotar
|
||||
center = nullptr; // Centro de rotación
|
||||
rotateSpeed = 0; // Velocidad de giro
|
||||
rotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
|
||||
counter = 0; // Contador interno
|
||||
angle_ = 0.0;
|
||||
rotate_enabled_ = false;
|
||||
center_ = nullptr;
|
||||
rotate_speed_ = 0;
|
||||
rotate_amount_ = 0.0;
|
||||
counter_ = 0;
|
||||
|
||||
currentFlip = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
||||
current_flip_ = SDL_FLIP_NONE;
|
||||
}
|
||||
|
||||
// Mueve el sprite
|
||||
void MovingSprite::move() {
|
||||
if (enabled) {
|
||||
xPrev = x;
|
||||
yPrev = y;
|
||||
if (enabled_) {
|
||||
x_prev_ = x_;
|
||||
y_prev_ = y_;
|
||||
|
||||
x += vx;
|
||||
y += vy;
|
||||
x_ += vx_;
|
||||
y_ += vy_;
|
||||
|
||||
vx += ax;
|
||||
vy += ay;
|
||||
vx_ += ax_;
|
||||
vy_ += ay_;
|
||||
}
|
||||
}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void MovingSprite::render() {
|
||||
if (enabled) {
|
||||
texture->render(renderer, (int)x, (int)y, &spriteClip, zoomW, zoomH, angle, center, currentFlip);
|
||||
if (enabled_) {
|
||||
texture_->render(renderer_, (int)x_, (int)y_, &sprite_clip_, zoom_w_, zoom_h_, angle_, center_, current_flip_);
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
// cppcheck-suppress duplInheritedMember
|
||||
auto MovingSprite::getPosX() const -> float {
|
||||
return x;
|
||||
return x_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
// cppcheck-suppress duplInheritedMember
|
||||
auto MovingSprite::getPosY() const -> float {
|
||||
return y;
|
||||
return y_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto MovingSprite::getVelX() const -> float {
|
||||
return vx;
|
||||
return vx_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto MovingSprite::getVelY() const -> float {
|
||||
return vy;
|
||||
return vy_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto MovingSprite::getAccelX() const -> float {
|
||||
return ax;
|
||||
return ax_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto MovingSprite::getAccelY() const -> float {
|
||||
return ay;
|
||||
return ay_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto MovingSprite::getZoomW() const -> float {
|
||||
return zoomW;
|
||||
return zoom_w_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto MovingSprite::getZoomH() const -> float {
|
||||
return zoomH;
|
||||
return zoom_h_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto MovingSprite::getAngle() const -> double {
|
||||
return angle;
|
||||
return angle_;
|
||||
}
|
||||
|
||||
// Establece la posición y el tamaño del objeto
|
||||
void MovingSprite::setRect(SDL_Rect rect) {
|
||||
x = (float)rect.x;
|
||||
y = (float)rect.y;
|
||||
w = rect.w;
|
||||
h = rect.h;
|
||||
x_ = (float)rect.x;
|
||||
y_ = (float)rect.y;
|
||||
w_ = rect.w;
|
||||
h_ = rect.h;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosX(float value) {
|
||||
x = value;
|
||||
x_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosY(float value) {
|
||||
y = value;
|
||||
y_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setVelX(float value) {
|
||||
vx = value;
|
||||
vx_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setVelY(float value) {
|
||||
vy = value;
|
||||
vy_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAccelX(float value) {
|
||||
ax = value;
|
||||
ax_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAccelY(float value) {
|
||||
ay = value;
|
||||
ay_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomW(float value) {
|
||||
zoomW = value;
|
||||
zoom_w_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomH(float value) {
|
||||
zoomH = value;
|
||||
zoom_h_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAngle(double value) {
|
||||
angle = value;
|
||||
angle_ = value;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void MovingSprite::incAngle(double value) {
|
||||
angle += value;
|
||||
angle_ += value;
|
||||
}
|
||||
|
||||
// Decrementa el valor de la variable
|
||||
void MovingSprite::decAngle(double value) {
|
||||
angle -= value;
|
||||
angle_ -= value;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto MovingSprite::getRotate() const -> bool {
|
||||
return rotateEnabled;
|
||||
return rotate_enabled_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto MovingSprite::getRotateSpeed() const -> Uint16 {
|
||||
return rotateSpeed;
|
||||
return rotate_speed_;
|
||||
}
|
||||
|
||||
// Establece la rotacion
|
||||
void MovingSprite::rotate() {
|
||||
if (enabled) {
|
||||
if (rotateEnabled) {
|
||||
if (counter % rotateSpeed == 0) {
|
||||
incAngle(rotateAmount);
|
||||
if (enabled_) {
|
||||
if (rotate_enabled_) {
|
||||
if (counter_ % rotate_speed_ == 0) {
|
||||
incAngle(rotate_amount_);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,27 +193,27 @@ void MovingSprite::rotate() {
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotate(bool value) {
|
||||
rotateEnabled = value;
|
||||
rotate_enabled_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateSpeed(int value) {
|
||||
if (value < 1) {
|
||||
rotateSpeed = 1;
|
||||
rotate_speed_ = 1;
|
||||
} else {
|
||||
rotateSpeed = value;
|
||||
rotate_speed_ = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateAmount(double value) {
|
||||
rotateAmount = value;
|
||||
rotate_amount_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::disableRotate() {
|
||||
rotateEnabled = false;
|
||||
angle = (double)0;
|
||||
rotate_enabled_ = false;
|
||||
angle_ = (double)0;
|
||||
}
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
@@ -221,59 +221,59 @@ void MovingSprite::update() {
|
||||
move();
|
||||
rotate();
|
||||
|
||||
if (enabled) {
|
||||
++counter %= 60000;
|
||||
if (enabled_) {
|
||||
++counter_ %= 60000;
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void MovingSprite::switchRotate() {
|
||||
rotateAmount *= -1;
|
||||
rotate_amount_ *= -1;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setFlip(SDL_FlipMode flip) {
|
||||
currentFlip = flip;
|
||||
current_flip_ = flip;
|
||||
}
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void MovingSprite::flip() {
|
||||
currentFlip = (currentFlip == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
|
||||
current_flip_ = (current_flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto MovingSprite::getFlip() -> SDL_FlipMode {
|
||||
return currentFlip;
|
||||
return current_flip_;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
auto MovingSprite::getRect() -> SDL_Rect {
|
||||
const SDL_Rect rect = {(int)x, (int)y, w, h};
|
||||
return rect;
|
||||
const SDL_Rect RECT = {(int)x_, (int)y_, w_, h_};
|
||||
return RECT;
|
||||
}
|
||||
|
||||
// Deshace el último movimiento
|
||||
void MovingSprite::undoMove() {
|
||||
x = xPrev;
|
||||
y = yPrev;
|
||||
x_ = x_prev_;
|
||||
y_ = y_prev_;
|
||||
}
|
||||
|
||||
// Deshace el último movimiento en el eje X
|
||||
void MovingSprite::undoMoveX() {
|
||||
x = xPrev;
|
||||
x_ = x_prev_;
|
||||
}
|
||||
|
||||
// Deshace el último movimiento en el eje Y
|
||||
void MovingSprite::undoMoveY() {
|
||||
y = yPrev;
|
||||
y_ = y_prev_;
|
||||
}
|
||||
|
||||
// Pone a cero las velocidades de desplacamiento
|
||||
void MovingSprite::clearVel() {
|
||||
vx = vy = 0.0F;
|
||||
vx_ = vy_ = 0.0F;
|
||||
}
|
||||
|
||||
// Devuelve el incremento en el eje X en pixels
|
||||
auto MovingSprite::getIncX() const -> int {
|
||||
return (int)x - (int)xPrev;
|
||||
}
|
||||
return (int)x_ - (int)x_prev_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user