From e523692e992115f386e7314d6d78e7b353f1b78f Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 8 Mar 2025 17:47:13 +0100 Subject: [PATCH] Els sprites de la intro ja apareixen i desapareixen com en el CC original --- source/moving_sprite.cpp | 102 +-------------------------------------- source/moving_sprite.h | 32 ++++++------ source/smart_sprite.cpp | 39 +++------------ source/smart_sprite.h | 35 +++++--------- 4 files changed, 36 insertions(+), 172 deletions(-) diff --git a/source/moving_sprite.cpp b/source/moving_sprite.cpp index ce166dd..91d029b 100644 --- a/source/moving_sprite.cpp +++ b/source/moving_sprite.cpp @@ -73,46 +73,7 @@ void MovingSprite::update() } // Muestra el sprite por pantalla -void MovingSprite::render() -{ - texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_); -} - -// Establece el valor de la variable -void MovingSprite::setZoomW(float value) -{ - zoom_w_ = value; -} - -// Establece el valor de la variable -void MovingSprite::setZoomH(float value) -{ - zoom_h_ = value; -} - -// Establece el valor de la variable -void MovingSprite::setAngle(double value) -{ - rotate_.angle = value; -} - -// Establece el valor de la variable -void MovingSprite::setRotatingCenter(SDL_Point *point) -{ - rotate_.center = point; -} - -// Incrementa el valor del ángulo -void MovingSprite::updateAngle() -{ - rotate_.angle += rotate_.amount; -} - -// Obtiene el valor de la variable -bool MovingSprite::isRotating() const -{ - return rotate_.enabled; -} +void MovingSprite::render() { texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_); } // Establece la rotacion void MovingSprite::rotate() @@ -135,43 +96,6 @@ void MovingSprite::setRotate(bool enable) rotate_.counter = 0; } -// Establece el valor de la variable -void MovingSprite::setRotateSpeed(int value) -{ - rotate_.speed = std::max(1, value); -} - -// Establece el valor de la variable -void MovingSprite::setRotateAmount(double value) -{ - rotate_.amount = value; -} - -// Cambia el sentido de la rotación -void MovingSprite::switchRotate() -{ - rotate_.amount *= -1; -} - -// Establece el valor de la variable -void MovingSprite::setFlip(SDL_RendererFlip flip) -{ - flip_ = flip; -} - -// Gira el sprite horizontalmente -void MovingSprite::flip() -{ - flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; -} - -// Obtiene el valor de la variable -SDL_RendererFlip MovingSprite::getFlip() -{ - return flip_; -} - - // Establece la posición y_ el tamaño del objeto void MovingSprite::setPos(SDL_Rect rect) { @@ -203,28 +127,4 @@ void MovingSprite::setPosY(float value) { y_ = value; pos_.y = static_cast(y_); -} - -// Establece el valor de la variable -void MovingSprite::setVelX(float value) -{ - vx_ = value; -} - -// Establece el valor de la variable -void MovingSprite::setVelY(float value) -{ - vy_ = value; -} - -// Establece el valor de la variable -void MovingSprite::setAccelX(float value) -{ - ax_ = value; -} - -// Establece el valor de la variable -void MovingSprite::setAccelY(float value) -{ - ay_ = value; } \ No newline at end of file diff --git a/source/moving_sprite.h b/source/moving_sprite.h index 90ca717..8010031 100644 --- a/source/moving_sprite.h +++ b/source/moving_sprite.h @@ -38,7 +38,7 @@ protected: SDL_RendererFlip flip_; // Indica como se voltea el sprite // Incrementa el valor del ángulo - void updateAngle(); + void updateAngle() { rotate_.angle += rotate_.amount; } // Mueve el sprite void move(); @@ -73,40 +73,40 @@ public: float getAccelY() const { return ay_; } // Establece la variable - void setVelX(float value); - void setVelY(float value); - void setAccelX(float value); - void setAccelY(float value); + void setVelX(float value) { vx_ = value; } + void setVelY(float value) { vy_ = value; } + void setAccelX(float value) { ax_ = value; } + void setAccelY(float value) { ay_ = value; } // Obten el valor de la variable - bool isRotating() const; + bool isRotating() const { return rotate_.enabled; } // Establece el valor de la variable - void setZoomW(float value); - void setZoomH(float value); + void setZoomW(float value) { zoom_w_ = value; } + void setZoomH(float value) { zoom_h_ = value; } // Establece el valor de la variable - void setAngle(double vaue); - void setRotatingCenter(SDL_Point *point); + void setAngle(double value) { rotate_.angle = value; } + void setRotatingCenter(SDL_Point *point) { rotate_.center = point; } // Activa o desactiva el efecto de rotación void setRotate(bool enable); // Establece el valor de la variable - void setRotateSpeed(int value); - void setRotateAmount(double value); + void setRotateSpeed(int value) { rotate_.speed = std::max(1, value); } + void setRotateAmount(double value) { rotate_.amount = value; } // Cambia el sentido de la rotación - void switchRotate(); + void switchRotate() { rotate_.amount *= -1; } // Establece el valor de la variable - void setFlip(SDL_RendererFlip flip); + void setFlip(SDL_RendererFlip flip) { flip_ = flip; } // Gira el sprite horizontalmente - void flip(); + void flip() { flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; } // Obtiene el valor de la variable - SDL_RendererFlip getFlip(); + SDL_RendererFlip getFlip() { return flip_; } // Establece la posición y_ el tamaño del objeto void setPos(SDL_Rect rect); diff --git a/source/smart_sprite.cpp b/source/smart_sprite.cpp index fa208e8..bf2a790 100644 --- a/source/smart_sprite.cpp +++ b/source/smart_sprite.cpp @@ -17,22 +17,13 @@ void SmartSprite::update() } } -// Establece el valor de la variable -void SmartSprite::setFinishedCounter(int value) +// Dibuja el sprite +void SmartSprite::render() { - finished_counter_ = value; -} - -// Establece el valor de la variable -void SmartSprite::setDestX(int x) -{ - dest_x_ = x; -} - -// Establece el valor de la variable -void SmartSprite::setDestY(int y) -{ - dest_y_ = y; + if (enabled_) + { + MovingSprite::render(); + } } // Comprueba el movimiento @@ -114,22 +105,4 @@ void SmartSprite::checkFinished() --finished_counter_; } } -} - -// Obtiene el valor de la variable -bool SmartSprite::isOnDestination() const -{ - return on_destination_; -} - -// Obtiene el valor de la variable -bool SmartSprite::hasFinished() const -{ - return finished_; -} - -// Habilita el objeto -void SmartSprite::setEnabled(bool value) -{ - enabled_ = value; } \ No newline at end of file diff --git a/source/smart_sprite.h b/source/smart_sprite.h index a2e3de3..321239d 100644 --- a/source/smart_sprite.h +++ b/source/smart_sprite.h @@ -32,27 +32,18 @@ public: // Actualiza la posición y comprueba si ha llegado a su destino void update() override; - // Establece el valor de la variable - void setFinishedCounter(int value); + // Dibuja el sprite + void render(); - // Establece el valor de la variable - void setDestX(int x); - - // Establece el valor de la variable - void setDestY(int y); - - // Obtiene el valor de la variable - int getDestX() const; - - // Obtiene el valor de la variable - int getDestY() const; - - // Obtiene el valor de la variable - bool isOnDestination() const; - - // Obtiene el valor de la variable - bool hasFinished() const; - - // Habilita el objeto - void setEnabled(bool value); + // Getters + int getDestX() const { return dest_x_; } + int getDestY() const { return dest_y_; } + bool isOnDestination() const { return on_destination_; } + bool hasFinished() const { return finished_; } + + // Setters + void setFinishedCounter(int value) { finished_counter_ = value; } + void setDestX(int x) { dest_x_ = x; } + void setDestY(int y) { dest_y_ = y; } + void setEnabled(bool value) { enabled_ = value; } }; \ No newline at end of file