So I have a player class that just shoots a bullet and for some reason it is not shooting the bullet the way I want it to. The problem is trying to get the bullet to shoot from the player's location in the direction upwards. So, player would have this:
void Player::shoot(Bullet &bullet)
{
bullet.isFired(true);
}
All the shoot function does is simply tell the bullet object that it has been fired and should now update, thus:
void Bullet::update(sf::Vector2f position, sf::Vector2f speed)
{
if (wasFired == true)
{
setPosition(position.x + speed.x, position.y + speed.y);
}
else if (wasFired == false)
{
wasFired = false;
}
}
The code here is only raw and written on the fly just to get a base up and running. And in the initialisation thereof:
void Game::update()
{
bullet.update(tank.getPosition(), sf::Vector2f(0, -10));
}
When I run the game, the bullet moves by 10 units upwards, but it does not update the position thereafter; however it does update the position according to the player's x-axis.