Im making a game like space invaders, you fly a spaceship and destroy enemies. I got the player spaceship loading and displaying and moving. Now i want to make projectiles, but i cant get it to work, how should i do it ?
projectiles from your spaceship obviously.
I tried something but kinda failed:
Inside of a class:
static sf::Texture _projectileTexture;
static sf::Sprite _projectileSprite[30];
inside of a .cpp
_projectileTexture.loadFromFile("projectile1.png");
for(int n = 0; n < 30; n++)
_projectileSprite[n].setTexture(_projectileTexture);
for(int n = 0; n < curProjectile; n++)
gameWindow.draw(_projectileSprite[n]);
how i try to make new projectiles:
if(inProjectile == true)
{
curProjectile ++;
pProjectile[curProjectile];
_projectileSprite[curProjectile].setPosition(pProjectile[curProjectile].posX, pProjectile[curProjectile].posY);
return;
}
General declarations:
int curProjectile = -1;
struct Projectile
{
float posX;
float posY;
bool alive;
};
Projectile *pProjectile = new Projectile[30];
running in main so i can initialize
for(int n(0); n < 30; n++)
{
pProjectile[n].posX = 20;
pProjectile[n].posY = 20;
}
suggestions please
Let me explain here what i did:
1. Load the projectile .png into a texture.
2. Load the texture into 30 sprite projectiles. (hoping that it will be enough)
3. Create with the Struct 30 projectiles.
4. Create/Set position of each one as they get shot.