0% found this document useful (0 votes)
164 views12 pages

Computing Lesson 1

Unit 1 focuses on designing code with objects, emphasizing the development of algorithms and programs where multiple objects interact. It introduces concepts such as sprite interaction, algorithm creation, and the roles of team members in programming projects. The unit includes practical exercises to reinforce learning through games and sprite programming in Scratch.

Uploaded by

myatkhant431
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
164 views12 pages

Computing Lesson 1

Unit 1 focuses on designing code with objects, emphasizing the development of algorithms and programs where multiple objects interact. It introduces concepts such as sprite interaction, algorithm creation, and the roles of team members in programming projects. The unit includes practical exercises to reinforce learning through games and sprite programming in Scratch.

Uploaded by

myatkhant431
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Unit 1 Be a designer

Designing code with objects


Get started!
Have you ever played a game that needs two people? Work with your partner to make a list of
games that need two or more people to play.
Does playing with another person make the game more fun and exciting?

You will learn to: In this unit, you will develop


• develop algorithms where two algorithms and programs
objects interrelate with two or more objects.
• develop programs where two or more objects
can interact
• outline the skills of the different people
needed to create a program.

9781398368606_HCP_Computing_LB5.indb 8 2/1/23 12:56 PM


Unit 1: Be a designer

Warm up
Work in groups of four. You will play a game that involves four players.
The object of the game is to reach the middle block first. Each player gets into position on one
corner of the board below.
Each player can:
• only move one block at a time
• can block the move of another player by placing an X on one of the blocks.

Which player won?


How many blocks did the player take to win?

Do you remember?
Before you start this unit, check that you:
• can follow, understand, edit and correct an algorithm that uses repetition
• know how to develop programs with repetition
• can test different parts of a program to identify and debug errors.

9781398368606_HCP_Computing_LB5.indb 9 2/1/23 12:56 PM


Unit 1: Be a designer

Algorithms with two objects


Learn
In this section, we will develop an algorithm where one sprite character follows another sprite.
Let’s write the algorithm for the first sprite to move from one end of the screen to the other.
Algorithm Name: Chasing Game Penguin
Step Instruction
❶ When the Green Flag is clicked
❷ Set size to 50%
❸ Glide 2 seconds to random position
➍ Repeat step 3 nine more times
➎ Stop program
To create and run this program in Scratch:
1 Open a new project.
2 Choose any sprite for Sprite 1 and add the following code.
3 Add the set rotation style left-right block from the Motions group.
4 Select the Repeat block from the Control group.
5 Add the Move ( ) steps from the Motions group.
6 Add the if on edge, bounce block from the motions block.
We will now write an algorithm for the second sprite.
Algorithm Name: Chasing Game Polar Bear
Step Instruction
❶ When the Green Flag is clicked
❷ Point towards Penguin
❸ Glide 1 second to Penguin
➍ Repeat steps 2 and 3 nineteen more times
➎ Stop program
The Polar bear will now
follow the Penguin, The point towards and glide towards blocks are
wherever it goes! in the Motions group. Once the Penguin sprite
has been added to the program, it appears as
an option in the drop-down menu in each block.

10

9781398368606_HCP_Computing_LB5.indb 10 2/1/23 12:56 PM


Unit 1: Be a designer

Practise
1 Complete the following algorithm for a third sprite in the chasing game. The Dinosaur
sprite should chase the Polar bear.
Algorithm Name: Chasing Game Dinosaur
Step Instruction
❶ When the __________ is clicked
❷ Set size to 50%
❸ Point towards __________
➍ Glide 0.5 seconds to __________
➎ Repeat steps ____ and ____ thirty nine more times
❻ Stop program
2 Create the code for this algorithm.
3 Run and test your code. Does the Dinosaur chase the Polar bear?

11

9781398368606_HCP_Computing_LB5.indb 11 2/1/23 12:56 PM


Unit 1: Be a designer

Algorithms and code with two objects


Learn
In this section, we will develop algorithms where one sprite talks to another sprite. When two
sprites interact, we must write an algorithm for each sprite.
In the following algorithms, a Fish sprite will ask the Dani sprite’s name three times. Dani will
respond with a new name every time it is asked.
In the Fish Sprite broadcast algorithm, the Fish sends out a message (broadcasts) and waits to
receive a response.
The code for this algorithm is:
Algorithm Name: Fish Sprite broadcast

