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 mRect
and the solution to sharing it will be identical to the solution from the Ball
class- a default access getRect
method that returns a RectF
object.
We will need to calculate and retain the length of the bat and will do so with a float
called...