Afegides classes SSprite, SMovingSprite i SAnimatedSprite

This commit is contained in:
2025-03-02 19:29:48 +01:00
parent 636b91ae6f
commit db3a0d7263
6 changed files with 632 additions and 0 deletions

45
source/s_sprite.cpp Normal file
View File

@@ -0,0 +1,45 @@
#include "s_sprite.h"
#include "surface.h" // Para Surface
// Constructor
SSprite::SSprite(std::shared_ptr<Surface> surface, int x, int y, int w, int h)
: surface_(surface),
pos_((SDL_Rect){x, y, w, h}),
clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
SSprite::SSprite(std::shared_ptr<Surface> surface, SDL_Rect rect)
: surface_(surface),
pos_(rect),
clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
SSprite::SSprite(std::shared_ptr<Surface> surface)
: surface_(surface),
pos_({0, 0, surface_->getWidth(), surface_->getHeight()}),
clip_(pos_) {}
// Muestra el sprite por pantalla
void SSprite::render()
{
surface_->render(pos_.x, pos_.y, &clip_);
}
// Establece la posición del objeto
void SSprite::setPosition(int x, int y)
{
pos_.x = x;
pos_.y = y;
}
// Establece la posición del objeto
void SSprite::setPosition(SDL_Point p)
{
pos_.x = p.x;
pos_.y = p.y;
}
// Reinicia las variables a cero
void SSprite::clear()
{
pos_ = {0, 0, 0, 0};
clip_ = {0, 0, 0, 0};
}