tornem al pc d'anit

This commit is contained in:
2025-07-12 09:55:56 +02:00
parent 6082a72392
commit 719c448779
5 changed files with 25 additions and 17 deletions

View File

@@ -5,7 +5,7 @@ frame_height=12
name=normal_up name=normal_up
speed=5 speed=5
loop=0 loop=0
frames=0,1,2,2,1,0 frames=0,1,2
[/animation] [/animation]
[animation] [animation]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -14,8 +14,8 @@ Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered, int owner
bullet_type_(bullet_type), bullet_type_(bullet_type),
owner_(owner) owner_(owner)
{ {
vel_x_ = (bullet_type_ == BulletType::LEFT) ? BULLET_VEL_X_LEFT_ vel_x_ = (bullet_type_ == BulletType::LEFT) ? VEL_X_LEFT_
: (bullet_type_ == BulletType::RIGHT) ? BULLET_VEL_X_RIGHT_ : (bullet_type_ == BulletType::RIGHT) ? VEL_X_RIGHT_
: 0; : 0;
std::string powered_type = powered ? "powered_" : "normal_"; 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; break;
} }
collider_.r = BULLET_WIDTH_ / 2; collider_.r = WIDTH / 2;
shiftColliders(); shiftColliders();
} }
@@ -59,14 +59,14 @@ BulletMoveStatus Bullet::update()
BulletMoveStatus Bullet::move() BulletMoveStatus Bullet::move()
{ {
pos_x_ += vel_x_; 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(); disable();
return BulletMoveStatus::OUT; return BulletMoveStatus::OUT;
} }
pos_y_ += BULLET_VEL_Y_; pos_y_ += VEL_Y_;
if (pos_y_ < param.game.play_area.rect.y - BULLET_HEIGHT_) if (pos_y_ < param.game.play_area.rect.y - HEIGHT)
{ {
disable(); disable();
return BulletMoveStatus::OUT; return BulletMoveStatus::OUT;

View File

@@ -26,6 +26,10 @@ enum class BulletMoveStatus : Uint8
class Bullet class Bullet
{ {
public: public:
// Constantes
static constexpr float WIDTH = 12.0f;
static constexpr float HEIGHT = 12.0f;
// Constructor y Destructor // Constructor y Destructor
Bullet(float x, float y, BulletType bullet_type, bool powered, int owner); Bullet(float x, float y, BulletType bullet_type, bool powered, int owner);
~Bullet() = default; ~Bullet() = default;
@@ -44,11 +48,9 @@ public:
private: private:
// Constantes // Constantes
static constexpr float BULLET_WIDTH_ = 12.0f; static constexpr float VEL_Y_ = -3.0f;
static constexpr float BULLET_HEIGHT_ = 12.0f; static constexpr float VEL_X_LEFT_ = -2.0f;
static constexpr float BULLET_VEL_Y_ = -3.0f; static constexpr float VEL_X_RIGHT_ = 2.0f;
static constexpr float BULLET_VEL_X_LEFT_ = -2.0f;
static constexpr float BULLET_VEL_X_RIGHT_ = 2.0f;
// Propiedades // Propiedades
std::unique_ptr<AnimatedSprite> sprite_; // Sprite con los gráficos std::unique_ptr<AnimatedSprite> sprite_; // Sprite con los gráficos

View File

@@ -648,8 +648,7 @@ void Game::renderBullets()
// Crea un objeto bala // Crea un objeto bala
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner) void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner)
{ {
bullets_.emplace_back( bullets_.emplace_back(std::make_unique<Bullet>(x, y, kind, powered_up, owner));
std::make_unique<Bullet>(x, y, kind, powered_up, owner));
} }
// Vacia el vector de balas // Vacia el vector de balas
@@ -1427,25 +1426,32 @@ void Game::DEMO_handlePlayerInput(const std::shared_ptr<Player> &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. // 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> &player, BulletType bulletType) void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bullet_type)
{ {
if (player->canFire()) if (player->canFire())
{ {
switch (bulletType) SDL_Point bullet = {0, 0};
switch (bullet_type)
{ {
case BulletType::UP: case BulletType::UP:
player->setInput(InputAction::FIRE_CENTER); player->setInput(InputAction::FIRE_CENTER);
bullet.x = 2 + player->getPosX() + (player->getWidth() - Bullet::WIDTH) / 2;
bullet.y = player->getPosY() - (Bullet::HEIGHT / 2);
break; break;
case BulletType::LEFT: case BulletType::LEFT:
player->setInput(InputAction::FIRE_LEFT); player->setInput(InputAction::FIRE_LEFT);
bullet.x = player->getPosX() - (Bullet::WIDTH / 2);
bullet.y = player->getPosY();
break; break;
case BulletType::RIGHT: case BulletType::RIGHT:
player->setInput(InputAction::FIRE_RIGHT); player->setInput(InputAction::FIRE_RIGHT);
bullet.x = player->getPosX() + player->getWidth() - (Bullet::WIDTH / 2);
bullet.y = player->getPosY();
break; break;
default: default:
break; 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"); playSound("bullet.wav");
// Establece un tiempo de espera para el próximo disparo. // Establece un tiempo de espera para el próximo disparo.