The Bat class

The Bat class, as we will see has several similarities to the Ball class. After all, it's just a moving rectangle. However, the bat in the game needs to be controlled by the player. So, we need to provide a way to communicate what the player is pressing on the screen to the Bat class.

In later projects with more complicated controls, we will let the class itself translate the screen presses. For the Bat class, we will let PongGame handle the touches and just let the Bat class know one of three things: move left, move right, don't move. Let's look at all the variables the Bat class is going to need.

We will need a RectF to hold the position of the bat and a way of sharing the details with the PongGame class. We will call this variable ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.