Reader small image

You're reading from  Android Game Programming by Example

Product typeBook
Published inJun 2015
Reading LevelIntermediate
Publisher
ISBN-139781785280122
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
John Horton
John Horton
author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton

Right arrow

Chapter 5. Platformer – Upgrading the Game Engine

Welcome to the second project of this book. Here, we will build a really tough retro platform game. It is not tough to build, but tough to beat when you play it. At the end of the project, we will also discuss ways to make the game play a little less punishing should you wish.

This chapter will focus entirely on our game engine and essentially lead to an upgraded version of the Tappy Defender code.

First, we will discuss what we want to achieve with this game: the backstory, game mechanics, and rules.

Then, we will quickly create an activity that instantiates a view that will do all the work.

After that, we will flesh out the basic structure of our PlatformView class, which will have some subtle, but important differences to our TDView class. Most notably, PlatformView will have a simple but effective way of managing the timing of all the events of our game.

We will then start the iterative process of building our GameObject class, from which...

The game


The game we will build is based on the game play of some of the brutally hard platform games of the '80s, such as Bounty Bob Strikes Back and Impossible Mission. These games featured difficult jumps and required insanely precise timing at the same time as giving the player an unforgiving number of lives/chances. This style of game works well for us because we can actually build a multilevel playable game in just four chapters.

The design of the classes will make it really easy for you to add your own extra features, and game objects or make it slightly less challenging to play should you want to.

The backstory

Our hero Bob, having just returned from a secret mission to destroy an evil scientist at the center of the Earth, finds he is deep underground. Worse, it seems that although he has defeated the evil scientist, it was not in time to save the planet from the powerful guards and deadly flying robot drones that he unleashed.

Bob must make his way from the deep underground fiery cave...

Upgrading the game engine


All the talk of guards, drones, fire, collectibles, guns, and the implied much larger game world suggests a much more complex system to manage. One of the goals of our game engine will be to make this complexity easily manageable. The other goal will be to separate the level design from the coding. When our game is done, you will be able to sit back and design the most evil, yet rewarding levels, in multiple different environments without touching the code.

The platform activity

First we start off with our Activity class, which is the entry point into our game. There is not much new here, so let's go ahead and get it built quickly. Create a new project, and in the Application Name field, enter C5 Platform Game. Choose Phones and tablets, then Blank Activity when prompted. In the Activity Name field, type PlatformActivity.

Tip

Obviously you don't have to follow my exact naming choices, but just remember to make minor alterations in the code to reflect your own naming...

Summary


We have covered a lot of ground in this chapter, and now have a well fleshed-out game engine.

As we have done much of the setup work, from now on, most of the code we add will also have a visible (or audible) result and be much more satisfying, as we will be able to regularly run our game to see the improvements.

In the next chapter, we will add sound effects and input detection, thus bringing Bob to life. Then, we will see how dangerous his world can be, and will promptly add collision detection so that he can stand on a platform.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Android Game Programming by Example
Published in: Jun 2015Publisher: ISBN-13: 9781785280122
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.
undefined
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

Author (1)

author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton