Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Android Game Programming by Example

You're reading from  Android Game Programming by Example

Product type Book
Published in Jun 2015
Publisher
ISBN-13 9781785280122
Pages 388 pages
Edition 1st Edition
Languages
Author (1):
John Horton John Horton
Profile icon John Horton

Table of Contents (18) Chapters

Android Game Programming by Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Player 1 UP 2. Tappy Defender – First Step 3. Tappy Defender – Taking Flight 4. Tappy Defender – Going Home 5. Platformer – Upgrading the Game Engine 6. Platformer – Bob, Beeps, and Bumps 7. Platformer – Guns, Life, Money, and the Enemy 8. Platformer – Putting It All Together 9. Asteroids at 60 FPS with OpenGL ES 2 10. Move and Draw with OpenGL ES 2 11. Things That Go Bump – Part II Index

Ending the game


If the game is not ended, the game is playing, and if the player has just died or won, the game is ended. We need to know when the game is ended and when it is playing. Let's make a new member variable gameEnded and declare it after the TDView class declaration:

private boolean gameEnded;

Now, we can initialize gameEnded in the startGame method. Enter this code as the very last line in the method.

gameEnded = false;

Now, we can finish the last few lines of our game rules logic, but wrap them in a test to see if the game has ended or not. Add the following code to conditionally update our game rules logic, right at the end of the TDView class's update method:

if(!gameEnded) {
            //subtract distance to home planet based on current speed
            distanceRemaining -= player.getSpeed();

            //How long has the player been flying
            timeTaken = System.currentTimeMillis() - timeStarted;
}

Our HUD will now have accurate data to keep the player informed of...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}