granera con sarna no pica

This commit is contained in:
2026-04-08 11:07:50 +02:00
parent d70edb29e7
commit 87cc58b5dd
29 changed files with 104 additions and 244 deletions

View File

@@ -23,21 +23,17 @@ Enemy::Enemy(const Data& enemy)
sprite_->setVelX(enemy.vx);
sprite_->setVelY(enemy.vy);
const int FLIP = (should_flip_ && enemy.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)); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) SDL flags are designed for bitwise OR
applyFlipMirror(enemy.vx);
collider_ = getRect();
color_ = enemy.color;
// Coloca un frame al azar o el designado
sprite_->setCurrentAnimationFrame((enemy.frame == -1) ? (rand() % sprite_->getCurrentAnimationSize()) : enemy.frame);
}
// Pinta el enemigo en pantalla
void Enemy::render() {
sprite_->render(1, color_);
sprite_->render();
}
// Actualiza las variables del objeto
@@ -60,9 +56,7 @@ void Enemy::resetToInitialPosition(const Data& data) {
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)); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
applyFlipMirror(data.vx);
collider_ = getRect();
}
@@ -105,6 +99,13 @@ void Enemy::checkPath() { // NOLINT(readability-make-member-function-const)
}
}
// Aplica flip horizontal y/o mirror vertical al sprite
void Enemy::applyFlipMirror(float vx) {
const int FLIP = (should_flip_ && 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)); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) SDL flags are designed for bitwise OR
}
// Devuelve el rectangulo que contiene al enemigo
auto Enemy::getRect() -> SDL_FRect {
return sprite_->getRect();