Arreglades les herencies de Sprite
Abans de llevar mil coses que sobren i replantejar-se estes 4 classes
This commit is contained in:
@@ -2,121 +2,108 @@
|
||||
|
||||
// Constructor
|
||||
Sprite::Sprite(int x, int y, int w, int h, std::shared_ptr<Texture> texture)
|
||||
: x_(x), y_(y), w_(w), h_(h), texture_(texture)
|
||||
{
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
spriteClip_ = {0, 0, w, h};
|
||||
|
||||
// Inicializa variables
|
||||
enabled_ = true;
|
||||
}
|
||||
: texture_(texture),
|
||||
pos_((SDL_Rect){x, y, w, h}),
|
||||
sprite_clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
||||
|
||||
Sprite::Sprite(SDL_Rect rect, std::shared_ptr<Texture> texture)
|
||||
: x_(rect.x), y_(rect.y), w_(rect.w), h_(rect.h), texture_(texture)
|
||||
{
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
spriteClip_ = {0, 0, w_, h_};
|
||||
: texture_(texture),
|
||||
pos_(rect),
|
||||
sprite_clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
||||
|
||||
// Inicializa variables
|
||||
enabled_ = true;
|
||||
}
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture)
|
||||
: texture_(texture) {}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void Sprite::render()
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
texture_->render(x_, y_, &spriteClip_);
|
||||
}
|
||||
texture_->render(pos_.x, pos_.y, &sprite_clip_);
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosX() const
|
||||
{
|
||||
return x_;
|
||||
return pos_.x;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosY() const
|
||||
{
|
||||
return y_;
|
||||
return pos_.y;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getWidth() const
|
||||
{
|
||||
return w_;
|
||||
return pos_.w;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getHeight() const
|
||||
{
|
||||
return h_;
|
||||
return pos_.h;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPos(int x, int y)
|
||||
{
|
||||
x_ = x;
|
||||
y_ = y;
|
||||
pos_.x = x;
|
||||
pos_.y = y;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPos(SDL_Point p)
|
||||
{
|
||||
x_ = p.x;
|
||||
y_ = p.y;
|
||||
pos_.x = p.x;
|
||||
pos_.y = p.y;
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPos(SDL_Rect r)
|
||||
{
|
||||
x_ = r.x;
|
||||
y_ = r.y;
|
||||
w_ = r.w;
|
||||
h_ = r.h;
|
||||
pos_ = r;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setPosX(int x)
|
||||
{
|
||||
x_ = x;
|
||||
pos_.x = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setPosY(int y)
|
||||
{
|
||||
y_ = y;
|
||||
pos_.y = y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setWidth(int w)
|
||||
{
|
||||
w_ = w;
|
||||
pos_.w = w;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setHeight(int h)
|
||||
{
|
||||
h_ = h;
|
||||
pos_.h = h;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect Sprite::getSpriteClip() const
|
||||
{
|
||||
return spriteClip_;
|
||||
return sprite_clip_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(SDL_Rect rect)
|
||||
{
|
||||
spriteClip_ = rect;
|
||||
sprite_clip_ = rect;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(int x, int y, int w, int h)
|
||||
{
|
||||
spriteClip_ = (SDL_Rect){x, y, w, h};
|
||||
sprite_clip_ = (SDL_Rect){x, y, w, h};
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
@@ -131,32 +118,20 @@ void Sprite::setTexture(std::shared_ptr<Texture> texture)
|
||||
texture_ = texture;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setEnabled(bool value)
|
||||
{
|
||||
enabled_ = value;
|
||||
}
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool Sprite::isEnabled() const
|
||||
{
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect Sprite::getRect() const
|
||||
SDL_Rect Sprite::getPos() const
|
||||
{
|
||||
return (SDL_Rect){x_, y_, w_, h_};
|
||||
return pos_;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void Sprite::incPosX(int value)
|
||||
{
|
||||
x_ += value;
|
||||
pos_.x += value;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void Sprite::incPosY(int value)
|
||||
{
|
||||
y_ += value;
|
||||
pos_.y += value;
|
||||
}
|
||||
Reference in New Issue
Block a user