canvi de pc
This commit is contained in:
@@ -2,201 +2,44 @@
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Constructor
|
||||
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Establece la posición X,Y del sprite
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture, int x, int y, int w, int h)
|
||||
: texture_(texture),
|
||||
pos_((SDL_Rect){x, y, w, h}),
|
||||
clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
||||
|
||||
// Establece el alto y el ancho del sprite
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture, SDL_Rect rect)
|
||||
: texture_(texture),
|
||||
pos_(rect),
|
||||
clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {}
|
||||
|
||||
// Establece el puntero al renderizador de la ventana
|
||||
this->renderer = renderer;
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
this->texture = texture;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
spriteClip = {0, 0, w, h};
|
||||
|
||||
// Inicializa variables
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
// Establece la posición X,Y del sprite
|
||||
this->x = rect.x;
|
||||
this->y = rect.y;
|
||||
|
||||
// Establece el alto y el ancho del sprite
|
||||
this->w = rect.w;
|
||||
this->h = rect.h;
|
||||
|
||||
// Establece el puntero al renderizador de la ventana
|
||||
this->renderer = renderer;
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
this->texture = texture;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
spriteClip = {0, 0, w, h};
|
||||
|
||||
// Inicializa variables
|
||||
enabled = true;
|
||||
}
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture)
|
||||
: texture_(texture),
|
||||
pos_({0, 0, texture_->getWidth(), texture_->getHeight()}),
|
||||
clip_(pos_) {}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void Sprite::render()
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
texture->render(renderer, x, y, &spriteClip);
|
||||
}
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosX()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getWidth()
|
||||
{
|
||||
return w;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getHeight()
|
||||
{
|
||||
return h;
|
||||
texture_->render(pos_.x, pos_.y, &clip_, zoom_, zoom_);
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPos(SDL_Rect rect)
|
||||
void Sprite::setPosition(int x, int y)
|
||||
{
|
||||
this->x = rect.x;
|
||||
this->y = rect.y;
|
||||
pos_.x = x;
|
||||
pos_.y = y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setPosX(int x)
|
||||
// Establece la posición del objeto
|
||||
void Sprite::setPosition(SDL_Point p)
|
||||
{
|
||||
this->x = x;
|
||||
pos_.x = p.x;
|
||||
pos_.y = p.y;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setPosY(int y)
|
||||
// Reinicia las variables a cero
|
||||
void Sprite::clear()
|
||||
{
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void Sprite::incPosX(int value)
|
||||
{
|
||||
x += value;
|
||||
}
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void Sprite::incPosY(int value)
|
||||
{
|
||||
y += value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setWidth(int w)
|
||||
{
|
||||
this->w = w;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setHeight(int h)
|
||||
{
|
||||
this->h = h;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect Sprite::getSpriteClip()
|
||||
{
|
||||
return spriteClip;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(SDL_Rect rect)
|
||||
{
|
||||
spriteClip = rect;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setSpriteClip(int x, int y, int w, int h)
|
||||
{
|
||||
if (w == -1 || h == -1)
|
||||
{
|
||||
spriteClip = {x, y, this->w, this->h};
|
||||
}
|
||||
else
|
||||
{
|
||||
spriteClip = {x, y, w, h};
|
||||
}
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
Texture *Sprite::getTexture()
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setTexture(Texture *texture)
|
||||
{
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setRenderer(SDL_Renderer *renderer)
|
||||
{
|
||||
this->renderer = renderer;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Renderer *Sprite::getRenderer()
|
||||
{
|
||||
return renderer;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Sprite::setEnabled(bool value)
|
||||
{
|
||||
enabled = value;
|
||||
}
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool Sprite::isEnabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect Sprite::getRect()
|
||||
{
|
||||
SDL_Rect rect = {x, y, w, h};
|
||||
return rect;
|
||||
}
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void Sprite::setRect(SDL_Rect rect)
|
||||
{
|
||||
x = rect.x;
|
||||
y = rect.y;
|
||||
w = rect.w;
|
||||
h = rect.h;
|
||||
pos_ = {0, 0, 0, 0};
|
||||
clip_ = {0, 0, 0, 0};
|
||||
}
|
||||
Reference in New Issue
Block a user