Scratch game making tutorial 113

Auto-bots 1

In this tutorial you will programme a robot (bot) to follow a path.

 

1. Create a new game and then right-click the cat thumbnail ("sprite1") to delete the cat sprite.

 

 

2. Select the stage, switch to the "Backgrounds" tab and then import this background image ..

This background has a black pathway drawn on it.

Now delete the blank white background.

Later you may wish to paint your own pathway background. To do so you will need to use this brush size (middle row, far right) ..

 

 

3. Create this variable ("for all sprites") ..

This variable will allow you to control the speed of multiple bots by dragging an on-screen slider.

Right click the variable display on the stage and select "slider" ..

Now right click it again and select "set slider min and max" and set the values to these ..

You will be able to set the speed of your bots between 0 and 5.5 steps.

Position the variable slider on the stage somewhere between the black paths.

 

 

4. Add these scripts to the stage ..

When the game starts the bot's speed will be set to 1 step.

 

 

5. Use "File>Save as" to save your game. Name it "Auto-bots 1".

 

 

6. Time to script the bots. Download and save this sprite ..

Now use the "Choose new sprite from file" button under the stage to load it ..

 

 

7. Select the Costumes tab and then click the "edit" button to have a closer look at the bot costume ..

We are looking down on the bot. It has 2 front "wheels", one green and one blue. It also has a thin yellow nose. We will use these colours to make the bot stay on a path. Whenever the bot tries to leave the path, the wheels will make it turn back onto the path.

 

 

8. The bot's red body needs to be approximtely the same width as the path. Also, we want the bot to start at a random place on the stage so we can watch it find and join (acquire) a path.

Add these scripts to the bot ..

 

 

9. Now for the clever bit. We need to add the scripts to make the bot stay on the path (you don't need to add the comments) ..

Notice how the bot moves 1/3 speed when it is turning back onto the path.

Press the "B" key to test your scripts. Press "E" to end when you are done.

 

 

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

 

 

11. If you are sure your bot scripts are correct and working well, duplicate the bot sprite until you have multiple bots. Try 6 to start with.

Press the "B" key to test your game. Press "E" to end when you are done.

 

 

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

 

 

13. Well done. You've finished. Could you turn this exercise into a full game?