eliminat el punter al renderer de 50.000 llocs

This commit is contained in:
2024-07-28 10:45:14 +02:00
parent 7501b4936f
commit 2948684ad3
58 changed files with 492 additions and 401 deletions

View File

@@ -4,7 +4,7 @@
// Constructor
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer)
{
sprite = new AnimatedSprite(texture, renderer, "", animation);
sprite = new AnimatedSprite(texture, "", animation);
disable();
enabled = true;
@@ -210,14 +210,7 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Añade rotación al sprite
sprite->setRotate(false);
sprite->setRotateSpeed(0);
if (velX > 0.0f)
{
sprite->setRotateAmount(2.0);
}
else
{
sprite->setRotateAmount(-2.0);
}
velX > 0.0f ? sprite->setRotateAmount(2.0) : sprite->setRotateAmount(-2.0);
break;
@@ -289,9 +282,13 @@ void Balloon::allignTo(int x)
posX = float(x - (width / 2));
if (posX < PLAY_AREA_LEFT)
{
posX = PLAY_AREA_LEFT + 1;
}
else if ((posX + width) > PLAY_AREA_RIGHT)
{
posX = float(PLAY_AREA_RIGHT - width - 1);
}
// Posición X,Y del sprite
sprite->setPosX(getPosX());
@@ -304,7 +301,7 @@ void Balloon::allignTo(int x)
// Pinta el globo en la pantalla
void Balloon::render()
{
if ((visible) && (enabled))
if (visible && enabled)
{
if (bouncing.enabled)
{
@@ -325,7 +322,7 @@ void Balloon::render()
sprite->render();
if (kind == POWER_BALL)
{
Sprite *sp = new Sprite(sprite->getRect(), sprite->getTexture(), sprite->getRenderer());
Sprite *sp = new Sprite(sprite->getRect(), sprite->getTexture());
sp->setSpriteClip(407, 0, 37, 37);
sp->render();
delete sp;
@@ -338,7 +335,7 @@ void Balloon::render()
if (kind == POWER_BALL and !popping)
{
Sprite *sp = new Sprite(sprite->getRect(), sprite->getTexture(), sprite->getRenderer());
Sprite *sp = new Sprite(sprite->getRect(), sprite->getTexture());
sp->setSpriteClip(407, 0, 37, 37);
sp->render();
delete sp;
@@ -579,16 +576,16 @@ void Balloon::updateState()
{
stoppedCounter--;
}
// Quitarles el estado "detenido" si no estan explosionando
// Si el contador ha llegado a cero
else if (!isPopping())
{
{ // Quitarles el estado "detenido" si no estan explosionando
setStop(false);
// Si es una powerball vuelve a rodar
if (kind == POWER_BALL)
{
sprite->setRotate(true);
}
setStop(false);
}
}
}
@@ -864,4 +861,16 @@ void Balloon::updateBounce()
bounceStop();
}
}
}
// Indica si el globo se puede explotar
bool Balloon::canBePopped()
{
return isEnabled() && !isPopping() && !isBeingCreated();
}
// Indica si el globo se puede destruir
bool Balloon::canBeDestroyed()
{
return isEnabled() && !isPopping();
}