Book Image

Android Game Programming by Example

By : John Horton
Book Image

Android Game Programming by Example

By: John Horton

Overview of this book

Table of Contents (18 chapters)
Android Game Programming by Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
7
Platformer – Guns, Life, Money, and the Enemy
Index

Rapid fire bullets


I've been addicted to games since Pong in the '70s, and remember my delight when a friend actually had a Space Invaders machine in his home for about a week. Although what really made asteroids so much better than Space Invaders, was how quickly you could shoot. In that tradition, we will make a satisfying, rapid fire stream of bullets.

Create a new class called Bullet, which has one vertex and will be drawn with a point. Note that we also declare and initialize an inFlight Boolean.

public class Bullet extends GameObject {

  private boolean inFlight = false;

  public Bullet(float shipX, float shipY) {
       super();

       setType(Type.BULLET);

       setWorldLocation(shipX, shipY);

       // Define the bullet
       // as a single point
       // in exactly the coordinates as its world location
       float[] bulletVertices = new float[]{

                0,
                0,
                0

       };
    
    setVertices(bulletVertices);

        
}

Next, we have...