I will post the part of my main.
while(window.isOpen)
//Events
if(keyboard.isKeyPressed(Keyboard::D))
{
posPlayer = player.movePlayerShip(true, false, false, false, posPlayer);
}
if(keyboard.isKeyPressed(Keyboard::A))
{
posPlayer = player.movePlayerShip(false, true, false, false, posPlayer);
}
if(keyboard.isKeyPressed(Keyboard::W))
{
posPlayer = player.movePlayerShip(false, false, true, false, posPlayer);
}
if(keyboard.isKeyPressed(Keyboard::S))
{
posPlayer = player.movePlayerShip(false, false, false, true, posPlayer);
}
if(keyboard.isKeyPressed(Keyboard::Space))
{
posBall = player.shoot(posBall, posPlayer, pressedSpace);
pressedSpace = true;
}
else if(canFollow)
{
posBall.y = posPlayer.y+16;
posBall.x = posPlayer.x+32;
}
//Render and position updates
Only look the code for the space key. I call the function shoot, which is this function:
Vector2f Jeu::shoot(Vector2f posBall, Vector2f posPlayer, bool pressed)
{
hideBall = false;
canFollow = false;
posBall.y -= 2;
if(posBall.y < 0)
{
isMoving = true;
posBall.y = posPlayer.y+16;
posBall.x = posPlayer.x+32;
pressed = false;
}
return posBall;
}
When I press space
and holding it, the ball is moving toward the y : 0 position.
If I don't hold it, it returns to the player position. Also, when I try to do a loop, the game crashes.
So, one question: Can I have some help, yes or no?
Thanks.