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
Android Game Programming by Example

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

By John Horton
€28.99 €19.99
Book Jun 2015 388 pages 1st Edition
eBook
€28.99 €19.99
Print
€37.99
Subscription
€14.99 Monthly
eBook
€28.99 €19.99
Print
€37.99
Subscription
€14.99 Monthly

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
Buy Now

Product Details


Publication date : Jun 30, 2015
Length 388 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781785280122
Vendor :
Google
Category :
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

  • Collision detection

  • High scores

  • Simple HUD

  • One-finger touch screen controls

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

  • 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

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

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:

  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:

  5. Click on the somewhat hidden Accept License Agreement checkbox:

  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:

  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:

  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:

  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:

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

Key benefits

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

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
Buy Now

Product Details


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

Table of Contents

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

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
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.