Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Android Game Programming By Example
Android Game Programming By Example

Android Game Programming By Example: Harness the power of the Android SDK by building three immersive and captivating games

eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Android Game Programming By Example

Chapter 1. Player 1 UP

The terminology used by old arcade and pinball machines "1 UP" was a kind of notice to the players that they were playing (up) now. It was also used to indicate earning an extra life. Are you ready to build three great games?

We will build three cool games together. Every line of code for these three games is shown in this book; you will never have to refer to the code files to see what is going on. Also, the entire file set required to build all three games is included in the download bundle that can be obtained from the books page on the Packt website.

All the code, Android manifest files, and the graphical and audio assets are included in the download as well. The three cool games are progressively more challenging to implement.

The first project uses a simple but functional game engine that clearly demonstrates the essentials of a main game loop. The game will be fully working with the home screen, high scores, sound, and animation. But by the end of the project, as we add features and try to balance the game play, we will soon see that we need more flexibility in order to add features.

In the second project, a hard retro platformer, we will see how we can use a simple and flexible design to build a relatively fast and very flexible game engine, which is extendable and reusable. This flexibility will allow us to make quite a complex and well-featured game. This game will have multiple levels, different environments, and more. This in turn will highlight the need for being able to draw graphics more quickly. That leads us on to the third project.

In the third project, we will build an Asteroids-like game called Asteroids simulator. Although the game won't have as many features as the previous project, it will feature the super-smooth drawing of hundreds of animated game objects running at over 60 frames per second. We will achieve this by learning about and using the Open Graphics Library for Embedded Systems (OpenGL ES 2).

By the end of this book, you will have a whole repertoire of design ideas, techniques, and code templates that you can use in your future games. By seeing the strengths and weaknesses of the different ways of making games on Android, you will be able to successfully design and build games in the most appropriate way for your next big game.

A closer look at the games

Here is a quick glimpse at the three projects.

Tappy Defender

Fly Flappy Bird-style with one finger to reach your home planet, while avoiding multiple enemies. Features include:

  • Basic animation
  • Home screen
    Tappy Defender
  • Collision detection
  • High scores
  • Simple HUD
  • One-finger touch screen controls
    Tappy Defender

Tough retro platformer

This is a genuinely tough-to-beat retro style platform game. We have to guide Bob from the underground fire caves through the city, forest, and finally to the mountains. It has four challenging levels. Features include:

  • A more advanced, flexible game engine
  • More advanced "sprite sheet" character animation
  • A level builder engine to design your levels in text format
  • Multiple scrolling parallax backgrounds
  • Transition between levels
  • A more advanced HUD
    Tough retro platformer
  • Add loads of extra diverse levels
  • Sound manager to easily manage sound FX
  • Pickups
  • An upgradeable gun
  • Seek-and-destroy enemy drones
  • Simple AI scripting for patrolling enemy guards
  • Hazards such as fire pits
  • Scenery objects to create atmosphere
    Tough retro platformer

Asteroids simulator

This is a classic shooter with retro vector-graphics style visuals. It involves clearing waves of smoothly animated spinning asteroids with a rapid fire gun. Features include:

  • 60 frames per second or better, even on old hardware
  • An introduction to OpenGL ES 2
  • Shooter with waves of progressive difficulty
  • Advanced multiphase collision detection
    Asteroids simulator

Setting up your development environment

All the code in this book and the download bundle will work in your favorite Android IDE. However, I found the latest version of Android Studio exceptionally friendly to use and the code was written and tested in it as well.

If you don't currently use Android Studio, I encourage you to give it a try. Here is a quick overview of how to get up and running quickly. This guide includes steps to install the Java JDK in case you are completely new to Android development.

Tip

If you already have your preferred development environment ready to go then jump straight to Chapter 2, Tappy Defender – First Step.

The first thing we need to do is prepare your PC to develop for Android using Java. Fortunately, this is made quite simple for us.

Tip

If you are learning on Mac or Linux everything in this book will still work. The next two tutorials have Windows-specific instructions and screenshots. However, it shouldn't be too difficult to vary the steps slightly to suit Mac or Linux.

All we need to do is:

  1. Install the Java Development Kit (JDK), which allows us to develop in Java.
  2. Then install Android Studio to make Android development fast and easy. Android Studio uses the JDK and some other Android-specific tools that get automatically installed when we install Android Studio.

Installing the JDK

