Here we are, over a third of the way through the book already, and now we finally hit our first mobile game. Well, this game is not the typical mobile or desktop game; this game, Chain Reaction, will be built for the Android platform. So, get your Android-powered phone/tablet and get cooking!
Have you ever worked inside a nuclear power plant? There, you have to avoid a chain reaction that could cause a nuclear meltdown. In Game #4, Chain Reaction, we want to create exactly that—a chain reaction. You will have a map of atoms in front of you and can trigger just one atom to start spinning. Will you be able to pick the right one and cause the biggest and longest chain reaction?
In this chapter you will:
OnResume
and OnSuspend
eventsIn Chain Reaction, the player will see a grid of 8 x 11 atom elements in front of him/her. There are elements with 1, 2, or 3 connectors. The player now has to choose one by touching it. Now, this element will rotate clockwise by 90 degrees. After the rotation is done, the game will check if the neighboring elements connect to the previous element. If yes, a sound will be played, the score will be raised by 1, and these connected elements will start to rotate. The goal of the player is to touch the elements that will hopefully start the longest chain reaction.
Do you want to develop this game? Of course you do! So let's get on with it.
HTML5? We are creating an Android app, so why modify the HTML5 canvas size? Well, you will notice that compiling for the Android platform will take a while, much longer than for HTML5. In the game, we don't use Android-specific features. Hence, we can develop and test the game in the HTML browser. For this, we want to change the canvas size of the HTML5 build. By default, it has a size of 640 x 480 pixels. As we have a target canvas size of 480 x 800 pixels, we want to change that.