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
About the Author
About the Reviewers
Platformer – Guns, Life, Money, and the Enemy

Reusing existing classes

Let's quickly add our SoundManager and InputController classes to this project because they only need a little tweak to accommodate our needs here too.

Add a member for a SoundManager and an InputController object in both the AsteroidsView and AsteroidsRenderer classes.

private InputController ic;
private SoundManager sm;

Initialize the new objects in the onCreate method of the AsteroidsView class and call the loadSound method like this:

public AsteroidsView(Context context, int screenX, int screenY) {

     sm = new SoundManager();
     ic = new InputController(screenX, screenY);
     gm = new GameManager(screenX, screenY);

Also in AsteroidsView, add an extra two arguments to the call to the AsteroidsRenderer constructor to pass in references to the SoundManager and InputController objects.

setRenderer(new AsteroidsRenderer(gm,sm,ic));

Now in the AsteroidsRenderer constructor add the two extra...