Wow.. thats.. quite a lot I will definitely keep your advices in mind when creating next project.... Thanks for advices!
No problem.
I admit that it is not the best way, but at this point I couldn't make up any other, working solution.
Here is an example of how I might rewrite that part of the code:
float deltaSeconds = deltaT.asSeconds();
ball.Logic(deltaSeconds);
leftPaddle.Logic(deltaSeconds);
rightPaddle.Logic(deltaSeconds);
if(Collision(ball, leftPaddle)) {
ball.BouceHorizontal(leftPaddle);
}
if(Collision(ball, rightPaddle)) {
ball.BouceHorizontal(rightPaddle);
}
Vec ballPosition = ball.GetPosition();
if(ballPosition.y < 0 || ballPosition.y > SCREEN_H) {
ball.BounceVertical();
}
bool resetPoint = false;
if(ballPosition.x < 0) {
score.IncreaseRightPlayerPoints();
resetPoint = true;
} else if(ballPosition.x > SCREEN_W) {
score.IncreaseLeftPlayerPoints();
resetPoint = true;
}
if(score.isGameOver()) {
ResetGame();
} else if(resetPoint) {
ResetForPoint();
}
The main change is pulling the code that deals with object interactions (ball vs paddle, ball vs wall, ...) outside the objects themselves. We no longer have the ball needing to know about the paddles and then trying to communicate collisions back to the playing class, which needs to forward them into the score class for further processing, which finally tries to return a decision about resetting back into the playing class.
A smaller, more focused change would be:
int pointScorer = ball.Logic(deltaT.asSeconds(), paddle1, paddle2);
if(pointScorer != 0) {
score.AddPoint(pointScorer)
if(score.isGameOver()) {
Reset();
}
}
You can probably see that I am not the best in creating object oriented code
That is OK, it is a skill that you refine over time. There are other people who might disagree with some of my comments. Leaving aside any outright errors I may have made, the likely cause of such disagreements is because there is no one true way to solve programming problems. You can get a sense of this even from the two approaches I outlined above.
Each person has their own "style", not merely at the presentation level but rather in how they fundamentally approach, understand, de-construct and solve problems. There are other aspects to style too, for example because I work with a team, I make an effort to write my programs in a more straight-forward manner, rather than the more idiosyncratic style I had before I started collaborating with other programmers. Another influence on my style is unit testing - the code where the ball doesn't need to know about the paddles is easier to unit test.
The way to improve your knowledge of object oriented code is to keep writing programs.