Chapter 22. Exploring More Patterns and Planning the Platformer Project

Welcome to the start of the final project. Over the next four chapters we will build a platform game packed full of features like parallax effect scrolling, animated controllable character, multiple different and challenging levels and much more (keep reading for more details).

During this project we will discover more Java patterns like the Singleton, another Java data class, the HashMap and explore the gaming concepts of a controllable camera and an animator.

At the same time, we will reinforce all the Java concepts we have already learned including aiding our understanding of and improving upon the entity-component/factory patterns we used in the previous project.

Here is what we will do in this chapter:

  • Discuss how we will build the Platformer project including design patterns, Camera class, level design files, improved graphics handling using the Singleton pattern and improved Transform class
  • Get started with the Platformer project
  • Specify all the game objects with ObjectSpec classes
  • Code the interfaces for the components that we will begin coding in the next chapter
  • Code the communications interfaces like EngineController, GameEngineBroadcaster and InputObserver

Be sure to read the next information box. It is probably the most useful in the book.

Note

The first 2 chapters of this project are long, and the classes are all interdependent with each other- they are parts of a system. The project is not executable until the end of chapter 23. You can read and code chapter 22 and 23 a step at a time if you like but it will take quite a while- make sure you have at least the day to spare. Alternatively, you could just read chapter 22 and 23 and carefully review the code and the patterns to make sure you understand what is happening. Then you could simply add the graphics and sound (explained in this chapter), create 2 packages (explained in Chapter 22, Specifying all the game objects with GameObjectSpec classes, section and Chapter 23, Create the levels, section). Then you can just copy and paste all the class files from chapter 23 folder of the download bundle into the proper package of your project (via the Android Studio project explorer window). You will then need to make sure/correct a few lines of text in a few files to do with importing your new packages and the first part of the engine can be working within an hour's work- after having first read through chapter 22 and chapter 23 thoroughly.

Choose whichever method you find the most rewarding.

Tip

WARNING! If you don't read the two chapters first you won't understand how to make the package import corrections I referred to in the earlier information box, you won't understand the structure of the code and the code won't work.

Now we can make a start. Let's call the platformer, Bob was in a hurry.

Platform Game: Bob Was in A Hurry

This is the most advanced game in the book. It has multiple levels and hundreds of game objects per level. The player must get from the start of the level, find and then reach the exit. Fastest times are kept as high scores for each of the three levels. However, there are also collectable coins scattered throughout the levels and a time penalty is added on to the finish time for each one left uncollected. Precise jumps are required, and the best route is not always obvious so a player wanting to do well will need to explore and experiment. The whole level is not visible on screen all at once. The level can be dozens of times the size of the screen, so exploration is required to see the whole thing.

Let's have a look at some screen-shots to understand the game better.

Platform Game: Bob Was in A Hurry

In the previous image you can see the home screen. The text labelled as number one is the fastest times for each of the three levels, Underground, Mountains and Cave. Double tapping on the appropriate third of the screen will start the level and the timer.

Take a look at this next image taken from the Underground level.

Platform Game: Bob Was in A Hurry

The levels each have their own distinctive background to set them apart from each other and there is also a good selection of decorative objects, platform designs and obstacles for each level. We will see more of the graphics soon. In the previous image notice the following things:

  1. The time is in the top left-hand corner. The format is as follows: number of seconds taken so far + number of penalty seconds that can be removed by collecting all the coins.
  2. Number two highlights the collectible coins.
  3. Number three highlights an animated fire tile. The tile will flicker, making it obvious this tile is bad for the player's health. The slightest touch will end the level and send the player back to the home screen.
  4. Number 4 is a Death tile. We need to stop the player accidentally getting out of the level into an eternal fall. By surrounding possible exits with Death tiles, we can end the game when the player falls or gets themselves into an impossible position. The tiles use a distinctive graphic to make level design and debugging clearer. In the finished game you would use a transparent (invisible) graphic or change it to something that matched the level.

This next image shows the Mountain level which is mainly a series of awkward jumps. The part highlighted number 1 is the level destination. When the player reaches the highlighted game object the game goes back to the home screen and if they got a faster time it will be updated.

Platform Game: Bob Was in A Hurry

The next level shown below is the City level. I have borrowed the background from the previous project.

Platform Game: Bob Was in A Hurry

In the image I have highlighted three rectangles. They are moving platforms. They go up and down a distance of 10 blocks. Once you see how to code them, it will be trivial to add horizontal movement or vary the distance they travel.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.242.71