diff --git a/data/gfx/bullet/bullet.ani b/data/gfx/bullet/bullet.ani index b4daa26..224920c 100644 --- a/data/gfx/bullet/bullet.ani +++ b/data/gfx/bullet/bullet.ani @@ -5,7 +5,7 @@ frame_height=12 name=normal_up speed=5 loop=0 -frames=0,1,2,2,1,0 +frames=0,1,2 [/animation] [animation] diff --git a/data/gfx/bullet/bullet.png b/data/gfx/bullet/bullet.png index 2e74a72..d775946 100644 Binary files a/data/gfx/bullet/bullet.png and b/data/gfx/bullet/bullet.png differ diff --git a/source/bullet.cpp b/source/bullet.cpp index d16730c..433e600 100644 --- a/source/bullet.cpp +++ b/source/bullet.cpp @@ -14,8 +14,8 @@ Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered, int owner bullet_type_(bullet_type), owner_(owner) { - vel_x_ = (bullet_type_ == BulletType::LEFT) ? BULLET_VEL_X_LEFT_ - : (bullet_type_ == BulletType::RIGHT) ? BULLET_VEL_X_RIGHT_ + vel_x_ = (bullet_type_ == BulletType::LEFT) ? VEL_X_LEFT_ + : (bullet_type_ == BulletType::RIGHT) ? VEL_X_RIGHT_ : 0; std::string powered_type = powered ? "powered_" : "normal_"; @@ -37,7 +37,7 @@ Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered, int owner break; } - collider_.r = BULLET_WIDTH_ / 2; + collider_.r = WIDTH / 2; shiftColliders(); } @@ -59,14 +59,14 @@ BulletMoveStatus Bullet::update() BulletMoveStatus Bullet::move() { pos_x_ += vel_x_; - if (pos_x_ < param.game.play_area.rect.x - BULLET_WIDTH_ || pos_x_ > param.game.play_area.rect.w) + if (pos_x_ < param.game.play_area.rect.x - WIDTH || pos_x_ > param.game.play_area.rect.w) { disable(); return BulletMoveStatus::OUT; } - pos_y_ += BULLET_VEL_Y_; - if (pos_y_ < param.game.play_area.rect.y - BULLET_HEIGHT_) + pos_y_ += VEL_Y_; + if (pos_y_ < param.game.play_area.rect.y - HEIGHT) { disable(); return BulletMoveStatus::OUT; diff --git a/source/bullet.h b/source/bullet.h index d738b70..08b2506 100644 --- a/source/bullet.h +++ b/source/bullet.h @@ -26,6 +26,10 @@ enum class BulletMoveStatus : Uint8 class Bullet { public: + // Constantes + static constexpr float WIDTH = 12.0f; + static constexpr float HEIGHT = 12.0f; + // Constructor y Destructor Bullet(float x, float y, BulletType bullet_type, bool powered, int owner); ~Bullet() = default; @@ -44,11 +48,9 @@ public: private: // Constantes - static constexpr float BULLET_WIDTH_ = 12.0f; - static constexpr float BULLET_HEIGHT_ = 12.0f; - static constexpr float BULLET_VEL_Y_ = -3.0f; - static constexpr float BULLET_VEL_X_LEFT_ = -2.0f; - static constexpr float BULLET_VEL_X_RIGHT_ = 2.0f; + static constexpr float VEL_Y_ = -3.0f; + static constexpr float VEL_X_LEFT_ = -2.0f; + static constexpr float VEL_X_RIGHT_ = 2.0f; // Propiedades std::unique_ptr sprite_; // Sprite con los gráficos diff --git a/source/sections/game.cpp b/source/sections/game.cpp index e2b7f8b..cb65141 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -648,8 +648,7 @@ void Game::renderBullets() // Crea un objeto bala void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner) { - bullets_.emplace_back( - std::make_unique(x, y, kind, powered_up, owner)); + bullets_.emplace_back(std::make_unique(x, y, kind, powered_up, owner)); } // Vacia el vector de balas @@ -1427,25 +1426,32 @@ void Game::DEMO_handlePlayerInput(const std::shared_ptr &player, int ind } // Maneja el disparo de un jugador, incluyendo la creación de balas y la gestión del tiempo de espera entre disparos. -void Game::handleFireInput(const std::shared_ptr &player, BulletType bulletType) +void Game::handleFireInput(const std::shared_ptr &player, BulletType bullet_type) { if (player->canFire()) { - switch (bulletType) + SDL_Point bullet = {0, 0}; + switch (bullet_type) { case BulletType::UP: player->setInput(InputAction::FIRE_CENTER); + bullet.x = 2 + player->getPosX() + (player->getWidth() - Bullet::WIDTH) / 2; + bullet.y = player->getPosY() - (Bullet::HEIGHT / 2); break; case BulletType::LEFT: player->setInput(InputAction::FIRE_LEFT); + bullet.x = player->getPosX() - (Bullet::WIDTH / 2); + bullet.y = player->getPosY(); break; case BulletType::RIGHT: player->setInput(InputAction::FIRE_RIGHT); + bullet.x = player->getPosX() + player->getWidth() - (Bullet::WIDTH / 2); + bullet.y = player->getPosY(); break; default: break; } - createBullet(player->getPosX() + (player->getWidth() / 2) - 6, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId()); + createBullet(bullet.x, bullet.y, bullet_type, player->isPowerUp(), player->getId()); playSound("bullet.wav"); // Establece un tiempo de espera para el próximo disparo.