New Projectiles class

Refactor of Bullet class
Different method of shooting.
This commit is contained in:
2024-12-01 17:44:25 +01:00
parent 2f6c98f4be
commit 2341c2fa6d
11 changed files with 127 additions and 62 deletions

View File

@@ -1,35 +1,9 @@
#include <iostream>
#include "../headers/Bullet.h"
Bullet::Bullet(float x, float y) {
bulletPosition.x = x;
bulletPosition.y = y;
outOfBounds = false;
bulletSprite.setTexture(Bullet::bulletTexture);
bulletSprite.setOrigin(bulletSprite.getLocalBounds().width/2, bulletSprite.getLocalBounds().height/2);
bulletSprite.setPosition(x, y);
bulletSpeed = -10.0f;
}
void Bullet::setSpeed(float speed) {
bulletSpeed = speed;
}
sf::Sprite &Bullet::getSprite() {
return bulletSprite;
}
void Bullet::update() {
bulletSprite.move(0.0f, bulletSpeed);
bulletPosition.y += int(bulletSpeed);
if(bulletPosition.y < -100) {
sprite.move(0.0f, speed);
position.y += int(speed);
if(position.y < -100) {
outOfBounds = true;
}
}
bool Bullet::getStatus() const {
return outOfBounds;
}
sf::Texture Bullet::bulletTexture = sf::Texture(); // plain init of static field
sf::Texture Bullet::rocketTexture = sf::Texture();
}