Okay.
I think you need to review some of basic concepts of C++ and Oriented Object Programming. :\
I'll give you the advices you need to complete your code. Think about it, review your object model, then when you got something else, post it again. =p
You need to review your projectile class. As it is now, it cannot work as a true object. Let's see what it is now :
#ifndef PROJECTILE_H
#define PROJECTILE_H
#include <SFML/Graphics.hpp>
class Projectile
{
// First of all, the attributes, meaning "where you store datas" must be in private. An object should be a "black box", its attributes hidden and with the function as "buttons" for the user. Member data are private by default. So we delete the first "public:"
public:
sf::Image BulletImage; // Here, the image is a big array of pixels stored in memory. When drawing, the image is "copy/paste" on the screen. There is no need to create a new Image at each projectile.
static sf::Sprite Bullet; // Also, the sf::Sprite already know its image as you have to give it in parameter when creating the sprite, or with a sprite.SetImage(); We don't need the "static" word.
bool BulletState; // This is OK. We need to know if a bullet is done for before destroying it from the scene.
float BulletSpeed; // This is OK. A bullet need to know at wich speed it move.
// Let see the functions.
public:
// Here, we need one or two constructors! How the object will know what to do and what are his attributes when we create it? :/
Projectile(); // Default constructor, even if we don't need it right know, it is always usefull to have it. It's rĂ´le is to give our basic attributes a default value at creation.
Projectile(sf::Image &image, sf::vector2f &position, float speed); // A constructor with parametter for our projectile, all it need to know is what it looks like, from where he begin his course and at what speed.
void SetDirection(sf::vector2f &target); // To set the direction, you can use a reference's coordinates, to tell the bullet to wich ennemy it should go
void SetDirection(float angle); // We can also set the direction with an angle, in degree
void SetSpeed(float); // Here, you just update the speed of the bullet if it have to change.
void Destroy(bool); // It's OK, we need to tell when the bullet hit its target
bool IsDestroyed(const Projectile& b); // It's OK, we need to know if the bullet have hit something, you can also test if it is off the screen here. Don't need parametter.
void Calculate(sf::RenderWindow &app); // It's OK, we need to update the positions of the bullet at each frame with it.
};
#endif
With this, our projectile became more clear. We can also enhance it through the inheritance. Why? Because the sprite already have the data members of a moving object -> a reference to it's image, the xy coordinates and a direction. Why not use it?
#ifndef PROJECTILE_H
#define PROJECTILE_H
#include <SFML/Graphics.hpp>
// We make the Projectile class inherite from sf::Sprite
class Projectile : public sf::Sprite
{
sf::Sprite Bullet; // Projectile became itself a sf::Sprite, we don't need to create another sprite anymore.
bool BulletState;
float BulletSpeed;
public:
Projectile(); // In the default constructor, we'll call for the default constructor of sf::Sprite
Projectile(sf::Image &image, sf::vector2f &position, float speed); // In this constructor, we'ell call for the sf::Sprite constructor and pass to it the &image and the &position.
void SetDirection(sf::vector2f &target); // The direction to a target is still interresting, but with an angle, you don't need anymore to have a SetDirection(float angle) function, you can use the sf::Sprite::SetRotation(float rotation).
// Functions bellow are still needed
void SetSpeed(float);
void Destroy(bool);
bool IsDestroyed();
void Calculate(sf::RenderWindow &app);
};
#endif
At the end, you should have in your main one single sf::Image created before your game loop, your vector ready to receive bullets and a way to add bullet to your vector when pressing your "fire" button. (with insert())
Try to figure out what the function's definition will look like. If you don't know what I was saying in this exemple, review your C++ tutorials and lesson first. :\
If you can't find how to write the class tomorrow or later, I'll give you some answers, but it will meaningless if you don't try a bit more by yourself. :p
And if you don't want to take those advices, feel free to do.