Implement Functions to Create and Update the Game

Implement the functions to create, initialize, and update the game.

Introduction

In the previous lesson, we initialized all the different game states required for the game. Now, we need to implement the createGame() and updateGame() functions, which are called from the GameState state created earlier.

Implement the function to create the game

Let's start with the implementation of the createGame() function. We'll be implementing the following steps in this function:

  1. Set the game world coordinates using the setBounds() function and specify the (x, y) coordinates we want the game world to start from and the width of the game world. These can be thought of as the dimensions in which our game is going to be rendered.

  2. Start the physics system for our game to apply velocities, gravities, and so on to the game objects.

  3. Generate the jumps array for 29 islands (the 30th30^{th} island is the last one so it does not require an entry in the array) containing integers ranging from 1 to 3, where each integer will denote the maximum number of jumps that can be taken from each island to reach the last island.

  4. Create a Group object for rendering clouds on the game screen. A Group object is a collection of similar game objects rendered in the game world.

  5. Add the sun's image as a sprite, because we'll be applying animations on it.

  6. For all 30 islands, create the island and display the maximum number of jumps that can be taken from it. For the last island, increase the size of the island object rendered in the game world.

  7. Add all the remaining images to the game world, and apply the animation on the flag image once the frog (player) reaches the last island.

Here's the code:

Get hands-on with 1400+ tech skills courses.