The code structure
We will have two activities, one for the menu screen and one for the game screen. The menu screen activity will be called MainActivity
, and the game screen activity will be called GameActivity
. You can find all the completed code files as well as all the assets such as images, sprite sheets, and sound files in the Chapter8/Snake
folder in the download bundle.
MainActivity
In contrast to our other projects, the menu screen will not have a UI designed in the Android Studio UI designer. It will consist of an animated snake head, a title, and a high score. The player will proceed to GameActivity
by tapping anywhere on the screen. As we need to accomplish animations and user interactions, even the home screen will have a thread, a view object, and methods normally associated with our game screens, like this:
MainActivity.java file Imports MainActivity class Declare some variables and objects onCreate SnakeAnimView class Constructor ...