Throw coffe with rotation and time stop with clock sound

This commit is contained in:
2021-04-04 12:31:48 +02:00
parent 4980c0f712
commit d84137daa7
10 changed files with 172 additions and 41 deletions

View File

@@ -38,6 +38,12 @@ void SmartSprite::init(LTexture *texture, SDL_Renderer *renderer)
mDestX = 0;
mDestY = 0;
setRotate(false);
setRotateSpeed(0);
setRotateAmount(0.0);
mCounter = 0;
// El Id siempre es >=0, por lo tanto si no se le asigna Id se queda en negativo
mId = -1;
@@ -65,13 +71,13 @@ void SmartSprite::setEnabled(bool state)
// Obtiene el valor de la variable
Uint16 SmartSprite::getEnabledTimer()
{
return mEnabledTimer;
return mEnabledCounter;
}
// Establece el valor de la variable
void SmartSprite::setEnabledTimer(Uint16 time)
{
mEnabledTimer = time;
mEnabledCounter = time;
}
// Establece el valor de la variable
@@ -86,6 +92,24 @@ void SmartSprite::setDestY(int value)
mDestY = value;
}
// Establece el valor de la variable
void SmartSprite::setRotate(bool value)
{
mRotate = value;
}
// Establece el valor de la variable
void SmartSprite::setRotateSpeed(Uint16 value)
{
mRotateSpeed = value;
}
// Establece el valor de la variable
void SmartSprite::setRotateAmount(double value)
{
mRotateAmount = value;
}
// Obtiene el valor de la variable
int SmartSprite::getDestX()
{
@@ -98,12 +122,37 @@ int SmartSprite::getDestY()
return mDestY;
}
// Obtiene el valor de la variable
bool SmartSprite::getRotate()
{
return mRotate;
}
// Obtiene el valor de la variable
Uint16 SmartSprite::getRotateSpeed()
{
return mRotateSpeed;
}
// Establece la rotacion
void SmartSprite::rotate()
{
if (mRotate)
{
if (mCounter % mRotateSpeed == 0)
{
incAngle(mRotateAmount);
}
}
}
// Actualiza la posición y comprueba si ha llegado a su destino
bool SmartSprite::update()
{
if (mEnabled)
{
move();
rotate();
// Comprueba si se desplaza en el eje X hacia la derecha
if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0)))
@@ -178,12 +227,12 @@ bool SmartSprite::update()
if (mIsOnDestination)
{
// Si el contador es mayor que cero, lo decrementa
if (mEnabledTimer > 0)
if (mEnabledCounter > 0)
{
--mEnabledTimer;
--mEnabledCounter;
}
// Si ha llegado a cero, deshabilita el objeto o manda el aviso en función de si tiene Id
else if (mEnabledTimer == 0)
else if (mEnabledCounter == 0)
{
if (mId < 0)
{
@@ -195,6 +244,9 @@ bool SmartSprite::update()
}
}
}
mCounter++;
mCounter %= 65000;
}
return mIsOnDestination;