Muntat a c++14 per a make_unique

Mes autos, const i constexpr perl codi
Ara la classe Screen es un poc pitjor
This commit is contained in:
2024-10-06 14:58:00 +02:00
parent 25a2753b13
commit afe092c742
16 changed files with 290 additions and 381 deletions

View File

@@ -13,14 +13,13 @@ constexpr int BULLET_VELX_RIGHT = 2;
// Constructor
Bullet::Bullet(int x, int y, BulletType kind, bool poweredUp, int owner, SDL_Rect *playArea, Texture *texture)
: posX(x), posY(y), width(BULLET_WIDTH), height(BULLET_HEIGHT), velX(0), velY(BULLET_VELY),
kind(kind), owner(owner), playArea(playArea),
sprite(std::unique_ptr<Sprite>(new Sprite(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture))) // Crear manualmente el std::unique_ptr
kind(kind), owner(owner), playArea(playArea)
{
velX = (kind == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind == BulletType::RIGHT) ? BULLET_VELX_RIGHT
: 0;
velX = (kind == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind == BulletType::RIGHT) ? BULLET_VELX_RIGHT : 0;
auto spriteOffset = poweredUp ? 3 : 0;
auto kindIndex = static_cast<int>(kind);
sprite = std::make_unique<Sprite>(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture);
sprite->setSpriteClip((kindIndex + spriteOffset) * width, 0, sprite->getWidth(), sprite->getHeight());
collider.r = width / 2;