Quitadas todas las variables globales y transformadas en punteros

This commit is contained in:
2022-10-20 18:24:12 +02:00
parent 596bf2c4a5
commit b4e76a4c7d
25 changed files with 848 additions and 781 deletions

View File

@@ -1,12 +1,12 @@
#include "spriteanimated.h"
//Constructor
// Constructor
SpriteAnimated::SpriteAnimated()
{
init();
}
//Iniciador
// Iniciador
void SpriteAnimated::init()
{
for (Uint8 i = 0; i < 20; i++)
@@ -25,41 +25,41 @@ void SpriteAnimated::init()
mAnimationCounter = 0;
}
//Calcula el frame correspondiente a la animación
// Calcula el frame correspondiente a la animación
void SpriteAnimated::animate(int index)
{
//Calculamos el frame actual a partir del contador
// Calculamos el frame actual a partir del contador
mCurrentFrame = mAnimationCounter / mAnimation[index].speed;
//Si alcanzamos el final de la animación, reiniciamos el contador de la animación
// Si alcanzamos el final de la animación, reiniciamos el contador de la animación
if (mCurrentFrame >= mAnimation[index].numFrames)
{
mAnimationCounter = 0;
}
//En caso contrario
// En caso contrario
else
{
//Escogemos el frame correspondiente de la animación
// Escogemos el frame correspondiente de la animación
setSpriteClip(mAnimation[index].frames[mCurrentFrame]);
//Incrementamos el contador de la animacion
// Incrementamos el contador de la animacion
++mAnimationCounter;
}
}
//Establece el frame actual de la animación
// Establece el frame actual de la animación
void SpriteAnimated::setCurrentFrame(Uint8 num)
{
mCurrentFrame = num;
}
//Establece el numero de frames de la animacion
// Establece el numero de frames de la animacion
void SpriteAnimated::setAnimationCounter(Uint16 num)
{
mAnimationCounter = num;
}
//Establece el rectangulo para un frame de una animación
// Establece el rectangulo para un frame de una animación
void SpriteAnimated::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
{
mAnimation[index_animation].frames[index_frame].x = x;
@@ -68,19 +68,19 @@ void SpriteAnimated::setAnimationFrames(Uint8 index_animation, Uint8 index_frame
mAnimation[index_animation].frames[index_frame].h = h;
}
//Establece la velocidad de una animación
// Establece la velocidad de una animación
void SpriteAnimated::setAnimationSpeed(Uint8 index, Uint8 speed)
{
mAnimation[index].speed = speed;
}
//Establece el numero de frames de una animación
// Establece el numero de frames de una animación
void SpriteAnimated::setAnimationNumFrames(Uint8 index, Uint8 num)
{
mAnimation[index].numFrames = num;
}
//Devuelve el rectangulo de una animación y frame concreto
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect SpriteAnimated::getAnimationClip(Uint8 index_animation, Uint8 index_frame)
{
return mAnimation[index_animation].frames[index_frame];