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 very easy to achieve.
In this chapter we are going to:
- Code the
Ball
class - Implement an instance of
Ball
in the game engine - Code the
Bat
class - Implement a
Bat
instance in the game engine - Add movement controls to the
Bat
Let's start by adding our first object to the game to bring a ball to life.