Scratch games making tutorial 146b

Path finder intermediate

In this tutorial you will create a game in which the Cat must reach rewards by running down paths which the player can individually rotate to create a route for the Cat.


Complete these steps ..


1. Open Scratch, OR create a new game (from the top menu choose "File>New").



2. Select the stage then edit the existing white background and use the paint bucket tool to paint it black. In the game the Cat will be prevented from walking on anything black.



3. Switch to the stages Script tab and add the following scripts to begin and end the game ..



4. Now select the Cat sprite, re-name it, and then click the "only face left-right" button ..



5. You need the Cat sprite to be really small so that it can easily run down the coloured paths.

Add the first scripts to set its starting properties ..



6. You need several sprites for your game. Download and save the following sprites ..


Path 1.sprite

Path 2.sprite

Path 3.sprite

Path 4.sprite

Path 5.sprite

Path 6.sprite

Reward 1.sprite

Now use the "Choose new sprite from file" button under the stage to import the sprites into your game ..

NOTE: You only need one Reward sprite for now, you will duplicate it when you have added the scripts to it.



7. Use "File>Save as" to name and save your game. Name it "Path finder intermediate" ..



8. Select the red Path 1 sprite and then select its Costume tab and click Edit. Now click the "Set costume center" button and you will see that the costume center point has already been set for you ..

The costume can rotate around this center point. Click cancel and return to the Scripts tab.

The player will be able to click on any Path to rotate it, so that they can create a route for the Cat to the Reward sprites. This creates a problem.

It is possible that a path will rotate away from the Cat sprite leaving it standing on black. You need to ensure that if the Cat is standing on a path that the player is rotating, the Cat stays on the path. You can do this by saving the paths X and Y co-ordinates in variables and then make the Cat go to them when the path is rotated. You need to make this only happen for the path the Cat is touching (current path), not other paths.

Create the following variables (for all sprites) ..


The player does not need to see these variables on the stage so you can hide them (leave them un-ticked).



9. Add the first script to Path 1 to set its properties for when the game begins ..



10. Now add the script that will ..

To create a bit of variety you can set each path to rotate either 9 degrees or -9 degrees.


Check the script very carefully and when you are sure it is correct, drag both path scripts and copy them to all 6 path sprites.

Now go and change some of the path rotation scripts to 9 degrees and some to -9 degrees like this ..



11. Drag the 6 paths and arrange them randomly on the stage. Something like this is good ..



12. You can go full screen (presentation mode) and test that the paths are rotating when you click on them. If you like, show (tick) the "current path x" and "current path y" variables so you can see the values change. When you are done un-tick them again to hide them.



13. Use "File>Save" to re-save your game ..



14. Select the Start sprite. The Cat will start the game from this sprite so we need to set its properties for when the game begins.

Add these scripts ..



15. The player will control the direction of the Cat sprite with the arrow keys, but you need to prevent it from walking on black.

Add these scripts to the Cat sprite ..



16. When the game begins you need to ensure that the Cat is NOT standing on black. A script is needed to send it to the Start sprite.

You also need the Cat to move to the center point of a Path if the Cat is touching the path when the player rotates it.

You can achieve both of these with the following scripts. Add them to the Cat sprite ..


Go full screen and then press the "B" key on your keyboard to test your Start, Cat and Path sprite scripts. You should be able to rotate the paths and direct the Cat along them.

Press the "E" key to end your game and continue working on it.



17. Use "File>Save" to re-save your game ..



18. The Cat must reach and touch Reward sprites to gain rewards.

Add the first scripts to the Reward sprite to set its size and hide it when the game begins ..



19. The Reward sprite has 3 simple costumes which help create a flashing effect ..


Add this simple script to make the Reward flash when it appears ..



20. You want the Reward sprite to appear at random positions around the stage, and at random times. Make it appear every 3 seconds and remain visible for 20 seconds so the Cat has a good chance of getting to it and touching it. Add this script..


Go full screen and then press the "B" key on your keyboard to test the Reward sprite.

Press the "E" key to end your game and continue working on it.



21. Use "File>Save" to re-save your game ..



22. The Cat is not yet earning any rewards when it touches the Reward sprite, and you don't have a countdown time limit for your game. it's time to add the scripts to allow this.

Select the Variable scripts and create the following variables "for all sprites" ..


Arrange the variable displays on the stage like this ..



23. Select the Rewards 1 sprite and add this script ..


Go full screen and then press the "B" key on your keyboard to test the Reward sprite and your new variable.

Press the "E" key to end your game and continue working on it.



24. It would be better if there were two Reward sprites which appear at different times and locations on the stage.

Right-click the Reward 1 sprite under the stage and duplicate it and then re-name it "Reward 2".



25. Edit the Reward 2 sprite's scripts so it hides for 6 seconds instead of 3 ..



26. Use "File>Save" to re-save your game ..



27. You're nearly finished. The only remaining script is for the countdown timer. Add its script to the stage ..


Go full screen and then press the "B" key on your keyboard to test your game.

Press the "E" key to end your game and then use "File>Save" to re-save it ..



28. Well done, you've finished making the game! Can you improve it? How about making your own additional path backgrounds? Or adding enemy sprites which follow the Cat and steal rewards?