Coding the Bullet class
The Bullet
class is not complicated. It is a tiny square bouncing around the screen and will have many similarities to the ball in the Pong game. To get started, add the member variables shown highlighted next to the Bullet
class:
import android.graphics.RectF; class Bullet {     // A RectF to represent the size and location of the     bullet     private RectF mRect;     // How fast is the bullet traveling?     private float mXVelocity;     private float mYVelocity;     // How big is a bullet     private float mWidth;     private float mHeight; }
We now have a RectF
called mRect
that will represent the position of the bullet. You will need to add the import
statement for the RectF
class as well. In addition, we have two float
variables to represent the direction/speed of travel...