EN Scratch 3 Course Notes PDF
EN Scratch 3 Course Notes PDF
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 1
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Table of Contents
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 2
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Introduction to Scratch and the Art of Coding
What is a program?
A program is a set of instructions that tells a computer or other electronic device
what to do. These instructions or commands are written in an artificial (i.e. non-
speaking) language. The script used is often referred to as code or computer code.
Computer programing or coding is the process of writing code.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 3
Code Week and was developed by Brendan Smith for the Camden Education Trust.
these online projects are remixes of other projects on the website
http://scratch.mit.edu
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 4
Code Week and was developed by Brendan Smith for the Camden Education Trust.
As children enjoy the challenge of creating and sharing Scratch projects, they learn
important mathematical and computational ideas such as arithmetic (addition,
subtraction, multiplication, division of numbers), geometry (branch of mathematics
that deals with the measurement, relationships of points, lines, angles etc. via such
terms as coordinates, shapes, size, relative position of figures), algebra (variables,
symbols representing numbers for explaining quantities and numeric relationships)
as well as additional concepts such as algorithms, while also learning to reason
systematically, solve problems, work collaboratively and develop presentational
skills.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 5
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 1 - Introduction to Scratch Interface
This site should also be used to store the best examples of the projects created by
your participating students, so that other mentors can used them as teaching
resources in their classroom and as examples for other participants to emulate.
However you can join the existing Code for Africa community by going to the Sign
In option and
Under Username, type in africacodeweek
Under Password, type in fionnfionn.
To upload a completed project from your computer or other smart device onto the
Africa Code Week account on the Scratch website, first go to the Create option in
the menu bar.
Then select under the File option Load from your computer
As a teacher, you may wish to create an account on the Scratch website for your
class, or school or group that can be used to host samples from each of your
participant’s work.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 6
Code Week and was developed by Brendan Smith for the Camden Education Trust.
This course though will use the Scratch Offline Editor.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 7
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 2 - Coding: The First Steps
In Scratch, sprites can move around, be active or be objects that stay still. We will
choose a sprite character that we will animate.
A sprite’s action comes from a response to scripts inputted by the user into the Script
(scripts or programme code) Area. These scripts are the instructions or commands
that tell the sprite what to do and are written in a sequence. The user drags individual
pieces of code from the Blocks’ Palette into the scripts area. These blocks then fit
together like pieces of children’s building bricks to create the instructions.
So let us enter Scratch and program the sprite to talk and to move around the
screen!
To open Scratch on your smart device, double click on the Scratch icon on your
computer.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 8
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Take your time and familiarise yourself with the main features of this screen or what
we will refer to as the Scratch Interface (Home Page).
Notice that the small version of the cat is highlighted in blue signifying that it is the
active component.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 9
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Placing Text
By placing blocks in the Script Area, the sprite will tell us his/her name.
First go to the Blocks’ Category section located at the left hand side of the Scratch
interface which contains thematic folders of blocks of code such as Motion, Looks,
Sound etc.
To the right of this section of the graphical user interface is what is referred to as
the Blocks Palette that contains all the individual blocks of code.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 10
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Make sure the blocks click together.
To do so, click on the at the top left of the cat sprite icon and type in the text
Fionn or your name choice in the relevant box.
Click the Green Flag at the top left hand side of the computer screen and see what
follows.
Select the Move block and change the number of steps to 50.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 11
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Attach this block to the rest of the blocks in the script area and start the program.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 12
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Place this block in the Script area with the addition of some extra Move blocks:
As you may have noticed, if we keep using this script, the cat will keep moving until
it almost disappears off the screen.
So we have to put in an extra command that will bring him or her back to the centre
of the screen on every occasion that we use this set of instructions.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 13
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The screen is divided into X (horizontal) and Y (vertical) coordinates based on the
centre of the screen being (X)0 (Y)0 and the numbers being positive or negative
depending on their positioning.
Get your pupils to move the sprite around the screen and watch as the values of the
X and Y coordinates change just above the sprite small icon at the right side of the
Sprite Interface as the sprite changes position.
This function allows the user to position different sprites at different locations.
(See later explanatory box on Geometry).
Hence we can place a piece of code or block at the beginning of the set of
commands that will instruct the cat to move back to the centre of the screen every
time that we select the Green flag.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 14
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Test the effectiveness of this new piece of code by using the mouse to position the
sprite towards the bottom or top of the screen before clicking on the Green Flag
icon.
Different methods other than a Green Flag can be used to start a script using the
‘When’ commands in the Control folder
So replace
with
Now click the Space Bar on the computer keyboard to start the programme.
Replace
with
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 15
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Saving the project
Go to the File folder
Select ‘Save to your computer’
Type in Fionn, or your own name for your cat icon in the section Save As……..
Then choose the option where you want to store it, such as Desktop or My Projects.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 16
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 3 - Placing Sounds in a Script
Play the
programme.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 17
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Now replace the cat meow in the script with other animal noises.
and clicking on the speaker icon at the bottom left hand corner of the page.
Click on your preferred sound which will then appear on the list of sounds on the
left column (under the heading Code).
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 18
Code Week and was developed by Brendan Smith for the Camden Education Trust.
You can now include the new sound in your script by selecting the relevant block (&
sound option) of code
Exercise
Wow! A Talking Cat!
Now let us get the cat to say the words that we have written into the programme,
namely Hello and My Name is Fionn.
Click on the Microphone image in the row of icons to the bottom left of the screen
as shown below:
Then choose to record your voice by clicking on the RED button below
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 19
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Say loud and clear, the word “Hello”.
You can trim and edit the audio as
required.
Return to the Script Area and select the Sound (pink) category.
Place the play sound My Voice block in the script just above the say hello for 2 secs
block
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 20
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 4 - Making the Sprite Walk Better
Let us now make the cat more realistic in its movements by getting it to move its’
legs when she/he walks.
This can be done by changing the physical look of an individual sprite under the
section labelled Costumes.
Go to Costumes and notice that there is a second image or Costume of the same
sprite with the legs and arms in different positions than that of the first image.
After the first Move and Wait blocks located in the script, place in a ‘Switch to
costume block with Costume 2‘ taken from Looks.
The option Costume 2 is chosen by clicking on the inverted black triangle icon
located to the left side of this block
Then, for the next Move and Wait blocks, place in a Switch to costume block with
Costume 1.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 21
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Play the Script by clicking on the Green Flag icon
This piece of code states that the sprite will change costume and move forward one
set of steps not just once but forever. Furthermore, the addition of if on edge
bounce command means that the sprite will not disappear off the screen but
turn each time it reaches the end of the screen in order to continue walking.
However you might now find that the sprite is walking upside down!
To ensure that the cat is standing upright and moving face front, go to the Motion
category and place under
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 22
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 5 - Multi-Coloured Sprites
Repeat this process for both Costume 1 and 2 until you have nine costumes.
Change the Costume numbers in the script so that they appear chronologically.
To the right of the icon costumes is the Paint Editor, which allows one to colour in
existing sprites as well as to paint and draw new ones.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 23
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Choose a different colour from the palette box labelled Fill
Select a colour and use the paint bucket icon to bring this new characteristic into
the existing Sprite on the screen.
Please ensure that the Paint Editor is in Bitmap Mode for use of the paint bucket
tool.
Note: Introduce to the students some of the other features of the Paint Editor
including duplication, text and erasing tools.
Repeat this process to bring a new colour into all of the remaining costumes
Play the Script by clicking on the Green Flag icon and watch the cat of many colours
walk!
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 24
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 6 - Changing the Backdrop (Stage)
At present, we are using a blank backdrop or background for the cat.
So let us bring some excitement into its’ life by having the cat walk around a new
landscape.
If you view the bottom left side of the screen, you will notice that Fionn the cat is
presently highlighted in blue which signifies, as mentioned previously, that the Sprite
is the action element in the Script.
Click on Stage.
The Stage icon is now highlighted in blue signifying that it has now become the
active element that the user can now change.
Go to the New Backdrops icon located under the Stage icon and select either of the
bottom options in the row of five icons (see below).
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 25
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Click on the Green Flag icon to start the programme.
You will now notice though that we have now got a problem, namely that Fionn the
cat looks as if it is walking on air!
So first ask the students to come up with a solution on how to code the script in
order to make the cat move across the floor of the bedroom.
We will of course have to put in some extra command code in a script for the cat
that will ensure that the it walks along the floor.
So double Click on the Backdrop icon to move back to the Script of the Sprite (cat).
Move the Sprite to the bottom left-hand corner of the Stage screen.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 26
Code Week and was developed by Brendan Smith for the Camden Education Trust.
GEOMETRY
Computer Images are made up of Pixels. They can be identified using X & Y
Coordinates.
A computer screen or a picture is made up of basic units known as Pixels. It is an
abbreviation of two words, picture and element.
Pixels are the smallest units of colour on a computer display or in a computer image
that can be controlled or programmed.
X, Y coordinates are respectively the horizontal (X) and vertical (Y) addresses of any
pixel or addressable point on a computer display screen.
The x coordinate is a given number of pixels along the horizontal axis of a display
starting from the pixel (pixel 0) in the centre of the screen. The y coordinate is a
given number of pixels along the vertical axis of a display starting from the pixel
(pixel 0) in the middle screen. Together, the x and y coordinates locate any specific
pixel location on the screen.
X & Y coordinates are part of the branch of mathematics known as Geometry which
is concerned with questions of relative position of figures, shape, size, and the
properties of space.
To familiarise users with XY gridlines, go to the new Backdrop section, as had been
undertaken previously above and select the last or second last icon in the row of
five icons. Then choose the xy-grid, the third last of the screen options in the
backdrop library.
Allow students to view the screen and move the sprite around in order that they
come to an appreciation of coordinates.
Explain their importance for instance in computer gaming (e.g. moving objects in a
game to a start position).
Return to the Bedroom 2 backdrop.
Move the cat to the top right hand corner of the stage. The X and Y coordinates for
the cat will appear under the stage as follows:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 27
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Once the cat is in position, the current X & Y coordinates for the cat will appear in
the X and Y boxes (as shown in the image above)
Go to Motion.
Move this block into the Script Area and position it directly under the first (Green
Flag) block in the set of programme instructions.
As mentioned above, the X and Y coordinates for the cat will be shown in the block.
Question: What do we have to do to get the cat to jump onto the bed?
The operator of course must instruct the sprite to move onto the bed by placing, in
the correct spot in the programme, a Motion block that includes the correct X and
Y coordinates.
Go to Motion.
The new X & Y coordinates (of the cat on the bed) will be shown in the block of
code. Move this block into the Script Area and position it in the correct location in
the set of programme instructions (probably best to locate it at the end of the
programme).
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 28
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Click the Green Flag icon to start the programme.
Save your programme file with the name CatJumps by selecting Save to your
computer in the File pull-down menu located at the top of the Scratch screen.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 29
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Exercise
Place some further blocks of code in the programme that will allow the cat to jump
off the bed and walk a few steps.
Furthermore, ensure that the cat changes colour for each step of the remainder of
his walk.
Exercise
Replace the backdrop with a new image from the Backdrop Library.
Notice that the new backdrop appears in a list of backdrops for your project on the
left side of the screen.
To revert to a previous or new backdrop, just bring your cursor onto the appropriate
backdrop image and click.
The new image is now highlighted, is the active element and becomes the backdrop
that appears on the Stage screen.
Then re-do the instructions so that the sprite jumps on and off some object that is
in your selected picture.
Note: the user has to click on the sprite image of the cat before it is highlighted (in
blue) when code can be added.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 30
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Save your new programme file with the name CatJumps2 by selecting Save to your
computer in the File pull-down menu located at the top left side of the Scratch
Interface.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 31
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Select a bird with two costume changes (so as to give the impression of wing
movement).
Go to
followed by
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 34
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Then go to the Animal folder and select the first running dog image (dog1).
Notice that the Dog icon is now highlighted in blue outline signifying that it is the
sprite that is currently active.
We now have to build a script or programme to operate the dog sprite allowing
him/her to run and to talk.
So in order to do so, we have at least one other version of the dog that will, in
combination with the existing dog costume, gives the impression of motion.
Selecting Costumes shows that there are two versions already available for use in
the programme.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 35
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Building a Script to operate the Dog
Go to the Blocks categories located on left side of
the Scratch Interface.
This will mean that once the Green Flag above the Stage is clicked, the sprite will
follow the commands that are placed in the Script Area.
However remember that we now have two sprites, namely the cat and the dog.
We want to have the dog only appear on stage (screen) after the cat has jumped
on the bed.
Hence we must have it hide when the programme begins, and only appear (show)
in the scene at a certain location (X & Y) after a certain amount of time has elapsed
(wait).
The following blocks in a combination sequence will allow the operator to undertake
this task:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 36
Code Week and was developed by Brendan Smith for the Camden Education Trust.
and the Wait block in the Control category
as well as the X and Y coordinates block in the Motion folder. The coordinates should
reflect a position to the far left of the cat (on the same X axis) and close to the edge
of the screen.
To get the sprite to give the appearance of motion, we first have to place a Switch
to costume command block towards the beginning of the script so that the first
version of the dog, namely dog1-a, always appears once the programme starts.
After the first Move (in this case go to x ___ & y___ block) and Wait block located in
the script, place in a ‘Switch to costume’ block with dog1-b taken from Looks.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 37
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The option dog1-b is chosen by clicking on the black triangle icon located to the
right side of this block
Then for the next Move and Wait blocks, place in a Switch to costume block with
dog1-a.
Repeat this process all the way through the script, thus alternating in sequence
between dog1-a and dog1-b.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 38
Code Week and was developed by Brendan Smith for the Camden Education Trust.
A Scared Cat!
In order to give more authenticity to the project, Fionn the cat needs to shout “Help!”
and put on a sad face when the dog appears and before it jumps on the bed.
Whilst on the bed, why not have the cat’s face full of tears!
So as an exercise get the students to create an extra costume change(s) for the cat
and place in appropriate code within the Script Area.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 39
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 8 - Creating a Sprite
In this lesson students are introduced to the powerful Paint Editor facility of Scratch
which allows users to create their very own sprites.
Click on the Stage icon at the bottom right of the screen and select the Beach Malibu
scene from the Outdoors section of the Backdrop Library.
You can include the cat sprite in the beach scene. But relocate him/her to the bottom
left hand corner of the screen, inputting a script that will have the cat walk back and
forth across the beach.
Now go to the new sprites section located underneath the stage on the right hand
side.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 41
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Ensure that the Editor is in Bitmap Mode (bottom left hand side).
Familiarize yourself with all its key features: colour palette box, erasure, brush. etc.
Now draw a skipping stickperson sprite using the colour palette (Fill) box
The sprite can be as simple or as detailed as you wish. So you can add on elements
such as hair, eyes, mouth etc.
Edit this second costume version so that the sprite’s arms, rope and other features
are positioned differently to the first version.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 42
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Once completed use a simple script to give animation to the skipping sprite.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 43
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 9 - Cursor-controlled Sprites
In this lesson students will become familiar with the programming of sprites to
follow the movements of the cursor.
Utilise the Mouse Tracker option located in point towards block______ (Motion) and
write up the following script
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 44
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Exercise:
1. Draw your own sprite bird with two costume changes using a stage contained in
the Outdoors section of the Backdrop library.
2. Create a programme with the sprite controlled by the Mouse-pointer code.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 45
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 10 - The Psychedelic Sprite
This lesson introduces students to the Sensing category that will allow us in this case
to change the Sprite’s physical appearance by movements of the mouse (or keypad).
The block below, as shown in the script above, is located in the Looks category
Go to the Sensing category to find the Mouse X and Mouse Y blocks which you
drop into the set color effect to _____________ as show in the script above.
Start the programme by clicking the Green Flag on the top hand corner of the
screen.
Because of the instructions that you have typed in, which will move the mouse
tracker left and right along the X axis, the sprite will change shape.
If you move the mouse along the Y axis, the sprite will change colour.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 46
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Exercise
Experiment with other effects by clicking the black arrow in the ‘set... effect to’ and
choose other options besides Whirl and Colour.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 47
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 11 - Sprite Interaction
This lesson will build on the familiarity gained in Lesson 9 with the Sensing
commands to show how to code in an automatic interaction between two sprites
using the Touching block of code.
Under the Costumes section of Max, delete all versions of the Sprite except max-b
and max-c.
These two versions should be fine to animate Max as she jumps up and down on
the trampoline.
However you can of course use the Paint Editor to change one or more of the
costumes in order to visually show the arms to be more raised even higher or lower.
This can be achieved using the highlighted tool in the image below.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 48
Code Week and was developed by Brendan Smith for the Camden Education Trust.
We of course want Max to jump up and down off the trampoline.
As Max touches the trampoline her arms will rise upwards. At the same time, the
surface of the trampoline will it seems react to the weight of Max by stretching
downwards until she jumps back up again.
We achieve this effect by the insertion of the touching command from the Sensing
category in the scripts of both Max and the trampoline.
For Max:
For the trampoline, the use of the fisheye effect from the Looks category gives the
impression of a bulge.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 49
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The script is as follows:
Please note that the fisheye effect has to be brought back to zero as otherwise the
trampoline will continue to bulge more and more each time that it is touched by
Max.
Exercise:
1. Make a Playground scene complete with a see-saw and a swing.
2. Draw in two children positioned at each end of the see-saw
3. Give the impression of the see-saw moving.
4. Draw in a child on the swing.
5. Give the impression of the swing moving.
6. Draw a boy or girl skipping. These characters can be simple stick people.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 50
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 12 - Two Sprites having a Chat
In this lesson students will become familiar with the Broadcast command code
which sends a message to some other part(s) of the programme (e.g. another sprite
or a backdrop) instructing it to implement a change.
Select twice the Butterfly 2 sprite from the Scratch library. Choose also an
appropriate backdrop.
Please note that if your sprite is turned the wrong way, click on the costume tab.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 51
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Place the following scripts in the second butterfly sprite
Exercise:
1. Create a programme where two people are chatting after meeting up whilst out
walking.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 52
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 13 - Creating a Coral Reef
Lesson Objectives:
• To understand the significance of the If command (with its cause and effect
impact) that is contained within the Control category
• To use the Random block of code (Operators) to change sprite positioning
• To use Sensing commands to give different effects when sprites come into
contact with each other
• To add in a music score.
Explain that the ‘go to front’ is very useful where there are two sprites positioned on
top of each other and where you want to have one of them appear always at the
front (or back) e.g.
The ‘go back _ layers’ blocks of code are applicable when you have multiple objects
on screen such as in an aquarium, populated with different fish and plants, where
you need to position some objects to the rear whilst others would be to the front
when they cross each other’s paths.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 53
Code Week and was developed by Brendan Smith for the Camden Education Trust.
and click on
Choose the small Fish sprite option from the Animals folder and duplicate it.
Delete all but one costume for each. Please ensure each of the two fish sprites uses
a different costume in order to ensure that each represents a separate species.
Rather than have the sprites change direction (i.e. only turn around) when they
‘bounce’ off the edge, which has been solely used up until now, the latter piece of
code allows the sprites to turn around (e.g. at 180 degree or right-to-left turn)
randomly within a certain range (e.g. 1 to 26).
Use of the
in combination with
located in the Operators folder signifies that this change in direction will occur once
in every twenty. So a lesser number range (e.g. 1 to 6), will lead to the turning around
movement of the sprite occurring more frequently.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 54
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The use of the powerful IF THEN command in the script means that if a certain listing
that is inputted occurs, then the corresponding stated reaction contained within the
code will automatically take place.
Used of Forever with the If then blocks of code ensures that this change in
direction of the sprite will be a
continuous process.
Exercise:
Get students to experiment with changes to the random numbers and with the turn
_ degree block.
Use the same code as with the previous sprite (above).
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 55
Code Week and was developed by Brendan Smith for the Camden Education Trust.
To reposition some of the seaweed plants towards the back, thus giving the effect
of the fish moving in front of and between individual plants, go to Looks and select
the following block:
Each layer represents one specific sprite area of movement. The higher the number,
the more marine sprites will be found swimming in front of the seaweed.
To have the seaweed located at the front of the screen, use the following motion
block:
Select a sprite whose code allows it to actually cross the path of another sprite.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 56
Code Week and was developed by Brendan Smith for the Camden Education Trust.
‘Whirl’, the aforementioned special effect used in the example above, will change
the physical shape of the sprite. The higher the number, the greater the distortion
to the sprite.
But it is important to add on to the block of code, after a wait of one or two seconds,
the additional block set whirl effect to 0 or clear graphics effects., Otherwise, the
sprite will remain permanently distorted.
The ‘whirl’ is one of a number of special effects in this command block located within
Looks as shown below:
Get the students to experiment with these options and in changing the number in
the set whirl effect to __
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 57
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Exercise
Get the students to draw:
a) A woodland or jungle scene populated by many different moving animals
such as birds, mammals, and insects or
b) A street scene populated by walkers, shoppers, cyclists, buskers etc.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 58
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 14 - Target Ball
Lesson Objectives:
• To learn the use of variables
• To use the Random block of code (Operators) to change sprite positioning.
• To show how an action can be programmed to occur when a sprite is clicked.
Make a second costume of the ball sprite that gives the impression that it is
exploding.
Type in Score under variable name and choose For all sprites.
Then place the following block into the Script area setting the Score to zero.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 59
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Now we want the sprite to move across the stage in set pattern. So we use the block
But the two white boxes in allow the user to set a range for X
and Y. So in this case we will have the sprite move across the maximum area of the
stage by using the following block
to ensure that the random movement is on-going use the Forever block.
Now we input a separate piece of code into the script that gives a score every time
that the ball is hit.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 60
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The use of Show and Hide above signifies that the ball disappears every time that it
is hit. Of course this means that the game is very short ending when the sprite is hit
once.
So in order to make the game longer and more fun, copy the sprite five or six times.
Then give each of these ball sprites a different set of X and Y coordinates in order
that they are all in different locations when the game starts.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 61
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 15 - Dancing Sprites
In this lesson, students learn how to create a dance animation through a
combination of commands from the Looks, Control and Sound categories.
First, click on the Stage icon located under the Stage section of the Scratch screen.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 62
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Now let’s animate!
First select
Next select the Wait command which the user should reduce in duration from 1
second (secs) to 0.5 seconds as otherwise the sprite will be dancing too slowly.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 63
Code Week and was developed by Brendan Smith for the Camden Education Trust.
In the sprite’s Script Area, add the following:
Now add the following script to introduce a disco light effect to the stage
Exercise
Get the students to start a new programme with a different backdrop, different
music and three dancing sprites.
Encourage them to draw for instance a few traditional dancers in different poses
and stagger (use Wait block) their appearance onstage. Locate (from the Web etc.)
some appropriate music and make your very own musical!
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 64
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 16 - Drawing Shapes
In this lesson students learn how to understand how to draw geometric shapes
using a series of scripts.
They also learn the concept of Chance using a Random selection block from
Operators.
In order to draw in Scratch, we have bring the cursor to the bottom left corner of
the Interface and select the add extension option represented by the icon
Then click on the Pen section which will automatically add this option to your Block
thematic categories.
It is also important to clear previous drawings from the stage area and to
recommence the drawing process on a blank canvas once the Green Flag is selected
to restart the project.
So use the command
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 65
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Adding on wait 1 second block will allow the viewer to better appreciate visually both
the commencement of the drawing and the actual process of the formation of a
new object.
To ensure that the geometric object that we are about to draw, namely a square, is
of sufficient dimensions for easy viewing, use a sizeable number of steps from
Motion e.g. 100 steps.
To code in the command that will make the four lines form a box, we first use the
Repeat command. In the construction of a square it is Repeat 4 times.
Please note also that for each geometric shape, the angle is proportionate to the
number of sides i.e. 360 degrees divided by the number of sides.
For instance, a square is 360 divided by four = 90;
A triangle is 360 divided by three = 120 and
A circle is 360 degrees divided by 360 = 1
So we have to turn the lines using a degrees block in the Motion category
We can also change the colours for each drawing by picking the random option in
the Operators category. The spectrum of colours go from 1 to 200. Hence choosing
a high random range e.g. 1-200 (see image below) for colour variation will allow the
programme to randomly select from the full range of colours each time that it is run.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 66
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Let’s draw a circle.
How many turns (degrees) in a circle?
So turn one degree at a time. Do not use the block in the script. This
is because using it will mean that it will take 360 seconds for the circle to form.
to give
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 67
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Exercise
1. Draw a Pentagon
2. Write a programme that draws three different shapes that appear at different
times at different locations on the Stage.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 68
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Shapes - others
Experiment with different angles and ‘repeats’ in the programme.
For instance, select the code below and admire the results
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 69
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Input the following code
to give
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 70
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Create A four petal Flower
The effect is achieved by making four half circles (180 degrees) and turning right (90
degrees) at the completion of each one.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 71
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 17 - Bouncing Ball
In this lesson, students become familiar with Degrees and Variables of Space.
Experiment with the speed of the ball by increasing and decreasing the number in
the move _ steps box
We can also control the speed of the ball during a game by using the Variable
category.
Select Make a Variable (for all sprites) and type in the word Speed in the option
Variable Name
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 72
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Right click on the icon (if using the mouse) and select the Slider option, which allows
the user to adjust the speed of the ball when in motion.
Drag the Speed block from the Variable category and position it in the white
(number) box in the move _______ steps block.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 73
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Exercise
1. Write a programme with a number of bouncing balls
2. Write a marine-themed programme that has a number of different bouncing
sea creatures such as jellyfish and sharks.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 74
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 18 - Drawing Free Hand
In this lesson, students learn how to create a programme that will allow a user to
draw free hand.
First, as with the programmes to draw shapes, the user has to make the cat
disappear (hide). This is because it would be very difficult to draw properly with a
sprite such as a cat being used as the drawing tool.
The user then uses the clear block followed by the set pen size block in order to
have a drawing pen of sufficient size.
The user can become the drawing pen by coding in his/her movement of the mouse
interface unit as we did in an earlier lesson when we had the movement of an animal
sprite being controlled by the mouse tracker.
But we need now to ensure that the programme takes account of the fact that the
user’s movement of the motion is not continuous. Otherwise we would have the
screen being filled by one never-ending line.
Hence we have to code in a set of instructions so that the artist can raise his/her pen
at any time to stop drawing and to continue drawing at some other point on the
screen.
This we achieve by coding in a script that is primarily based
around the
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 75
Code Week and was developed by Brendan Smith for the Camden Education Trust.
This will give
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 76
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 19 – Walking the Dog
In this lesson students are introduced to the Timer feature, allowing changes to
backdrops and sprites to occur at certain designated times.
Students will also use the ‘point in direction’ block, which controls the direction that
a sprite faces and moves.
The lesson is based on a girl or a boy taking a dog for a walk-through different
landscapes.
Select from the People section in the sprite library an appropriate sprite with multiple
walking costume changes.
Go to the backdrop (backdrops) library of the Stage option and select three different
scenes from the Outdoors folder.
Under the
command, we add two additional blocks over and above what the
user is familiar with from previous lessons.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 77
Code Week and was developed by Brendan Smith for the Camden Education Trust.
from the Sensing Folder which brings the time back to zero when the Green Flag is
clicked.
block which codes in the direction that the sprite will be facing and walking. This is
important as the storyline will include the girl in this case turning and walking back
whens she gets to the end of his journey.
Thus the initial script would be
We now place underneath the above blocks additional code that will reposition the
sprite back at the extreme left (end of screen) along the X axis when she reaches the
extreme right of the screen. This is because we want the girl to be seen walking
through different backdrops (from scene to scene) as if it is one long continuous
journey.
To do this we use a block of code that allows something to happen when the end
of the screen is reached. This is the
command.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 78
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Go to the Operators folder and select the Greater Than
option block
Type in the digits 226 in the right hand box which represents the pixel number (X
axis) on the far right of the screen.
So place
We use the
block.
Notice that the X coordinate has a high minus number that will, when the
programme is running, give the impression of the girl sprite walking onto the stage
(screen).
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 79
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The code will now appear as
Now we go to the Stage script where we will code in three backdrops that will
change based on a time parameter control.
(Looks)
(Sensing)
and combining
(Operators)
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 80
Code Week and was developed by Brendan Smith for the Camden Education Trust.
to give:
Please note that the numbers inputted are based on the length of time it takes for
the girl to move along the X axis from one end of the screen to the other.
Obviously it is critical that the coder synchronises the timer with the re-positioning
of the sprite back to the left of the screen every time that she reaches the end of the
screen. This will probably involve a bit of ‘trial and error’ on behalf of the student.
So in order to complete this part of the programme, we will input an additional piece
of coding that will limit the amount of time that the girl sprite is walking facing right
so as to allow her to turn around when she gets to the end of the last backdrop and
walk a few steps back (to the left).
First we measure the amount of time it takes the sprite to walk from the beginning
of the first scene to the end of the last scene. In this particular project, it was 34
seconds which is inserted with the Timer into the if _____then block
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 81
Code Week and was developed by Brendan Smith for the Camden Education Trust.
There is now needed an additional block which will reverse the direction of the
walking sprite and end the programme:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 82
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Now we introduce a second sprite, namely a dog that barks.
However we will have the dog appear after the girl calls for her pet to join her on
the walk.
Hence, as the animal only shows a few seconds after the girl has begun her travels
and in answer to the girl’s call for him to join her whilst always walking a few steps
behind his owner, we need to code into the script a command(s) that will hide the
dog before it reaches the end of the screen (please note the backdrops change in
response to the actual times when the girl reaches the end of the screen). The dog
also re-appears in the next screen only after the girl has moved a few steps forward.
Thus we use the Show and Hide option from the Looks folder.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 83
Code Week and was developed by Brendan Smith for the Camden Education Trust.
As was done with the script for the girl sprite, once the end of the last screen is
reached, input code that reverses the direction of the sprite to walk a few steps back.
The coding of the timer parameters for the dog has to be synchronised with that of
the girl script.
Finally, we should also input code to allow a bit of chat going between the girl and
the dog.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 84
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 20 – Planning & Designing A Gamei
Students need to be informed of the importance of first planning out their proposed
game with pencil/pen and paper rather than rushing in to happily write up scripts
They should understand the need to define the purpose of the game, how this is to
be achieved and the role of each of the game elements such as the different sprites
and how they relate (effect) to each other.
The written plan (or Algorithm) is then used to build the game.
However the tutor should first provide an example of different types of games that
could then be used as starting points or templates for the students’ own creations.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 85
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 21 – Game: Shark Attack!
This lesson introduces students to a) programming the arrow keys to control the
movement of sprites (a popular characteristic of many computer games) and the
b) Stop all code.
The lesson also re-introduces a powerful Touching command and the if command
(with its cause and effect impact).
Select from the Animal folder a) Shark sprite with two costume changes (‘open’ &
‘shut’ mouths) and b) a little fish sprite.
Give names to the shark and the little fish. In this example, I have called the former
Kracken and the latter Pandora.
The forever loop block of code and the content contained within will mean that, no
matter where Pandora is located, the shark will always follow.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 86
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The ‘move 2 steps’ should be of sufficient speed for the initial version of this Shark
Attack game as it will allow the small fish the opportunity to escape the clutches of
the Kraken.
In the above piece of code, the touching option is found appropriately in the
SENSING folder.
The additional pieces of code from the Look folder will give the impression of the
Shark eating the little fish by alternating between costumes with the a) closed b)
open mouth options (costumes).
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 87
Code Week and was developed by Brendan Smith for the Camden Education Trust.
To ensure that the fish is always facing in the correct direction when it is being
moved by the left and right arrow keys, the point in direction block from the Motion
category needs to be added into the script as follows:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 88
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Finally, the inclusion of the Show and Hide blocks as well as two Wait options (shown
below) will mean that Pandora disappears after it is ‘eaten’ by the Shark.
As you can see from the code above, the use of Stop All will bring the “Shark Attack!”
game to an end.
There is fossil evidence of sharks going back 400 million years. This is remarkable
especially when one realises that the first dinosaurs only appeared on the planet 243
million years ago.
Today we know of more than 1,000 species of sharks with new species being
discovered every year.
But the very existence of these remarkable fish is threatened due to the activities of
humans. With 70 million killed every year, many species of sharks are now
endangered and could become extinct in the near future.
Saving these creatures is key to restoring the life of the Earth’s oceans.
Exercise
Car Chase
Get students to use the commands and the coding processes taught in the Shark
Attack! Lesson to create a Car Chase project.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 89
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Have the students use a similar script to that below for the Police car:
Get the students to use a similar script for the thief’s car to below:
Note: Programming the Four Arrow Keys to control the direction as well as the
movement of the car
In Shark Attack! specific blocks of codes were used to have the little fish being chased
facing left when moving in a left direction and facing right when moving in a right
direction.
This time we also need to have the car being chased facing up (north) and down
(south) when travelling in those directions.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 90
Code Week and was developed by Brendan Smith for the Camden Education Trust.
See below:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 91
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 22 - Shark Attack Advanced
This lesson increases the complexity of the ‘Shark Attack!’ game by introducing a
competitive element into the project in the form of a timer (Sensing command), the
random selection (the concept of chance), the use of simple variables in the form of
‘lives’ and the creation of different levels.
Note: In Mathematics, a variable is a value that may change within the scope of a
given problem or set of operations. Here in this instance, we use variables to
represent the number of lives of one of the sprites, which changes as a result of
interaction with another sprite.
As with the previous lesson (Shark Attack!), we will use a Shark (Kraken), a small fish
(Pandora) and an ‘Underwater’ backdrop from the Scratch Outdoor folder.
Start
Click on the Backdrop icon, then duplicate the Underwater backdrop once.
Edit this new level (Level 2), by drawing in some additional features such as extra or
larger blades/stems on the seaweed, coral and rocks as well as changing the
backdrop colour to a deeper shade of blue.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 92
Code Week and was developed by Brendan Smith for the Camden Education Trust.
When the editing is completed, duplicate Level 2 twice more.
With the second new level (Level 3), use the edit option to enter the Paint Editor.
Then type in the relevant wording in large bold lettering such as You Lose! By using
the (T)ext icon.
With the third new level (Level 4), type in the text You Win! in large bold lettering
To reposition the text to a suitable location, click on the T(ext) icon. Bring the cursor
onto the little black rectangle that appears at the top left hand corner of the
onscreen text (see below). A ‘hand’ icon then appears allowing the operator to drag
the text to a new location.
Then go to the Operators’ folder and the ‘greater than’ block of code
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 93
Code Week and was developed by Brendan Smith for the Camden Education Trust.
In the first blank white box in the above, place in TIMER from the Sensing folder.
In the second blank white box, input a number that will represent a time duration
measured in seconds:
Within the forever if block above place, from the Events folder, the broadcast option.
To ensure that the Backdrop changes after 15 seconds has elapsed, select new from
the broadcast block of code and type in the text “new level”.
Note: There is an alternative and easier way to change the backdrops, namely the
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 94
Code Week and was developed by Brendan Smith for the Camden Education Trust.
To ensure that that the game ends and all elements stop when the You Win! or You
Lose! screens appear, place the following code in the Pandora (or Kraken) script:
The user also has to ensure that the correct screen appears every time that the game
is played or restarted by inputting the following code into the Backdrop script:
A characteristic of the new level will be the fact that the shark will increase in speed,
this making the game more challenging for Pandora (user).
This feature is achieved by inputting the following code into the Shark’s script:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 95
Code Week and was developed by Brendan Smith for the Camden Education Trust.
You can of course increase the speed even further by changing the digits in the
move__steps block.
The little fish sprite has to stay alive for the specific period of time that the user has
chosen. If he manages to stay alive for this inputted time duration, then he/she is
declared the winner.
This is achieved by inputting the following piece of code into the little fish script that
is based on a 30 second game duration:
The Timer has to be reset to 0 every time that the game restarts.
This is achieved by placing the RESET TIMER option into the little fish code as follows:
Click on the Green Flag to check out that the game is functioning okay.
Notice that a Timer indicator box appears on the top left hand side of screen:
However for the timer to be shown on the stage, the little box to the left of the Timer
code in the Sensing folder must contain a black marking.
If this is not the case, click on this box.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 96
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The Use of Variables
To programme in extra LIVES for the little fish sprite, go to the Variable folder and
select the Make a Variable option.
You will be asked to type in a name.
Type in the number 5 in the Set Lives to block before placing this code into the
script of the little fish as follows:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 97
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The little fish now has five lives.
If he/she loses all of his/her lives before reaching thirty seconds, then the game is
over.
So input the following code:
which is made up of blocks from the Control, Variables and Operators folders.
The little fish loses a life each time that it is touched by the shark.
This result is achieved by inserting within the touching block section of the shark’s
script.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 98
Code Week and was developed by Brendan Smith for the Camden Education Trust.
To give a fighting chance to the little fish in its attempts to escape the clutches of
the shark, we need to add on a piece of code that will allow it to appear in different
locations randomly each time that it is caught (touched) by the shark.
The wider the number range in the random (green) block, the wider the area that
the little fish will reappear (i.e. show) after each time that he is touched by the Shark.
To add even more difficulty to the game, create another sprite that appears when
the second Level is reached. This sprite will be coded so that if he touches the little
fish, it too reduces the amount of Lives by one.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 99
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Return to the little fish (Pandora) script, where we add the following instructions that
will lead to a loss of one life each time it is touched by the crab.
Exercise
Chasing Dinosaurs
Get the participants to create a game of one dinosaur chasing another dinosaur
using Lives and Levels. It will involve one sprite moving from a forest, to a desert to
a water, field or mountain scene. From the second scene, get them to introduce a
second dinosaur (or another exotic creature) who will start chasing the main
protagonist.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 100
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 23 – Tennis Solitaire
This lesson introduces a simple game modelled on one of the great classic computer
games known as Pong. It will introduce students to another Sensing command
based on touching colour. They will also learn how to change the direction of a
Sprite using a combination of Motion and Operator commands.
Go to the new sprite icon and draw a black paddle using the line drawing
tool and a suitable Brush size.
the 0 of .
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 101
Code Week and was developed by Brendan Smith for the Camden Education Trust.
This ensures that the mouse pointer will always only move right or left across the
screen along the X axis.
Go to the sprite column and select a ball sprite from the gallery. Alternatively
you can draw your own ball. If you do decide to do so, do not choose red as a
colour as we will soon be using red as the colour of the goal line.
However it is recommended that students use an existing sprite from the gallery for
this project.
followed by a separate command block that will let the ball bounce in a general
upwards direction with a nice sound effect if it touches the Paddle.
To achieve this, first input the script below:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 102
Code Week and was developed by Brendan Smith for the Camden Education Trust.
However, to ensure that the ball bounces upwards off the paddle rather than
downwards, we need to use a point in direction block where downwards (i.e. 180)
movement
Its’ upwards thrust is helped by increasing the amount of steps that it moves after it
touches the paddle.
appears after the move 12 steps block, then the ball sprite will keep on moving
downwards or sideways rather than upwards.
To ensure that the game correctly ends when the red line is touched, input the
following:
NOTE: For the above code block to work appropriately, the red colour chosen for
the touching colour should have same colour value (colour, saturation and
brightness) as that of the red colour value for the red line.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 104
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 24 – Adventure Games: The Amazing Maze!
Adventure games are based on a main character undertaking a journey across
many different lands where he/she encounters obstacles or dangers that have to be
overcome or circumnavigated in order to reach the final destination and claim a
treasure or reward.
The Maze is a popular variant of this type of game.
This lesson reinforces many of the important commands learnt in the previous few
chapters such as broadcasting and touching colour.
Bitmap images store colour information. It stores the colour of each and every
individual pixel that makes it up.
Bitmap images store the colour information of every individual pixel that makes up
the above image.
Vector images store mathematical formulae that draw lines and curves.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 105
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Creating Levels
First select the Stage icon, click on Edit and colour the backdrop black.
Copy this black backdrop three more times.
The Sprites
First select a main character sprite whose movement will be controlled by the four
arrow keys.
Go to new sprite icon. Draw a coloured ball using the circle drawing tool.
Using the paint brush icon, draw a number of uneven lines emanating from the circle
area.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 106
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Once again, use the to draw another coloured ball (RED) using the circle
drawing tool. Then with the paint brush draw a number of scraggly BLUE lines
emanating from the circle area.
Alternatively select appropriate sprites from the gallery. This might be easier and less
problematic for you as a mentor as it might avoid individual students forgetting the
specific numbers of their colour selection (Colour, Saturation and Brightness), for the
sprites that they created.
This sprite will represent an obstacle for the HERO sprite that if he touches will led
to him losing the game.
Hence to increase its difficulty for Hero, we will have the second sprite constantly
rotating which is achieved by the use of a Turn Degree block in the Motion folder in
combination with a Forever block
Furthermore, this sprite will only appear in the Advanced Level. Hence the use of
HIDE in the opening code
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 107
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Duplicate , this sprite six times.
Of course the position of each of these duplicated sprites has to be different and
should be located to give maximum obstacle impact to the Hero sprite.
So change the entry in each of the individual blocks of code
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 108
Code Week and was developed by Brendan Smith for the Camden Education Trust.
To increase the level of difficulty for the Hero sprite, the Ghost sprite can be
replicated a few times, with the X and Y coordinates for obvious reasons being
different for each version.
The final sprite addition will serve as a PRIZE that if reached by the Hero sprite will
lead to the message You Win! screen appearing and the game ending.
The final positioning of the sprites in the Advanced Level should be similar to:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 109
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The intensity of the difficulty for the Hero in securing the PRIZE can be increased for
instance by adding two blocks of code to the script of the red circle sprite positioned
in front of the PRIZE that will allow it to move in a circular motion.
a set of instructions that if it touches blue spokes of the mines, the message ‘You
Lose’ will appear and the Hero will disappear.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 110
Code Week and was developed by Brendan Smith for the Camden Education Trust.
a set of instructions that if it touches the Ghost sprite , the message ‘You Lose’ will
appear and the Hero will disappear.
a set of instructions that if it touches the yellow box, the game will move onto the
next level.
a set of instructions that if it touches the prize in the second level, the message ‘You
Win’ will appear and the game will end.
Finally, the code for the Stage has to be written to respond (via the inclusion of
When I receive block) to the broadcasts contained in the HERO sprite:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 111
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Exercise:
Say Cheese! Get the students to construct a Maze project whereby a mouse has to
avoid being entrapped by mousetraps and caught by cats in order to reach the
finishing line to claim a lovely big slice of cheese.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 112
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 25 – Demon Chaser
Demon Chaser
Key Command Blocks: ‘Forever if______’, ‘When I Receive’ & ‘Broadcast’ (Control
folder), ‘Say’ (Looks), ‘Touching (a sprite)’ (Sensing), ‘Pick random ___ to ___’ Make a
Variable, ‘Make a List’ (Data), ‘___or ___’ (Operators), ‘Turn ___ degrees’, If on edge,
bounce’ (Motion), ‘Play sound ____’ (Sounds).
Make a List option in the Data folder allows the developer to compile for instance a
list of comments or words that a sprite would say when something specific happens
such as being touched by another sprite during a game.
The game requires two sprites and two versions of a backdrop. The latter would
have one screen displaying the text Game Over.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 113
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Improvements: After completion of the above guidelines, get the students to make
some adjustments that they feel might improve the game
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 114
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Code for Backdrop
Exercise
Get the students to create their own game, based on what they have already learnt
from this and other lessons, for the next class using sprites drawn by themselves.
Encourage each individual or group to explain and demonstrate their own project
creations to the full class.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 115
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 26 - Extending the Demon Chaser Game
First we add a new sprite for the treasure (in this case a bowl of cheese puffs).
Then we add two new variables, one called “Score” and one called “Level”
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 116
Code Week and was developed by Brendan Smith for the Camden Education Trust.
We add the following script to the “treasure” sprite:
This script moves the treasure sprite to a random part of the screen when the game
starts. Each time Gobo touches the treasure, the score is increased by 10 points and
the treasure is moved to a new random position. If the Demon touches the treasure
then the score is reduced by 5 points and the treasure moves to a new random
position.
Now we remove the original “woods1” backdrop that had the “Game Over” message.
We add 2 new backdrops to the stage. When the level changes, we will change the
backdrop.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 117
Code Week and was developed by Brendan Smith for the Camden Education Trust.
We add the following script to the stage to control the levels:
When the green flag is clicked, we set the score to 0, the level to 1 and the backdrop
to “woods” (the first backdrop). We add a forever loop to keep checking the score
and to increase the level if necessary. If we are on level 1 and the score is greater
than 50, then we increase the level by 1 and we switch to the next backdrop. Similarly,
if the level is 2 and the score is greater than 100, we go to level 3 and change to
backdrop 3. If the level is 3 and the score is greater than 150 then the player wins
and we broadcast a “You Win” message.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 118
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Now we add 2 new sprites for indicating whether a player has won or lost the game.
Using sprites for this allows us to simply show a “win” or “lose” message over the
current backdrop:
We add the following script to the “You Win” sprite:
When the game starts, we hide the “You Win” sprite. If we receive the “You Win”
message broadcast by the stage, then we show it.
We add the following script to the “You Lose” sprite:
When the game starts, we hide the “You Lose” sprite. If we receive the “Game Over”
message broadcast by the Good Sprite, then we show it.
We add the following scripts to the “Good Guy”, “Bad Guy” and “treasure” sprites,
to hide them when the game is over:
To make the game a bit more challenging, we can make the Bad Guy actively follow
the Good Guy instead of just moving about randomly. We can also make him move
more quickly as the levels increase. To do this we change the script for the Bad Guy
to the following:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 119
Code Week and was developed by Brendan Smith for the Camden Education Trust.
In this script, we continuously point the Bad Guy towards the Good Guy and move
him a random number of steps towards the Good Guy. The maximum number of
steps the Bad Guy can move is 10 times the current level. This means that he tends
to speed up as the levels get higher, making the game more difficult on each new
level.
Exercise
Get the students to create an Adventure Game based on a legendary mythological
hero from their own county/culture having to fight off demons and monsters in the
mountains, in the seas and in the caves in order to gain a treasure.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 120
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 27 – Shooter Games: Asteroids
Shooter games are based on an environment whereby a main character secures
points for touching another character or set of characters. This genre is often quite
challenging and can test a player's speed and reaction time. Oftentimes, the
player-character, if he/she survives obstacles, doesn’t lose lives and claims a certain
score, can then moves forward onto another level or mission.
Asteroids
In this simplified version of the classic game Asteroids, students will be introduced
for the first time on how to create a sprite that imitates the rapid action motions of
a laser (or bullet).
Spaceship sprite
Draw (or select from the sprite gallery) a spaceship with three costumes, one of
which signifies an explosion.
The first two costumes when coded in will give the impression that the spaceship is
moving rapidly through space due to the small difference in the size and the shape
of the spaceship particularly the width or length of the rocket booster flames.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 121
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Set up Lives using the My Variable option in the Variables folder.
Select a maximum of 5 lives.
Create a Score monitor using the same procedure using zero (0) as the starting
figure.
Control the movement of the spaceship using the Up and Down Arrow keys only.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 122
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Draw an asteroid sprite with two costumes.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 123
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Now we return to the Spaceship script as we have to programme in commands that
will signify the impact of a collusion with an asteroid.
As there are multiple asteroids, it would take a lot of code to recognise each of the
individual sprites. However we collectively identify all the asteroids by using the
identifying colour grey.
So the main coding script for the spaceship should now read as follows:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 124
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Finally, input code that will stop the game once all the
spaceship’s lives are lost:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 125
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The Laser Sprite
However you need to go into the costumes’ Paint Editor of the Rocketship sprite to
get a better alignment between both sprites.
After doing so, move the Rocketship sprite out of the middle of the screen in the
Paint Editor using the Arrow positioning icon located at the Top left hand corner of
the tools menu within Vector mode.
However if the sprite comprises multiple parts that may move independently of each
other using this tool, go to the tool located at the top right of the menu
which allow it to be manipulated as one entity.
You will see a very small target marking. Move the spaceship sprite to the left and
in front of the target.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 126
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Run the full script project and see if it works.
You may though have to experiment a few times with moving the rocketship sprite
in the Paint Editor until you feel the alignment between both sprites is satisfactory.
Now, we build a code that will give the visual impression that, when the spacebar is
touched, a laser is shot from the spaceship in a straight firing line towards the
direction of the asteroid.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 127
Code Week and was developed by Brendan Smith for the Camden Education Trust.
The code below includes commands that registers the laser hits of an asteroid:
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 128
Code Week and was developed by Brendan Smith for the Camden Education Trust.
block, you input the same numbers in the colouring box as you did when colouring
the asteroid. Otherwise no score will be registered when you touch an asteroid.
These numbers are:
Colour: 25; Saturation: 0; Brightness: 65.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 129
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 28 – Two Player Games
Teamwork is a core element in the teaching of Scratch. Hence regular project works
involving two or more students are recommended.
Likewise, participants are encouraged to produce games that involve multiple
players as today’s modern computer gaming tends to be played in an interactive
online social networking environment.
Soccer Striker
Shooting type games are a popular genre.
Key Command Blocks: ‘Ask a Question’ & ‘Answer’ sensing commands, ‘Touching
colour’, the ‘If’ command, Variables & Operators, ‘When I Receive’ & ‘Broadcast’.
Note that the Ask command (Sensing folder) allows the user to input an answer.
The veracity or falseness of the reply and the resulting responses are controlled by
the commands inserted.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 130
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Draw out a suitable section of a soccer pitch.
Introduce sprites that will take on the roles of a striker, a goalkeeper, a football and
an official host.
Note: In the scripts below, all X and Y positions for the striker, a goalkeeper, a football
and the host are all specific to the demonstration project only and will not conform to
any other project. They exist only as guidelines.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 131
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Note: The in the above script refers to the colour of
the goal nets which have to be touched by the ball in order to register a score.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 132
Code Week and was developed by Brendan Smith for the Camden Education Trust.
In the above text, the block appears beside the striker.
However you will probably need to go into the costumes’ Paint Editor of the striker’s
sprite in order to have the ball positioned at the feet of the striker.
After doing so, move the striker’s sprite out of the middle of the screen in the Paint
Editor using the Arrow positioning icon located at the top left-hand corner of the
tools menu within Vector mode. However if the sprite comprises multiple parts that
may move independently of each other using this tool, go to the tool
located at the top right of the menu which allow it to be manipulated as one entity.
Once you move the sprite, you will see a very small target marking. Move the striker
sprite until its feet are behind the ball sprite.
Looking at the stage will help you get the proper alignment.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 133
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 134
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Script: Striker sprite
Exercise
Create a hockey or other sporting game based on the same or similar structure to
the above Soccer Striker game.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 135
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 29 - Two Player Games: Tennis for Two
Even more than the single player version used in an earlier lesson, this two player
Tennis game is closer to the original classic game known as Pong.
Key Command Blocks: ‘forever if’, ‘When I Receive’ & ‘Broadcast’ & Stop All (Control
folder), ‘Touching (a sprite)’ (Sensing), ‘Change by ____’ & ‘Set ___to’ (Variables), Pick
random __ to __ ‘ (Operators), Point in Direction __’, Turn (Motion).
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 136
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Scripts: Ball sprite
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 137
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 138
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Script: Paddle 1 sprite
Script. Stage costumes: a) Standard version with 2 coloured goal lines at opposite
ends of the screen, b) Player 1 Wins! and c) Player 2 Wins!
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 139
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Lesson 30 – Geography Quiz: Travelling across a
Continent
Coding a Quiz using Scratch is a popular activity in schools. The themes range from
general knowledge to a specific subject. In the latter area, it can give an exciting new
dimension to the teaching of languages, sciences, history and geography. The
students can be given the opportunity to research the questions and answers of
their chosen subject as well as to build an exciting question and answer project that
will capture the interest of people participating.
The sample project below is of a tour of Europe. The questions here are based on
naming the countries. But it could be instead based on naming the main languages,
capitals, the head of states, popular tourist destinations, mountains, rivers, lakes etc.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 140
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Key Command Blocks: ‘Forever if’, ‘If ____ Else’, ‘Repeat until___’, ‘When I Receive’ &
‘Broadcast’ & Stop All (Control folder), ‘Say’ (Looks), ‘Touching (a colour)’, ‘Ask’,
‘Answer’ (Sensing), ‘Change by ____’ & ‘Set ___to’ (Variables), ‘___or ___’ (Operators),
Turn (Motion), ‘Play sound ____’ (Sounds).
One Sprite (Daire) and one backdrop (map of Europe) with only a script for the
former.
Scripts:
Part 1
Part 2
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 141
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Part 4 (containing Part 3 above)
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 142
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Part 4 (containing Part 1 and Part 3)
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 143
Code Week and was developed by Brendan Smith for the Camden Education Trust.
Script for the country Britain
Follow the same procedure for all the other marked countries.
Exercise
Get the children in the class or the participants in the session, as individuals or in
groups, to make a similar project based on the continent of Africa.
This will involve a lot of advanced research and planning in order to obtain the
necessary relevant information (e.g. capitals of countries, languages spoken,
geographical features such as main rivers, mountains, etc).
i Note: All Lesson Plans compiled by Brendan Smith, Camden Education Trust, Galway, Ireland.
Africa Code Week is an initiative by SAP. All content here is the intellectual property of Africa 144
Code Week and was developed by Brendan Smith for the Camden Education Trust.