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:
Camera
class, level design files, improved graphics handling using the Singleton pattern and improved Transform
classObjectSpec
classesEngineController
, GameEngineBroadcaster
and InputObserver
Be sure to read the next information box. It is probably the most useful in the book.
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.
Now we can make a start. Let's call the platformer, 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.
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.
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:
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.
The next level shown below is the City level. I have borrowed the background from the previous project.
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.
18.118.149.19