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.
Here is a quick glimpse at the three projects.
One-finger touch screen controls
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:
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
Seek-and-destroy enemy drones
Simple AI scripting for patrolling enemy guards
Hazards such as fire pits
Scenery objects to create atmosphere
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
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.
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.
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:
We need to be on the Java website, so visit: http://www.oracle.com/technetwork/java/javase/downloads/index.html.
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:
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.
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:
downloadsfolder, 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.
In the first of several install dialogs, click on the Next button and you will see the following dialog box:
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.
Next up is the last dialog of the Java installer; for this click on Close.
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:
JAVA_HOMEfor Variable name: and enter
C:\Program Files\Java\jdk1.8.0_05for 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.
Click on OK to save your new settings.
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.
Click on OK to save the updated Path variable.
The JDK is now installed on our PC.
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.
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.
In the folder you just downloaded Android Studio to, right-click on the
android-studio-bundle-135.12465-windows.exefile and click on Run as administrator. The end of your filename will vary depending on the version of Android Studio and your operating system.
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.
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:
In the next dialog, leave the default settings and then click on Next.
On the Choose start menu folder dialog box leave the defaults and click on Install.
On the Installation complete dialog, click on Finish to run Android Studio for the first time.
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.