Commit pa que Mon arregle el codi mentre em dutxe

This commit is contained in:
2024-10-09 21:48:01 +02:00
parent 3c1dcad3ab
commit f2fa216b0d
34 changed files with 862 additions and 1218 deletions

View File

@@ -1,101 +1,68 @@
#include "smart_sprite.h"
#include "moving_sprite.h" // for MovingSprite
#include "moving_sprite.h" // for MovingSprite
class Texture;
// Constructor
SmartSprite::SmartSprite(Texture *texture)
SmartSprite::SmartSprite(std::shared_ptr<Texture> texture)
{
// Copia punteros
setTexture(texture);
// Inicializa el objeto
init();
}
// Inicializa el objeto
void SmartSprite::init()
{
enabled = false;
enabledCounter = 0;
onDestination = false;
destX = 0;
destY = 0;
counter = 0;
finished = false;
finishedCounter_ = 0;
onDestination_ = false;
destX_ = 0;
destY_ = 0;
finished_ = false;
}
// Actualiza la posición y comprueba si ha llegado a su destino
void SmartSprite::update()
{
if (enabled)
{
// Actualiza las variables internas del objeto
MovingSprite::update();
// Comprueba el movimiento
checkMove();
// Comprueba si ha terminado
checkFinished();
}
MovingSprite::update();
checkMove();
checkFinished();
}
// Pinta el objeto en pantalla
void SmartSprite::render()
{
if (enabled)
{
// Muestra el sprite por pantalla
MovingSprite::render();
}
}
// Obtiene el valor de la variable
bool SmartSprite::isEnabled()
{
return enabled;
MovingSprite::render();
}
// Establece el valor de la variable
void SmartSprite::setEnabled(bool enabled)
void SmartSprite::setFinishedCounter(int value)
{
this->enabled = enabled;
}
// Obtiene el valor de la variable
int SmartSprite::getEnabledCounter()
{
return enabledCounter;
}
// Establece el valor de la variable
void SmartSprite::setEnabledCounter(int value)
{
enabledCounter = value;
finishedCounter_ = value;
}
// Establece el valor de la variable
void SmartSprite::setDestX(int x)
{
destX = x;
destX_ = x;
}
// Establece el valor de la variable
void SmartSprite::setDestY(int y)
{
destY = y;
destY_ = y;
}
// Obtiene el valor de la variable
int SmartSprite::getDestX()
int SmartSprite::getDestX() const
{
return destX;
return destX_;
}
// Obtiene el valor de la variable
int SmartSprite::getDestY()
int SmartSprite::getDestY() const
{
return destY;
return destY_;
}
// Comprueba el movimiento
@@ -105,10 +72,10 @@ void SmartSprite::checkMove()
if (getAccelX() > 0 || getVelX() > 0)
{
// Comprueba si ha llegado al destino
if (getPosX() > destX)
if (getPosX() > destX_)
{
// Lo coloca en posición
setPosX(destX);
setPosX(destX_);
// Lo detiene
setVelX(0.0f);
@@ -119,10 +86,10 @@ void SmartSprite::checkMove()
else if (getAccelX() < 0 || getVelX() < 0)
{
// Comprueba si ha llegado al destino
if (getPosX() < destX)
if (getPosX() < destX_)
{
// Lo coloca en posición
setPosX(destX);
setPosX(destX_);
// Lo detiene
setVelX(0.0f);
@@ -134,10 +101,10 @@ void SmartSprite::checkMove()
if (getAccelY() > 0 || getVelY() > 0)
{
// Comprueba si ha llegado al destino
if (getPosY() > destY)
if (getPosY() > destY_)
{
// Lo coloca en posición
setPosY(destY);
setPosY(destY_);
// Lo detiene
setVelY(0.0f);
@@ -148,10 +115,10 @@ void SmartSprite::checkMove()
else if (getAccelY() < 0 || getVelY() < 0)
{
// Comprueba si ha llegado al destino
if (getPosY() < destY)
if (getPosY() < destY_)
{
// Lo coloca en posición
setPosY(destY);
setPosY(destY_);
// Lo detiene
setVelY(0.0f);
@@ -164,29 +131,29 @@ void SmartSprite::checkMove()
void SmartSprite::checkFinished()
{
// Comprueba si ha llegado a su destino
onDestination = (getPosX() == destX && getPosY() == destY) ? true : false;
onDestination_ = (getPosX() == destX_ && getPosY() == destY_) ? true : false;
if (onDestination)
{ // Si esta en el destino comprueba su contador
if (enabledCounter == 0)
{ // Si ha llegado a cero, deshabilita el objeto y lo marca como finalizado
finished = true;
if (onDestination_)
{
if (finishedCounter_ == 0)
{
finished_ = true;
}
else
{ // Si no ha llegado a cero, decrementa el contador
enabledCounter--;
{
--finishedCounter_;
}
}
}
// Obtiene el valor de la variable
bool SmartSprite::isOnDestination()
bool SmartSprite::isOnDestination() const
{
return onDestination;
return onDestination_;
}
// Obtiene el valor de la variable
bool SmartSprite::hasFinished()
bool SmartSprite::hasFinished() const
{
return finished;
return finished_;
}