INTRO optimizada y revisada
This commit is contained in:
@@ -4,36 +4,17 @@
|
||||
// Constructor
|
||||
SmartSprite::SmartSprite(LTexture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Copia punteros
|
||||
setTexture(texture);
|
||||
setRenderer(renderer);
|
||||
|
||||
// BORRABLE ***
|
||||
setPosX(0);
|
||||
setPosY(0);
|
||||
setWidth(0);
|
||||
setHeight(0);
|
||||
|
||||
setVelX(0);
|
||||
setVelY(0);
|
||||
setAccelX(0);
|
||||
setAccelY(0);
|
||||
|
||||
setSpriteClip(0, 0, 0, 0);
|
||||
|
||||
setRotate(false);
|
||||
setRotateSpeed(0);
|
||||
setRotateAmount(0.0);
|
||||
|
||||
setEnabled(false);
|
||||
setEnabledCounter(0);
|
||||
// HASTA AQUI
|
||||
|
||||
// Inicializa variables
|
||||
enabled = false;
|
||||
enabledCounter = 0;
|
||||
onDestination = false;
|
||||
destX = 0;
|
||||
destY = 0;
|
||||
|
||||
counter = 0;
|
||||
id = 0;
|
||||
finished = false;
|
||||
}
|
||||
|
||||
@@ -42,11 +23,28 @@ SmartSprite::~SmartSprite()
|
||||
{
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void SmartSprite::render()
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
// Muestra el sprite por pantalla
|
||||
MovingSprite::render();
|
||||
}
|
||||
}
|
||||
@@ -103,7 +101,7 @@ int SmartSprite::getDestY()
|
||||
void SmartSprite::checkMove()
|
||||
{
|
||||
// Comprueba si se desplaza en el eje X hacia la derecha
|
||||
if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0)))
|
||||
if (getAccelX() > 0 || getVelX() > 0)
|
||||
{
|
||||
// Comprueba si ha llegado al destino
|
||||
if (getPosX() > destX)
|
||||
@@ -117,7 +115,7 @@ void SmartSprite::checkMove()
|
||||
}
|
||||
}
|
||||
// Comprueba si se desplaza en el eje X hacia la izquierda
|
||||
else if ((getAccelX() < 0) || ((getAccelX() == 0) && (getVelX() < 0)))
|
||||
else if (getAccelX() < 0 || getVelX() < 0)
|
||||
{
|
||||
// Comprueba si ha llegado al destino
|
||||
if (getPosX() < destX)
|
||||
@@ -132,7 +130,7 @@ void SmartSprite::checkMove()
|
||||
}
|
||||
|
||||
// Comprueba si se desplaza en el eje Y hacia abajo
|
||||
if ((getAccelY() > 0) || ((getAccelY() == 0) && (getVelY() > 0)))
|
||||
if (getAccelY() > 0 || getVelY() > 0)
|
||||
{
|
||||
// Comprueba si ha llegado al destino
|
||||
if (getPosY() > destY)
|
||||
@@ -146,7 +144,7 @@ void SmartSprite::checkMove()
|
||||
}
|
||||
}
|
||||
// Comprueba si se desplaza en el eje Y hacia arriba
|
||||
else if ((getAccelY() < 0) || ((getAccelY() == 0) && (getVelY() < 0)))
|
||||
else if (getAccelY() < 0 || getVelY() < 0)
|
||||
{
|
||||
// Comprueba si ha llegado al destino
|
||||
if (getPosY() < destY)
|
||||
@@ -161,20 +159,9 @@ void SmartSprite::checkMove()
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||
void SmartSprite::update()
|
||||
// Comprueba si ha terminado
|
||||
void SmartSprite::checkFinished()
|
||||
{
|
||||
if (!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
MovingSprite::update();
|
||||
|
||||
// Comprueba el movimiento
|
||||
checkMove();
|
||||
|
||||
// Comprueba si ha llegado a su destino
|
||||
onDestination = (getPosX() == destX && getPosY() == destY) ? true : false;
|
||||
|
||||
@@ -182,7 +169,6 @@ void SmartSprite::update()
|
||||
{ // Si esta en el destino comprueba su contador
|
||||
if (enabledCounter == 0)
|
||||
{ // Si ha llegado a cero, deshabilita el objeto y lo marca como finalizado
|
||||
//enabled = false;
|
||||
finished = true;
|
||||
}
|
||||
else
|
||||
@@ -198,18 +184,6 @@ bool SmartSprite::isOnDestination()
|
||||
return onDestination;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void SmartSprite::setId(int id)
|
||||
{
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int SmartSprite::getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool SmartSprite::hasFinished()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user