The first thing we need to do is get the latest version of the JDK. To complete this guide, perform the following instructions:

  1. We need to be on the Java website, so visit: http://www.oracle.com/technetwork/java/javase/downloads/index.html.
  2. Find the three buttons shown here and click on the one that says JDK that is highlighted in the following image. They are on the right-hand side of the web page. Then, click on the Download button under the JDK option:
    Installing the JDK
  3. You will be taken to a page that has multiple options to download the JDK. In the Product/File Description column, you need to click the option that matches your operating system. Windows, Mac, Linux, and some other less common options are all listed.
  4. A common question asked here is, do I have 32- or 64-bit windows? To find out, right-click on your My Computer icon (This PC on Windows 8), click on the Properties option, and look under the System heading at the System type entry:
    Installing the JDK
  5. Click on the somewhat hidden Accept License Agreement checkbox:
    Installing the JDK
  6. Now, click on download for your OS and type as previously determined. Wait for the download to finish.
  7. In your downloads folder, double-click on the file you just downloaded. The latest version at the time of writing for a 64-bit Windows PC was jdk-8u5-windows-x64. If you are using Mac/Linux or have a 32-bit OS, your filename will vary accordingly.
  8. In the first of several install dialogs, click on the Next button and you will see the following dialog box:
    Installing the JDK
  9. Accept the defaults shown in the previous image by clicking on Next. In the next dialog box, you can accept the default install location by clicking on Next.
  10. Next up is the last dialog of the Java installer; for this click on Close.

    Note

    The JDK is now installed. Next, we will make sure that Android Studio is able to use the JDK.

  11. Right-click on your My Computer icon (This PC on windows 8) and click on Properties | Advanced system settings | Environment Variables... | New... (under System variables, not under User variables). Now, you can see the New System Variable dialog box:
    Installing the JDK
  12. Type JAVA_HOME for Variable name: and enter C:\Program Files\Java\jdk1.8.0_05 for the Variable value: field. If you installed the JDK somewhere else, then the file path you enter in the Variable value: field will need to point to wherever you put it. Your exact file path will likely have a different ending to match the latest version of Java at the time you downloaded it.
  13. Click on OK to save your new settings.
  14. Now under System variables, click on Path and then click on the Edit... button. At the very end of the text in the Variable value: field, enter the following text to add our new variable to the file paths that Windows will use, ;JAVA_HOME. Be sure not to miss the semicolon from the beginning.
  15. Click on OK to save the updated Path variable.
  16. Now, click on OK again to clear the Advanced system settings dialog box.

The JDK is now installed on our PC.

Installing Android Studio

Without delay, let's get Android Studio installed, and then we can begin our first game project. Visit:

https://developer.android.com/sdk/index.html

  1. Click on the button labeled DOWNLOAD ANDROID STUDIO FOR WINDOWS to start the Android Studio download. This will take you to another web page with a very similar looking button to the one you just clicked on.
  2. Accept the license by checking the checkbox and commence the download by clicking the button labeled DOWNLOAD ANDROID STUDIO FOR WINDOWS and wait for the download to complete.
  3. In the folder you just downloaded Android Studio to, right-click on the android-studio-bundle-135.12465-windows.exe file and click on Run as administrator. The end of your filename will vary depending on the version of Android Studio and your operating system.
  4. When asked if you want to allow the following program from an unknown publisher to make changes to your computer, click on Yes. On the next screen, click on Next.
  5. On the screen pictured here, you can choose which users of your PC can use Android Studio. Choose which is right for you as all options will work, and then click on Next:
    Installing Android Studio
  6. In the next dialog, leave the default settings and then click on Next.
  7. On the Choose start menu folder dialog box leave the defaults and click on Install.
  8. On the Installation complete dialog, click on Finish to run Android Studio for the first time.
  9. The next dialog is for users who have already used Android Studio, so assuming you are first-time user, select the I do not have a previous version of Android Studio or I do not want to import my settings checkbox. Then click on OK:
    Installing Android Studio

That was the last piece of software we needed. We will begin to use Android Studio straight away in the next chapter.

Summary

This chapter was deliberately kept as short as possible, so we can get on with building some games. We will do this now.

Left arrow icon Right arrow icon

Description

The book is best suited for existing Android or Java programmers who want to adapt their skills to make exciting Android games. The book is also for determined readers who might have no Android, game programming or even Java experience, but a reasonable understanding of object oriented programming knowledge is assumed.

