- Renombrar proyecto de demo5_sprites_bouncing a vibe1_delta - Actualizar CMakeLists.txt, Makefile y defines.h con nuevo nombre - Añadir código fuente C++ para simulación de sprites con física - Incluir recursos (texturas) y configuración de compilación - Crear .gitignore apropiado para proyectos C++ 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
40 lines
758 B
C++
40 lines
758 B
C++
#include "sprite.h"
|
|
#include "texture.h" // for Texture
|
|
|
|
// Constructor
|
|
Sprite::Sprite(std::shared_ptr<Texture> texture)
|
|
: texture_(texture),
|
|
pos_{0.0f, 0.0f, 0.0f, 0.0f},
|
|
clip_{0.0f, 0.0f, 0.0f, 0.0f} {}
|
|
|
|
// Establece la posición del sprite
|
|
void Sprite::setPos(SDL_FPoint pos)
|
|
{
|
|
pos_.x = pos.x;
|
|
pos_.y = pos.y;
|
|
}
|
|
|
|
// Pinta el sprite
|
|
void Sprite::render()
|
|
{
|
|
texture_->render(&clip_, &pos_);
|
|
}
|
|
|
|
// Establece el rectangulo de la textura que se va a pintar
|
|
void Sprite::setClip(SDL_FRect clip)
|
|
{
|
|
clip_ = clip;
|
|
}
|
|
|
|
// Establece el tamaño del sprite
|
|
void Sprite::setSize(float w, float h)
|
|
{
|
|
pos_.w = w;
|
|
pos_.h = h;
|
|
}
|
|
|
|
// Modulación de color
|
|
void Sprite::setColor(int r, int g, int b)
|
|
{
|
|
texture_->setColor(r, g, b);
|
|
} |