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.
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 ...
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.