Today we are going to start making a role playing game or an RPG. We are going to learn how to use conditional statements to animate our sprite and change the backdrop! Next lesson we will continue our game by coding an object for our character to find.
Step 1. Open Scratch
Go to scratch.mit.edu in your preferred browser.
Log in with your username and password.
Find the Quest Game Starter in your class studio and open it, and click
You will now see the start of your project with four sprites:
Step 2. Take a look at your Character sprite
Look at the code already on your Character2 sprite. This code animates the sprite.
It is a lot of code but it is very simple!
Look more closely. There are four conditional statements telling the sprite what to do when each of the arrow keys is pressed.
When a key is pressed the sprite points in the direction of the arrow, and switches between three costumes and moves three times.
Hint: If you look at the sprite’s costumes in the costume tab you will see all the different costumes for the different movements.
Step 3. Take a look at the House Entrance and Ouside Door
Look at the House Entrance and Outside Door sprites. You will see code already on these sprites.
These scripts tell the sprites when they need to show and hide!
Step 4. Go inside the house
Add this script to your Character2 sprite.
This script will tell the backdrop to change to inside, hide the house and change the x location when you touch the House Entrance sprite.
Add this block to the script:
This conditional statement will make the sprite go back to the town backdrop if it touches the Outside Door sprite.
Step 5. Head to the forest!
Add this script to the Character2 sprite.
What edge does the sprite have to walk to to get to the forest?
Hint: We test what the current backdrop is so that the sprite will only go to the forest if it is already in the town. It will not go to the forest from the other locations!
Add another conditional statement to your Character2 sprite.
Step 7. Extension: Go to the water
If the sprite walks to the right edge of the screen it should go to the water backdrop.
Add the script below to the Character2 sprite, and fill in the blanks make it do this!
Hint: the right edge is x = 240, and the left edge is x = -240
Step 8. Extension: Make the sprite avoid objects
Add the script below to your Character2 sprite. This will stop the sprite from bumping into the different objects.
Hint: There are at least three different objects your sprite should avoid. Can you find them? Remember to click the square in the touching colour block and then the colour you want the script to sense.