What you will learn

  • Build simple to advanced game engines for different types of game, with cool features such as sprite sheet character animation and scrolling parallax backgrounds
  • Design and implement genuinely challenging and playable levels
  • Implement the critical main game loop
  • Implement basic and advanced collision detection mechanics
  • Bring to life a challenging enemy AI
  • Make the math behind 2D rotation, velocity, and collisions simple
  • Run your game designs at 60 frames per second or better
  • Process multitouch screen input effectively and efficiently
  • Implement a multitude of other game features such as pickups, firing weapons, HUDs, generating and playing sound FX, scenery, level transition, high scores, and more
  • Implement a flexible and advanced game engine that uses OpenGL ES 2 for fast, smooth frame rates

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 30, 2015
Length: 388 pages
Edition : 1st
Language : English
ISBN-13 : 9781785286193
Vendor :
Google
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jun 30, 2015
Length: 388 pages
Edition : 1st
Language : English
ISBN-13 : 9781785286193
Vendor :
Google
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 152.97
Android NDK Beginner`s Guide - Second Edition
$54.99
Learning Java by Building Android Games
$48.99
Android Game Programming By Example
$48.99
Total $ 152.97 Stars icon
Banner background image

Table of Contents

12 Chapters
1. Player 1 UP Chevron down icon Chevron up icon
2. Tappy Defender – First Step Chevron down icon Chevron up icon
3. Tappy Defender – Taking Flight Chevron down icon Chevron up icon
4. Tappy Defender – Going Home Chevron down icon Chevron up icon
5. Platformer – Upgrading the Game Engine Chevron down icon Chevron up icon
6. Platformer – Bob, Beeps, and Bumps Chevron down icon Chevron up icon
7. Platformer – Guns, Life, Money, and the Enemy Chevron down icon Chevron up icon
8. Platformer – Putting It All Together Chevron down icon Chevron up icon
9. Asteroids at 60 FPS with OpenGL ES 2 Chevron down icon Chevron up icon
10. Move and Draw with OpenGL ES 2 Chevron down icon Chevron up icon
11. Things That Go Bump – Part II Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4
(9 Ratings)
5 star 66.7%
4 star 11.1%
3 star 22.2%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Rodger Jan 06, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
John Horton describes exactly how to write for Android and Java without throwing masses of unintelligible buzzwords at you. Each stage is carefully and easily explained and each new concept and word is explained in plain english. This does not mean that he doesn't teach in depth but only that he introduces the ideas as you need them to understand what you are doing. I have read and tried to follow many books and videos on android and John Hortons books have taught me more than any of the others.
Amazon Verified review Amazon
Guillermo Rodriguez Jul 17, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is excellent! It has a fresh, fun style, but at the same time it covers the topics of Android Game Development with technical depth and correctness It is a wonderful tool for every Android programmer.
Amazon Verified review Amazon
Hugo Oct 14, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I think the title is wrong, this isn't just a programming book, this is a complete game development course, the author starts by talking about what you will have at the end, them he introduces every game talking about the foundations not just code and result, you are introduced to good practices to achieve your game complete, it is fundamental in my opinion to have a project complete, the programming part is really good as he is presenting the critical points of the game structure in natural basis, you understand what he does because you understand the need of that code part. I think that the difficult of this book is between intermediate to advanced, but he made a book that everyone who wants to make a mobile game can start with solid basis. All the projects has its own focus and difficult level, I think they shown almost every feature you need to make a good 2d mobile game.
Amazon Verified review Amazon
jamie Jul 30, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Fantastic book and i would give 10 stars if possible! i have to disagree with another review i have seen about the book not being useful to developers at beginner level, although the book intro does assume you have some development knowledge it all depends on what you are looking to take from this book! i am practically new to android game development and needed to know more on game loops and sprites and i got this know how by reading this book and putting it to practice with the games made in this book so even from a beginners point of view i have to say that what i have took from this book has been a massive help towards my understanding of what it takes to get games built and running! java code in any book anywhere can seem daunting to all of us but by using examples i find it is the best method and by example is exactly what this book shows, if you still do not get whats happening in code then simply go over it again as with everything in life, things become clearer the more you practice.Before i read and used the examples in this book i was at a stand still with my games development and was annoyed with my self as was trying to take so much information in from a number of different sources it was really taking a toll on me but when i came accross this book it ticked all the right boxes and i am glad i gave my time to read this as all this time it was one source i really needed to focus on with the right information and it happend to be the best choice i made investing my time into this because it gave me everything i needed to know and more! i am now confident with my own looping and sprites, and much better ways of the headach i was having with fps, this book is not just good to give a once over! for me it is also an ideal reference book.The way the book has been written is very straight forward and informative this makes it easy to follow, you can copy and paste the code or download the code if you have a paperback copy however if your new to development and really keen to learn i find that by writing the code myself gives me that bit extra of my learning progress and comes across clearer then copy and pasting chunks of code.I hope this book helps you all as much as it has helped me, if your really serious about android games development then you can never have enough learning books, i do highly recommend to add this to your front collection.thank you to John Horton and also to Packt for this book being here today! i had almost given up so for this i am truly thankful and will look out for more books from you in the future should there be any.Jamie LoweGames Developer in the making.
Amazon Verified review Amazon
Thomas Möller Aug 15, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Der Autor erläutert die Spieleprogrammierung auf Android-Geräten anhand von drei 2D-Spielen. Diese Rezension bezieht sich nur auf die ersten beiden Spiele. Das dritte Spiel (Asteroids mit Nutzung von OpenGL ES 2) habe ich bisher noch nicht durchgearbeitet.John Horton nutzt für die Spieleprogrammierung keine UI-Elemente des Android Betriebssystem (wie z.B. Button, Layout, Textfields usw.) und benötigt daher keinen Rückgriff auf die mit den Activities assozierten XML-Dateien. Daher braucht man keine weiteren Kenntnisse über die Android-UI-Bibliotheken, was recht entspannend ist.Alles wird im Android-Canvas (eine Art Leinwand, die später im Spiel die Displayanzeige darstellt) direkt in Java programmiert.Der Autor entwickelt im ersten Spiel eine Game-Engine, die gut funktioniert und sich auch leicht auf eigene Spielideen übertragen lässt.Im zweiten Spiel (Run & Jump) wird die Game-Engine dann erweitert und verwaltet zahlreiche Grafikobjekte, mit denen der Spieler auf verschiedene Weise interagiert. Dazu kommt noch ein mehrstufig scollender Hintergrund, der dadurch sogar eine räumliche Tiefe des Hintergrunds erzielt. Das Spiel wird von Anfang an so programmiert, dass es einen Level-Editor enthält, mit dem ohne größere Eingriffe in das Javaprogramm eigene Levels erstellt und beliebig geändert werden können. Dazu reicht ein einfacher Texteditor aus. Die neuen oder geänderten Level müssen lediglich in das Programm eingebunden werden, was aber mit wenigen Programmzeilen möglich ist.John Horton erklärt recht kleinschrittig die einzelnen Programmschritte. Ich fand sie dadurch gut nachvollziehbar. Ein Spiel erstreckt sich über mehrere Buchkapitel. Mindestens am Ende jedes Kapitels, häufig aber auch zwischendurch, werden Teilabschnitte der Programmierung fertiggestellt, die ein Testen des Spiels zulassen. So bleibt die Motivation hoch und man kann schnell die Wirkung der Programmteile erkunden.Pro: - Gut verständlich, sofern man Javakenntnisse besitzt. - Motivierende und grafisch schon recht anspruchsvolle Spiele (zumindest das 2. Spiel). - Gut strukturierte Programmierung durch Nutzung von Vererbung, MVC-Architektur (zumindest soweit sinnvoll) und Datenkapselung. - Der Autor erläutert meistens recht genau, wo jeweils die neuen Codezeilen in den Klassen programmiert werden müssen, so dass man auch ohne Downloads der Source-Dateien das Programm nach und nach selbst eintippen kann. - Am Ende jedes Spiels zeigt der Autor noch einige Ideen auf, wie das Spiel ohne großen Programmieraufwand erweitert und verbessert werden kann. Dazu können in der Regel die bisher geschaffenen Programmelemente genutzt werden oder müssen nur geringfügig erweitert werden.Contra: - Das Layout der Codezeilen ist teilweise schlecht formatiert. Es sind z.T. Einrückungen vorhanden, wo keine hingehören und umgekehrt. Das erschwert das Lesen und Verstehen des Codes etwas. - Im zweiten (und schon recht komplexen Spiel) wollte der Autor wohl mit den letzten Programmteilen schnell (oder endlich) fertig werden. Leider enthalten dort zwei Klassen bzw. umfangreichere Methoden Fehler (keine bloßen Flüchtigkeitsfehler). Sie fallen bei einem Kurztest möglicherweise nicht aber bei etwas längeren Tests oder geändertem Level schon. Sofern man aber bis dahin den Erklärungen folgen konnte, ist man auch in der Lage, die Programme entsprechend zu ändern, obwohl die notwendigen Änderungen jeweils recht umfangreich waren.Trotz dieser eher kleinen Abstriche steckt das Buch aber so voller Ideen und hilfreicher Konzepte, dass es für mich sehr wertvoll ist und 5 Sterne verdient. Ich freue mich schon auf die Erläuterungen für das dritte und letzte Spiel (welches w.o. erwähnt sogar OpenGL ES 2 nutzt).Für den Leser sind moderate Java-Kenntnisse erforderlich, Android-Kenntnisse dagegen kaum.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.