Primer commit
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#include "sprite.h"
|
||||
|
||||
// Constructor
|
||||
Sprite::Sprite(Texture *texture)
|
||||
{
|
||||
this->texture = texture;
|
||||
pos = {0, 0, 0, 0};
|
||||
clip = {0, 0, 0, 0};
|
||||
frame = 0;
|
||||
numFrames = 3;
|
||||
animationSpeed = 20;
|
||||
animationCounter = 0;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Sprite::~Sprite()
|
||||
{
|
||||
}
|
||||
|
||||
// Establece la posición del sprite
|
||||
void Sprite::setPos(SDL_Point pos)
|
||||
{
|
||||
this->pos.x = pos.x;
|
||||
this->pos.y = pos.y;
|
||||
}
|
||||
|
||||
// Pinta el sprite
|
||||
void Sprite::render()
|
||||
{
|
||||
texture->render(&clip, &pos);
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
void Sprite::update()
|
||||
{
|
||||
animationCounter++;
|
||||
if (animationCounter % animationSpeed == 0)
|
||||
{
|
||||
animate();
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el rectangulo de la textura que se va a pintar
|
||||
void Sprite::setClip(SDL_Rect clip)
|
||||
{
|
||||
this->clip = clip;
|
||||
}
|
||||
|
||||
// Establece el tamaño del sprite
|
||||
void Sprite::setSize(int w, int h)
|
||||
{
|
||||
this->pos.w = w;
|
||||
this->pos.h = h;
|
||||
}
|
||||
|
||||
// Anima el sprite
|
||||
void Sprite::animate()
|
||||
{
|
||||
frame = (frame + 1) % numFrames;
|
||||
clip.x = frame * pos.w;
|
||||
}
|
||||
|
||||
// Modulación de color
|
||||
void Sprite::setColor(int r, int g, int b)
|
||||
{
|
||||
texture->setColor(r, g, b);
|
||||
}
|
||||
Reference in New Issue
Block a user