Step Instruction
❶ When the Green Flag is clicked
❷ Say What’s your name? for 2 seconds
❸ Broadcast message 1 for 2 seconds
➍ Say What’s your name? for 2 seconds
➎ Broadcast message 2 for 2 seconds
❻ Say What’s your name? for 2 seconds
❼ Broadcast message 3 for 2 seconds
❽ Stop program

The Dani sprite performs an action when it receives


a message. In this case, the action for each message is different. This means we will write
different algorithms for each message.
In the algorithm below, the Dani sprite says its name when it receives the first message. The
Dani sprite then waits for a response from the Fish sprite.
The code for this algorithm is:
Algorithm Name: Dani Responds Costume 1
Step Instruction
❶ When I receive broadcast message 1
❷ Say Hello! My name is Dani-a for 2 seconds
❸ Wait 2 seconds
➍ Stop program

12

9781398368606_HCP_Computing_LB5.indb 12 2/1/23 12:56 PM


Unit 1: Be a designer

Did you know?


The broadcast message sends a message to all sprites.
The broadcast message and wait block waits for the sprite to respond to the instructions.
The when I receive message block tells a sprite what to do when they receive the message.

Practise
1 Fill in the algorithm for Dani’s response to the second message. Dani should say that they
are called Dani-b.

Algorithm Name: Dani Responds Costume 2

Step Instruction

❶ When I receive broadcast __________

❷ Say ____________________ for __________ seconds

❸ Wait ____ seconds

➍ Stop program

2 Write the algorithm for the third costume for Dani’s response to the third message.
3 If you haven’t already, create the code for the Fish Sprite broadcast algorithm and the
Dani Responds Costume 1 algorithm.
4 Create the code for the Dani Responds Costume 2 algorithm.
5 Create the code for the Dani Responds Costume 3 algorithm.

The broadcast message


block is in the Events
group. You can select which
message to broadcast, or
create new messages, by
clicking on the drop down.

13

9781398368606_HCP_Computing_LB5.indb 13 2/1/23 12:56 PM


Unit 1: Be a designer

Skills of the program team


Learn
Creating a final program needs a number of key people with different skills. These people work as
part of a team to complete the final program.

The project manager


Anna is the project manager.
She makes sure that everyone on
the team gets their work done.
She assigns tasks, tells each
member of the team what they
have to do and ensures the task
is done on time.
She is skilled in communication,
planning and organising tasks.

The computer engineer


Chrissy is a computer engineer.
She must understand how
hardware works together with
the software.
She is usually part of the team
when software is written for
specific hardware – for instance,
a microwave.

The programmer
Kala is skilled in writing programs
using different programming
languages. She knows how to
program in Scratch!
She writes the software for
games and other programs.

14

9781398368606_HCP_Computing_LB5.indb 14 2/1/23 12:56 PM


Unit 1: Be a designer

The designer
Jarno is responsible for how a program looks and
feels for the user.
If the program is a game, Jarno is the artist who
designs the look of characters, background scenes
and different levels.

The testers
Jim makes sure that the finished program
does not have any bugs. He has to test the
program systematically.
If he finds a bug, it means that the program is not
doing what it was intended to do. Jim records the
error, and sends it back to the programmer and
designer to fix.

Practise
1 Which one of the following statements is true about a project manager?
A They design how characters in a game look.
B They are skilled in writing programs.
C They ensure that the program has no bugs.
D They are skilled in organising tasks.
2 Which of the following is NOT true about a project manager?
A They are skilled in communicating with the members of the team.
B They assign the task to each member of the team.
C They ensure the tasks get done on time.
D They are responsible for the look and feel of the software.
3 State whether the following are true or false:
a Testers are optional when creating a final program.
b Without a programmer, you cannot create the final program.
c A programmer knows only one computer language.
d A computer engineer knows how hardware functions with the software.
4 Work in groups of 3–4.
You have been asked to recruit some students at your school onto your Program Team.
Write a letter describing the different roles on your team and the skills that each role needs.

15

9781398368606_HCP_Computing_LB5.indb 15 2/1/23 12:56 PM


Unit 1: Be a designer

Go further
1 Copy and fill in the blanks using the word bank below.
captain tester project manager programmer computer engineer designer

A ____________ is responsible for how a program looks and feels. The ____________ ensures that
there are no bugs. The ____________ is skilled in writing programs. The ____________ ____________
designs and builds the hardware components that works with the software. The ____________
____________ is skilled in communication and is the team ____________.
2 In Stage 4, you learnt how to add a sub-routine.
You wrote code for the Chasing Game in an earlier Learn panel.
a Write the Scratch code to match the Jump Sub-routine algorithm below. Add the code
to the Penguin. This code will make the sprite jump.

