Hi there,
for my studies I have to program a simple game. There for I chose "Break out" and sfml. I created a class ball and reset the position:
void Ball::ResetPosition(int windowWidth, int windowHeight)
{
_moveToX = -1.f;
_moveToY = -1.f;
float distanceToGround = 10.f;
float ballPositionX = windowWidth / 2.f;
float ballPositionY = windowHeight - _paddleSize.y - distanceToGround - (_ball.getSize().y) - 4;
_ball.setPosition(ballPositionX, ballPositionY);
}
For collision testing I don't want to move the ball randomly on the screen. There for I created to variables, the first one is for the movement direction to the x-axis and the second one for the y-axis.
My game thread calls from now on the function MoveBall:
void Ball::MoveBall()
{
_ball.move(_moveToX, _moveToX);
}
The idea was the following... If I set the direction to -1,-1 the ball would move towards to the left corner of my window. If I change the direction to 1 and -1 it would move to the right side of the window.
My problem now is, that the ball doesn't behave like expected:
vector | direction |
1, 1 | down |
-1, -1 | left |
-1, 1 | left |
1, -1 | down |
Is there something I wrong with my code? Or has the ball possibly a own coord system?
rgds
_schuki