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

Drawing a static game border


In this simple class, we define four sets of points that will represent four lines. Unsurprisingly, the GameObject class will draw the border using these points as the end points of lines.

In the constructor, which is the entirety of the class, we set the type by calling setType(), the world location as the center of the map, and height and width as the height and width of the entire map.

Then, we define the four lines in a float array and call setVertices() to prepare a FloatBuffer.

Create a new class called Border and add the following code:

public class Border extends GameObject{

  public Border(float mapWidth, float mapHeight){

        setType(Type.BORDER);
        //border center is the exact center of map
        setWorldLocation(mapWidth/2,mapHeight/2);

        float w = mapWidth;
        float h = mapHeight;
        setSize(w, h);

       // The vertices of the border represent four lines
       // that create a border of a size passed into the constructor...