Afegit zoom a la classe Sprite

This commit is contained in:
2024-12-03 11:39:31 +01:00
parent 1aa0dd3864
commit 3c5bbf2ab0
4 changed files with 33 additions and 128 deletions

View File

@@ -54,7 +54,7 @@ Director::Director(int argc, const char *argv[])
section::name = section::Name::GAME; section::name = section::Name::GAME;
section::options = section::Options::GAME_PLAY_1P; section::options = section::Options::GAME_PLAY_1P;
#elif DEBUG #elif DEBUG
section::name = section::Name::CREDITS; section::name = section::Name::LOGO;
#else // NORMAL GAME #else // NORMAL GAME
section::name = section::Name::LOGO; section::name = section::Name::LOGO;
section::attract_mode = section::AttractMode::TITLE_TO_DEMO; section::attract_mode = section::AttractMode::TITLE_TO_DEMO;

View File

@@ -90,6 +90,9 @@ void GameLogo::init()
dust_left_sprite_->setPosY(y_); dust_left_sprite_->setPosY(y_);
dust_left_sprite_->setWidth(16); dust_left_sprite_->setWidth(16);
dust_left_sprite_->setHeight(16); dust_left_sprite_->setHeight(16);
// Inicializa el bitmap de 'Arcade Edition'
arcade_edition_sprite_->setZoom(2.0f);
} }
// Pinta la clase en pantalla // Pinta la clase en pantalla

View File

@@ -19,31 +19,7 @@ Sprite::Sprite(std::shared_ptr<Texture> texture)
// Muestra el sprite por pantalla // Muestra el sprite por pantalla
void Sprite::render() void Sprite::render()
{ {
texture_->render(pos_.x, pos_.y, &sprite_clip_); texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_, zoom_);
}
// Obten el valor de la variable
int Sprite::getX() const
{
return pos_.x;
}
// Obten el valor de la variable
int Sprite::getY() const
{
return pos_.y;
}
// Obten el valor de la variable
int Sprite::getWidth() const
{
return pos_.w;
}
// Obten el valor de la variable
int Sprite::getHeight() const
{
return pos_.h;
} }
// Establece la posición del objeto // Establece la posición del objeto
@@ -60,84 +36,6 @@ void Sprite::setPosition(SDL_Point p)
pos_.y = p.y; pos_.y = p.y;
} }
// Establece la posición del objeto
void Sprite::setPosition(SDL_Rect r)
{
pos_ = r;
}
// Establece el valor de la variable
void Sprite::setX(int x)
{
pos_.x = x;
}
// Establece el valor de la variable
void Sprite::setY(int y)
{
pos_.y = y;
}
// Establece el valor de la variable
void Sprite::setWidth(int w)
{
pos_.w = w;
}
// Establece el valor de la variable
void Sprite::setHeight(int h)
{
pos_.h = h;
}
// Obten el valor de la variable
SDL_Rect Sprite::getSpriteClip() const
{
return sprite_clip_;
}
// Establece el valor de la variable
void Sprite::setSpriteClip(SDL_Rect rect)
{
sprite_clip_ = rect;
}
// Establece el valor de la variable
void Sprite::setSpriteClip(int x, int y, int w, int h)
{
sprite_clip_ = (SDL_Rect){x, y, w, h};
}
// Obten el valor de la variable
std::shared_ptr<Texture> Sprite::getTexture() const
{
return texture_;
}
// Establece el valor de la variable
void Sprite::setTexture(std::shared_ptr<Texture> texture)
{
texture_ = texture;
}
// Devuelve el rectangulo donde está el sprite
SDL_Rect Sprite::getPosition() const
{
return pos_;
}
// Incrementa el valor de la variable
void Sprite::incX(int value)
{
pos_.x += value;
}
// Incrementa el valor de la variable
void Sprite::incY(int value)
{
pos_.y += value;
}
// Reinicia las variables a cero // Reinicia las variables a cero
void Sprite::clear() void Sprite::clear()
{ {

View File

@@ -12,6 +12,7 @@ protected:
std::shared_ptr<Texture> texture_; // Textura donde estan todos los dibujos del sprite std::shared_ptr<Texture> texture_; // Textura donde estan todos los dibujos del sprite
SDL_Rect pos_; // Posición y tamaño donde dibujar el sprite SDL_Rect pos_; // Posición y tamaño donde dibujar el sprite
SDL_Rect sprite_clip_; // Rectangulo de origen de la textura que se dibujará en pantalla SDL_Rect sprite_clip_; // Rectangulo de origen de la textura que se dibujará en pantalla
double zoom_ = 1.0f; // Zoom aplicado a la textura
public: public:
// Constructor // Constructor
@@ -28,40 +29,43 @@ public:
// Reinicia las variables a cero // Reinicia las variables a cero
virtual void clear(); virtual void clear();
// Obten el valor de la variable // Obtiene la posición y el tamaño
int getX() const; int getX() const { return pos_.x; }
int getY() const; int getY() const { return pos_.y; }
int getWidth() const; int getWidth() const { return pos_.w; }
int getHeight() const; int getHeight() const { return pos_.h; }
// Devuelve el rectangulo donde está el sprite // Devuelve el rectangulo donde está el sprite
SDL_Rect getPosition() const; SDL_Rect getPosition() const { return pos_; }
// Establece el valor de la variable // Establece la posición y el tamaño
void setX(int x); void setX(int x) { pos_.x = x; }
void setY(int y); void setY(int y) { pos_.y = y; }
void setWidth(int w); void setWidth(int w) { pos_.w = w; }
void setHeight(int h); void setHeight(int h) { pos_.h = h; }
// Establece la posición del objeto // Establece la posición del objeto
void setPosition(int x, int y); void setPosition(int x, int y);
void setPosition(SDL_Point p); void setPosition(SDL_Point p);
void setPosition(SDL_Rect r); void setPosition(SDL_Rect r) { pos_ = r; }
// Incrementa el valor de la variable // Establece el nivel de zoom
void incX(int value); void setZoom(float zoom) { zoom_ = zoom; }
void incY(int value);
// Obten el valor de la variable // Aumenta o disminuye la posición
SDL_Rect getSpriteClip() const; void incX(int value) { pos_.x += value; }
void incY(int value) { pos_.y += value; }
// Establece el valor de la variable // Obtiene el rectangulo que se dibuja de la textura
void setSpriteClip(SDL_Rect rect); SDL_Rect getSpriteClip() const { return sprite_clip_; }
void setSpriteClip(int x, int y, int w, int h);
// Obten el valor de la variable // Establece el rectangulo que se dibuja de la textura
std::shared_ptr<Texture> getTexture() const; void setSpriteClip(SDL_Rect rect) { sprite_clip_ = rect; }
void setSpriteClip(int x, int y, int w, int h) { sprite_clip_ = (SDL_Rect){x, y, w, h}; }
// Establece el valor de la variable // Obtiene un puntero a la textura
void setTexture(std::shared_ptr<Texture> texture); std::shared_ptr<Texture> getTexture() const { return texture_; }
// Establece la textura a utilizar
void setTexture(std::shared_ptr<Texture> texture) { texture_ = texture; }
}; };