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,28 +1,13 @@
#ifndef LOTOSTATEK_BULLET_H
#define LOTOSTATEK_BULLET_H
#include "SFML/Graphics/Sprite.hpp"
#include "Projectile.h"
#include "SFML/Graphics/Texture.hpp"
class Bullet {
struct Position {
int x;
int y;
};
class Bullet : public Projectile {
public:
Bullet(float x, float y);
sf::Sprite &getSprite();
void setSpeed(float speed);
bool getStatus() const;
void update();
static sf::Texture bulletTexture;
static sf::Texture rocketTexture;
private:
sf::Sprite bulletSprite;
Position bulletPosition;
float bulletSpeed;
bool outOfBounds;
Bullet(float x, float y, sf::Texture &texture) : Projectile(x,y, texture) {};
void update() override;
};

View File

@@ -4,6 +4,7 @@
#include <chrono>
#include "Actor.h"
#include "Rocket.h"
class Player : public Actor {
public:
@@ -16,10 +17,12 @@ public:
void moveRight() override;
void moveUp() override;
void moveDown() override;
std::vector<Rocket>& getRockets();
private:
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
std::vector<Bullet> rightBullets;
std::vector<Rocket> rockets;
sf::Texture rocketTexture;
sf::Texture bulletTexture;
};

27
headers/Projectile.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef PROJECTILE_H
#define PROJECTILE_H
#include <SFML/Graphics/Sprite.hpp>
class Projectile {
struct Position {
int x;
int y;
};
public:
Projectile(float x, float y, sf::Texture &texture);
sf::Sprite &getSprite();
void setSpeed(float speed);
bool isOutOfBounds() const;
virtual void update() = 0;
static sf::Texture texture;
protected:
~Projectile() = default;
sf::Sprite sprite;
Position position{};
float speed;
bool outOfBounds;
};
#endif //PROJECTILE_H

14
headers/Rocket.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef ROCKET_H
#define ROCKET_H
#include "Projectile.h"
class Rocket : public Projectile{
public:
Rocket(float x, float y, sf::Texture &texture) : Projectile(x,y, texture) {};
void update() override;
};
#endif //ROCKET_H