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:
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.Start the physics system for our game to apply velocities, gravities, and so on to the game objects.
Generate the jumps array for 29 islands (the
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. Create a
Group
object for rendering clouds on the game screen. AGroup
object is a collection of similar game objects rendered in the game world.Add the sun's image as a sprite, because we'll be applying animations on it.
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.
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.