drag'n drop de enemics, boundaries i items

This commit is contained in:
2026-04-02 10:53:21 +02:00
parent b6fec3eba7
commit b31346830f
15 changed files with 321 additions and 83 deletions

View File

@@ -53,6 +53,20 @@ void Enemy::update(float delta_time) {
void Enemy::updateAnimation(float delta_time) {
sprite_->animate(delta_time);
}
// Resetea el enemigo a su posición inicial (para editor)
void Enemy::resetToInitialPosition(const Data& data) {
sprite_->setPosX(data.x);
sprite_->setPosY(data.y);
sprite_->setVelX(data.vx);
sprite_->setVelY(data.vy);
const int FLIP = (should_flip_ && data.vx < 0.0F) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
const int MIRROR = should_mirror_ ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE;
sprite_->setFlip(static_cast<SDL_FlipMode>(FLIP | MIRROR));
collider_ = getRect();
}
#endif
// Comprueba si ha llegado al limite del recorrido para darse media vuelta

View File

@@ -30,7 +30,8 @@ class Enemy {
void render(); // Pinta el enemigo en pantalla
void update(float delta_time); // Actualiza las variables del objeto
#ifdef _DEBUG
void updateAnimation(float delta_time); // Solo actualiza la animación sin mover al enemigo
void updateAnimation(float delta_time); // Solo actualiza la animación sin mover al enemigo
void resetToInitialPosition(const Data& data); // Resetea el enemigo a su posición inicial (para editor)
#endif
auto getRect() -> SDL_FRect; // Devuelve el rectangulo que contiene al enemigo

View File

@@ -41,6 +41,14 @@ auto Item::getPos() -> SDL_FPoint { // NOLINT(readability-convert-member-functi
return P;
}
#ifdef _DEBUG
// Establece la posición del item (para editor)
void Item::setPosition(float x, float y) {
sprite_->setPosition(x, y);
collider_ = sprite_->getRect();
}
#endif
// Asigna los colores del objeto
void Item::setColors(Uint8 col1, Uint8 col2) {
// Reinicializa el vector de colores

View File

@@ -29,6 +29,9 @@ class Item {
auto getCollider() -> SDL_FRect& { return collider_; } // Obtiene el rectangulo de colision del objeto
auto getPos() -> SDL_FPoint; // Obtiene su ubicación
void setColors(Uint8 col1, Uint8 col2); // Asigna los colores del objeto
#ifdef _DEBUG
void setPosition(float x, float y); // Establece la posición del item (para editor)
#endif
private:
static constexpr float ITEM_SIZE = 8.0F; // Tamaño del item en pixels