Algorithm Name: Jump Sub-routine


Step Instruction
❶ Define Jump Sub-routine
❷ Change y by 40
❸ Wait 1 second
➍ Change y by –40
b Add a call to Jump sub-routine in the Chasing Game Penguin algorithm. The sub-routine
should be called after the Penguin glides.
c Add the code for the sub-routine call to the Chasing Game Penguin code.
3 a Complete a second algorithm for the Penguin sprite to:
• send message1 “You can’t catch me!”
• send message2 “Who is behind you?”
Algorithm Name: Jump Sub-routine
Step Instruction
❶ When the Green Flag is clicked
❷ Say _______________ for 2 seconds
❸ Broadcast _______________ for 2 seconds
➍ Say _______________ for 2 seconds
➎ Broadcast _______________ for 2 seconds
❻ Stop program

16

9781398368606_HCP_Computing_LB5.indb 16 2/1/23 12:56 PM


Unit 1: Be a designer

Challenge yourself!
You will create a new chasing game.
This game will contain three sprites: the Fish, the Octopus and the Shark.
The Fish should:
• Glide for 3 seconds towards the mouse pointer when the Green Flag is clicked
• Change to a random costume at the end of each glide
• This should repeat 8 times.
The Octopus should:
• Say “Are you coming?” for 1 second when the Green Flag is clicked
• Glide for 1 second towards the Fish
• Point towards the Fish at the end of the glide
• Broadcast a message at the end of each glide
• This should repeat 12 times.
The Shark should:
• Glide for 1 second towards the Octopus when it receives a message
• Say “I heard you!”
• Change costume at the end of the glide.
1 Write the algorithms for each sprite.
2 Write the code for each sprite.
3 Run and test your programs. Do the sprites behave as described?

17

9781398368606_HCP_Computing_LB5.indb 17 2/1/23 12:56 PM


Unit 1: Be a designer

My project
1 a Conduct research to determine if there are any other people that can be added to a
programming team.
b What skills should they have?
c Create a flyer to advertise the job position. Include the skills that this person must have
on your flyer.
2 In the first Learn panel and Practise panel, we created an algorithm for up to three sprites
to talk to each other. Create an algorithm where four sprites talk to each other. Convert the
algorithm to code.
3 In this project, we will create a new Chasing Game. However, we will make it more complex
by having the sprites record their position by drawing a circle.
a Add the Pen extension blocks to the palette.
b In the algorithm below, Sprite 1 moves randomly six times. Write the code to match this
algorithm. (Hint: see Learn panel – Algorithm with two objects.) You can use any sprite.
Algorithm Name: Chasing Game Sprite 1 – Random position
Step Instruction
❶ When the Green Flag is clicked
❷ Set position to: x =125, y = 70
❸ Say “You can’t catch me!” for 1 second
➍ Glide 2 seconds to random position
➎ Call Circle Sub-routine
❻ Repeat steps 3 to 6 five more times
❼ Stop program
c Below is the algorithm for the sub-routine to draw a circle. Write the code to match the
Circle Sub-routine algorithm.
Algorithm Name: Circle Sub-routine
Step Instruction
❶ Define Circle sub-routine
❷ Set pen colour to 50
❸ Pen down
➍ Move 10 steps
➎ Turn right 36 degrees
❻ Repeat steps three and four 10 times
❼ Pen up

18

9781398368606_HCP_Computing_LB5.indb 18 2/1/23 12:56 PM


Unit 1: Be a designer

d Add two additional Sprites into your Chasing Game project. You can choose any sprites.
The code for Sprite 2 and Sprite 3 is exactly the same as Sprite 1 except that:
• Sprite 2 should follow Sprite 1
• Sprite 3 should follow Sprite 2
• Different pen colours should be chosen.
Remember: A pen colour of 50 is blue. Different numbers are used for different colours.
e Test your code and debug any errors.

What can you do?


Well done! You can
Read and review what you can do. now program sprites to
✔ I can develop algorithms where two objects interact. interact with each other!
✔ I can develop programs where more than two
objects interrelate.
✔ I can state the skills of different persons required to create a program.

19

9781398368606_HCP_Computing_LB5.indb 19 2/1/23 12:56 PM

You might also like