Chapter 7: Dynamic Collision Detection and Physics – Finishing the Pong Game
In this chapter, we will code our second class. We will see that although the ball is obviously quite different from the bat, we will use the exact same techniques to encapsulate the appearance and functionality of a ball inside a Ball
class, just like we did with the bat and the Bat
class. We will then add the finishing touches to the Pong game by coding some dynamic collision detection and scorekeeping. This might sound complicated but as we are coming to expect, SFML will make things much easier than they otherwise would be.
We will cover the following topics in this chapter:
- Coding the Ball class
- Using the Ball class
- Collision detection and scoring
- Running the game
We will start by coding the class that represents the ball.