Hi,
I'm trying to create more than one projectile in an array because using when using one projectile, when you fire a second time, the first projectile disappears for the projectile to fire again.
I thought using for-loops would the best way to go about it but not sure what I am doing wrong.
//Here is instantiating the class
for (int i = 0; i < PROJECTILES; i++)
{
_projectile[i] = new Projectile();
}
//Projectile Inits
for (int i = 0; i < PROJECTILES; i++)
{
_projectile[i]->_speed = 0.8f;
_projectile[i]->_frameTime = 250;
_projectile[i]->_launched = false;
}
//Loading Projectile Content
for (int i = 0; i < PROJECTILES; i++)
{
_projectile[i]->_texture = new Texture2D();
_projectile[i]->_boundry = new Rect();
_projectile[i]->_texture = projTexture;
_projectile[i]->_boundry = projRect;
}
//Spacebar to fire
for (int i = 0; i < PROJECTILES; i++)
{
if (state->IsKeyDown(Input::Keys::SPACE))
{
_projectile[i]->_boundry->X = _player->_position->X + 35;
_projectile[i]->_boundry->Y = _player->_position->Y + 59;
_projectile[i]->_launched = true;
}
if (i == 5)
{
i = 0;
}
}
/?Draw Projectile
for (int i = 0; i < PROJECTILES; i++)
{
if (_projectile[i]->_launched)
{
SpriteBatch::Draw(_projectile[i]->_texture, _projectile[i]->_boundry, 0.5f, 0.0f);
_projectile[i]->_boundry->Y -= _projectile[i]->_speed * elapsedTime;
}
}
Now the issue I'm having is that PROJECTILES = 5 so it draws all five projectiles at the same time below each other, and when fired the all move together.
The speed is also stacking so the five projectiles move faster than the 1 projectile should be moving at.
Not sure what mistakes I am making and I'm not sure if I have given enough information.
Thank you
Ryan