Game making tutorial 47

Auto shape drawing advanced

In this tutorial you will create a game in which mouse clicks on the stage cause shapes to be drawn. You will script algorithms create a variety of shapes and then experiment to create your own.

Complete these steps ..

 

1. Create a new game. Either open Scratch or if it is already open choose "File>New" ..



2. Delete the cat sprite1.

 

 

3. Fill the stage background with black so that the shapes show clearly when they are drawn.

 

 

4. Paint a new sprite with a single black dot. Use the smallest paint brush size to paint it and name it "Pen point"..



5. Create these variables (for all sprites) ..

These variables will be used by the player to change the shapes that the pen draws.

Position them on the stage along the top like this ..

Right click on each variable on the stage and select "Slider" ..

Now right-click on each again and set the slider range (Min and Max) for each variable to these values ..

Variable Min Max
Pen size 1 20
Pen color 0 200
Shape 1 4
Shape size 10 100

 

 

6. Save your game. Name it "Auto shape drawing".

 

 

7. Add these scripts to the pen to set the variables to their initial values and to clear the stage ..

 

 

8. Now you must add the scripts that draw the shapes when the player clicks their mouse on the stage. The player will choose the pen size and color, and the shape and its size, by dragging the sliders on the stage.

 

First you must ensure that the pen only draws when it is below the sliders on the stage. Add this script (134 will work if your variables are placed near the top edge of the stage) ..

Now add the next script blocks to the script you have just created. These new blocks prepare the pen to draw the shape ..

 

 

9. Save your game.

 

 

10. Now we need to complete the script by adding 4 more "if" script blocks below the one we have just created. Each of these will draw a different shape ..

 

 

11. Save your game. You're done! Press "B" to test your game.

 

 

12. Edit, or add new, "if" script blocks to create your own shapes. If you add some more, don't forget to change the slider max value for the shape variable.