Is this entity a sfml object? If so:
NameOfEntity.getPosition().x will give you the horizontal position.
NameOfEntity.getPosition().y will give you the vertical position.
Example:
float xSpeed = 1, ySpeed = 0.2;
entity.move(xSpeed, ySpeed);
If(entity.getPosition().x > 500) {
xSpeed = xSpeed * -1;
entity.move(xSpeed, 0);
}
else If(entity.getPosition().x < 10) {
xSpeed = xSpeed * -1;
entity.move(xSpeed, 0);
}
(written from my phone, so sorry for any typos)
This code will have entity move back and forward horizontally
It will also move down vertically, but I have not added any code to make it change the y direction...
Hint: it's nearly the same as the one that chanqged the x direction...
Best regards