AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Build, test and reset

Week 15 · Unit 6: Be an animator · 3 lessons
3

Two sprites, one program

Computing 5: Unit 6, pp. 70–85
GoalPlan a program with two sprites that each have their own scripts and predict what happens when they meet.
New words
interact · to affect each othersprite · an object in a Scratch programpassword · a secret word or phrase that lets you in; it must be kept secretsafe · protected from harm or from other people
Explanation

Most programs have more than one sprite, and each sprite has its own scripts. The scripts can run at the same time. One sprite may move while the other waits and checks. A condition can use the other sprite, such as ‘touching Tortoise’. We plan each sprite with the questions from the last lesson, then predict what happens when they meet. If … then is also used for passwords: if the password is correct, then let the person in. A password must stay secret. Make it long and hard to guess, and tell it only to a parent or carer.

x 240−240y 180−180TortoiseFlag
Worked examples
QuestionTortoiseFlag
Is it static?nono
What actions?moves 20 stepschecks all the time
Inputright arrow key pressedgreen flag clicked
Conditionnonetouching the Tortoise
Conclusionnonesays Winner! and stops all
A program has a Tortoise and a Flag. The player presses the right arrow key to move the Tortoise. The Flag keeps checking, and when the Tortoise touches it, the Flag says ‘Winner!’ and stops the program.
Tortoisewhenclickedgo to x:-100y:0Tortoisewhenright arrowkey pressedmove20stepsFlagwhenclickedsayWinner!for2secondsstopalliftouchingTortoise?thenforever
Here are the scripts. The Tortoise has a start script that puts it at x: -100, and the Flag stands at x: 100. The Tortoise moves 20 steps for each press, so after 10 presses it reaches the Flag and the Flag says ‘Winner!’.
Starttype the passwordpassword correct?yesnounlock the tabletEnd
Selection is also used to protect passwords. The program asks for the password. If it is correct, then it lets the person in. If it is not correct, it does nothing.
Class activity

Sprite theatre (3 players). Two players are sprites and one is the stage manager. The Bus starts at one end of a line of 8 floor squares and the Stop stands on square 6. The stage manager says ‘key’, and the Bus takes one step. The Stop watches the Bus all the time and says ‘Board here!’ the moment the Bus is on its square. After the Bus has arrived, the stage manager says ‘flag’ and both players go back to their starting squares. Try again with the Stop on square 4.

Practice
1
The Bus starts at x: -60 and moves 30 steps for each press. The Stop is at x: 60. On which press does the Stop say ‘Board here!’?
Buswhenspacekey pressedmove30stepsStopwhenclickedsayBoard here!for2secondsiftouchingBus?thenforever
2
A Child moves with the arrow keys. A Puddle says ‘Splash!’ whenever the Child touches it. Complete the plan.
QuestionChildPuddle
Is it static???
Input??
Condition??
Conclusion??
3
Write the algorithm for the Puddle in numbered steps.
4
Which is the safest password rule? (a) use your birthday, (b) make it long and hard to guess, and tell only a parent or carer, (c) use your pet’s name and tell your best friend.