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
speed=5
loop=0
frames=0,1,2,2,1,0
frames=0,1,2
[/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),
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;

View File

@@ -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<AnimatedSprite> sprite_; // Sprite con los gráficos

View File

@@ -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<Bullet>(x, y, kind, powered_up, owner));
bullets_.emplace_back(std::make_unique<Bullet>(x, y, kind, powered_up, owner));
}
// 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.
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())
{
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.