This is part three of a three part series about making a platform game in Scratch. In this tutorial we’ll be adding a goal for our character to reach, new levels, and an ending screen.
- Part 1 – Character Creation and Intro Screen
- Part 2 – First Level and Character Movement
- Part 3 – Adding a Goal, More Levels and an Ending Screen
Star Light, Star Bright…
Let’s add our goal, a star. Click on the paint new sprite button to add our star sprite. Using the paintbrush tool, and a dark yellow color, draw the outline for your star. Don’t worry if it’s not perfect!
Next, select the fill tool and the bright yellow color and fill the star in:
Switch to the scripts tab to add a script for our star. When the green flag is clicked we want the star to be hidden. When the game starts we want the star to appear above the upper platform.
If you run the game now, you should see the star appear above the upper platform like so:
However, nothing happens if our blue guy reaches the star! Not yet at least, let’s fix that…
Reach for the Stars
Go to the variables palette and add a new variable for all sprites called “Level”:
Now let’s switch back to the scripts tab for the blue guy sprite. When our blue guy touches the star we’ll increment the level and broadcast the message “Next Level”. In order to avoid incrementing the level more than once, we’ll hide our blue guy and move him to a different location on the stage before we show him. This way he won’t be touching the star on the next pass of the loop. We should also set the value of Level to 1 when the game starts off. Here’s what the blue guy script looks like now:
Since we only have one level at this point, nothing interesting will happen when the blue guy touches the star. We need to add at least a couple more levels.
Following the steps that you took to create the first level (in the previous tutorial) add at least two more levels. You can do anything your heart desires with the levels, just be sure that it will be possible to get the star on each level because otherwise that won’t be any fun!
Here are some examples for the next two levels:
Before this will work, we need to add code that will switch to the next costume each time the Level sprite receives the “Next Level” message. Here is the updated script for the level:
Finally, switch to the star sprite script and add code to move the star to a new location when the star sprite receives the “Next Level” message. Locate the star in a spot that makes sense for that level. The coordinates that I provided below are for the level layouts that I had created:
OK, that’s it… Test out the game now. Does it work? What happens when you get the star on the last level? Hmmm…
The final step in completing our game is to show a screen with the message “You Win!” after the blue guy reaches the last goal.
First, let’s add an if-else block to our blue guy’s script. If the value for our level is greater than 3 (our last level), then we’ll broadcast the message “Game Over”, otherwise we broadcast “Next Level”, reposition the blue guy and show him. Here’s the final version of the blue guy script:
Now, let’s change the script for our star so that the star is hidden when it receives the “Game Over” message:
We also want the level sprite to be hidden at the end of the game:
Finally, we need to add a new background for our stage that we’ll show at the end of the game. Switch to the stage and click on the backgrounds tab. Now click paint to create the “You Win!” background:
Almost there…Switch to the scripts tab for the stage and add blocks to handle when the green flag is clicked (show intro background) and when the Game Over message is received (show the You Win background):
That’s it! Try playing the game now…Can you get the “You Win!” screen to appear?
I hope you found this tutorial helpful. If you’ve had any problems, the completed game can be found on the Scratch website at:
Now, go make your own platform game!