Chapter 10: Coding the Bat and Ball
As we have done so much theory and preparation work in the previous two chapters, we can quickly make some progress on this one. We already have our bare-bones game engine coded and ready to update, draw, and track time down to the nearest millisecond.
Now we can add code to the Bat
and the Ball
classes. By the end of the chapter, we will have a moving ball and a player-moveable bat. Although we will need to wait until the next chapter before the ball bounces off the walls and the bat, we will also code the necessary methods in the Ball
class so that this last step will be easy to achieve.
In this chapter, we are going to do the following:
- Coding the
Ball
class - Implementing an instance of
Ball
in the game engine - Coding the
Bat
class - Implementing a
Bat
instance in the game engine - Adding movement controls to the Bat class
Let's start by adding our first object to the game to bring the ball to life.