Loading...
Hello, my name's Ms. Powell and welcome to Computing.
I'm so pleased that you decided to join me here today.
In today's lesson, we're going to be learning how to design a game using repetition.
Let's get started.
Hello and welcome to today's lesson from the unit Using Repetition in Programming to Create a Game.
This lesson is called Designing a Game, and by the end of today's lesson, you'll be able to design a project that includes repetition.
We'll be using these keywords throughout today's lesson.
Let's take a look at them.
The first word is repetition.
Repetition.
This means a part of a programme where one or more commands are run multiple times in the loop.
Algorithm.
Algorithm.
This is a precise sequence of steps that can be followed to do a task.
Today's lesson is split into two sections.
In the first section, we'll look at investigating repetition, and in the second section, we'll look at designing an algorithm for a game.
Let's get started with the first section, investigate repetition.
In programming, what is repetition? Pause the video and have a quick think.
Repetition is a part of a programme where one or more commands are run multiple times in the loop.
Why are loops useful? Lucas says, "Loops help you make your programmes more fun and more efficient." Jun says, "You can use a loop to make a character keep moving or to show and hide a sprite over and over again." Well done.
Fantastic listening.
A count-controlled loop repeats a section of a programme a fixed number of times.
In Scratch, this is the count-controlled loop.
Here you can see the count-controlled loop.
It's a yellow block, and it says "repeat" in it.
It has a white circle and that's where you can type a value.
If you wanted this to repeat three times, you'd type three into the white circle.
All of the other blocks that are contained within the count-controlled loop will be repeated.
An infinite loop repeats without stopping.
In Scratch, this is the forever loop.
It is useful for repeating a sequence of actions without ending until the programme is stopped.
Here, you can see the yellow infinite loop in Scratch.
It says "forever." You may put blocks within the forever loop, and those will be the actions that are repeating.
An infinite loop might be helpful to get a sprite to move back and forwards across the screen during the programme, whereas a count-controlled loop might be helpful if you would like a sprite to repeat only a certain number of actions and then stop and move on to something else.
Open the Bat Catching project on oak.
link/bat.
Open the Bat Catching Project and play the game.
Watch what the bats do.
Can you spot any repetition? Look closely at how the bats appear, move, and disappear.
Pause the video so you can play the game.
(bats singing) The bats hide, show, move to random positions, and wait.
This is repeated infinitely.
Do you think all the bat sprites have the same code? Why or why not? Pause the video and have a quick think.
Use the purple See Inside button to look at the code for this project.
This is a code for the sprite named Bat2.
If we read the code, we can see when green flag is clicked, this triggers the programme to start.
We have the forever block, and within the forever block, we have hide, go to random position, wait one second, show, wait two seconds, and that repeats again and again until the programme ends.
This is an infinite loop.
It repeats a section of code without ever ending.
This forever loop makes the bat appear and disappear over and over while the game runs.
All the bats' codes use a forever loop, but the wait time in this block is different.
Bat2 had two seconds here as the value, and Bat3 has three seconds.
Why? Pause the video and have a quick think.
How has changing the value in the wait block affected how the sprites move? Super thinking.
As the value is different for each sprite, this means that the bats don't all appear at the same time.
Aisha says, "It makes the game more fun." If we were to imagine that the wait value were the same for all of the bats, they would appear and disappear at the same time.
It might look a little bit like they're flashing.
It wouldn't make it so fun to catch them.
Which sprite will appear and disappear the fastest? Pause the video and look at the codes here in Scratch.
See if you can work out which one will appear and disappear the fastest.
Do you think it'll be A, B, or C? If you read through those blocks, you can have a little look to see what's the same and what's different.
I can see at the bottom, we have a different value for the wait times.
In A, we have wait two seconds, in B, we have, wait one second, and in C, we have wait three seconds, which one will appear and disappear the fastest? Well done, super thinking.
It's B.
B will appear and disappear the fastest.
That's because it has a wait of one second.
That is a smaller value than two seconds and three seconds, so the bats will be appearing and disappearing faster than the other bats.
in the Bat Catching game, why do different sprites have different wait times? Is it A, to save memory, B, to stop repetition, or C, so they don't all appear together, or D, so the forever loop can work.
Pause the video and have a quick think.
Is it A, B, C, or D? Well done for having a try.
The answer is C, so they don't all appear together.
I have a task here for you I'd like you to have a go.
Investigate repetition.
Decide if the sequence should use a count-controlled or infinite loop.
Explain your decision.
The sequence is watering three plants.
Do you think that would be best suited to a count-controlled loop or an infinite loop, and put an explanation why.
Clean the floor until turned off.
Do you think that should be a count-controlled loop or an infinite loop? Playing background music, count-controlled loop or infinite loop? Clapping five times, count-controlled loop or infinite loop? Put a tick in the box to see if you can work out which loop best suits the sequences and explain why.
Pause the video to finish the task.
I'd like to give you some feedback.
Let's take a look at the first sequence, watering three plants.
I think that would be best suited to a count-controlled loop.
Why is that? It should stop after three plants.
Cleaning the floor until turned off, I think that would be suited to an infinite loop.
Why is that? It keeps going until someone stops it.
Playing background music, I think that would be suited to an infinite loop.
Why is that? It doesn't stop after a few songs.
Clapping five times, I think that would be suited to a count-controlled loop.
And why's that? You only need to clap a set number of times and then stop.
Well done.
Fantastic.
You've done so well in the first section, investigating repetition.
Let's move on to the second section, design an algorithm for a game.
What is an algorithm? Alex says, "An algorithm is a precise sequence of steps that can be followed to do a task." You can think of an algorithm as a sequence of commands.
For example, if you were to brush your teeth, there'd be a set order of steps you would take to complete the job.
The first thing you'd most likely do is take your toothbrush.
The next thing you do is probably put some toothpaste on it.
Thirdly, you probably brush your teeth.
Fourth, you might gargle some water.
And fifth, you put your toothbrush away.
The sequence of steps I've just described is an algorithm, and we use algorithms in computing.
In this part of the lesson, you'll design a Scratch game, similar to the Bat Catching game.
Your sprite should disappear and play a sound when clicked on, and then reappear.
First, choose a theme.
Lucas says, "I want my game to be underwater." Aisha says, "I'm thinking of using outer space as my theme," and Jun says, "I'd like my game to be set in a garden." Once you have a theme, choose what kind of sprites you want.
You can look through the Scratch sprite library to get some ideas.
To open the Scratch sprite library, number one, hover over the cat button.
Number two, select the cat button to open the library.
Look through the available backdrops to get ideas.
To open the Scratch backdrop library, number one, hover over the backdrop button.
Number two, select the backdrop button to open the library.
Each sprite in your game needs to do something interesting, and they need to use repetition.
For example, your sprite might hide and show, move to a random position, play a sound, change appearance, disappear when clicked.
Alex says, "All of these actions will go inside a loop, so they will repeat." Jun says, "Will all of your sprites have the same algorithm or will they be different?" True or false: you only need one loop for the whole game? Pause the video and have a quick think.
Is that true or false? The answer is false.
Why is that? Each sprite needs its own loop so it can repeat its actions independently.
Well done for having a try.
Design an algorithm for a game.
An event is the trigger that tells a programme to start doing something.
In Scratch, we use event blocks to begin a set of instructions.
You should decide what event is going to start your game.
It could be when green flag is clicked or it could be when space key is pressed.
Every game needs an ending.
In your game, the player is trying to catch the sprites.
What will happen when they're all caught? Some ideas are the sprite stop appearing after they've all been clicked, a message appears that says you win, the background changes to a winning screen, a sound plays to celebrate, or something else.
Some of these terms might help you write your algorithms. In this box, we have rotate a certain amount of degrees clockwise, rotate a certain amount of degrees anti-clockwise, go to a random place on the screen, start playing the sound, and you can name the sound here in your algorithm.
When you start the programme, make it invisible, make it visible, and wait for a certain amount of seconds, do this a certain amount of times, and repeatedly.
All of these terms might be really useful if you're writing out your algorithm on paper and in sentences.
Fill in the blanks.
In Scratch, a trigger such as "When green flag clicked" is called an something block.
When all of the sprites have been caught, your game will something.
Pause video and have a look at the two words, event and end.
See if you can put them into the blanks.
Let's look at the answers.
In Scratch, a trigger such as "When green flag clicked," is called an event block.
When all of the sprites have been caught, your game will end.
I have a task here for you.
I'd like you to complete the game design sheet.
For each sprite, write down how the sprite will move, if there are any sounds, what type of repetition will be used.
Write the algorithm for the sprite.
Record which backdrops you will use and how the game will end.
Pause the video to finish the task.
I'd like to give you some feedback.
This is an example of the game design sheet.
Sprite name is sprite 1: bat 1.
How will does sprite move? Randomly.
Will there be any sounds? Owl sound when clicked.
Type of repetition used.
I've chosen an infinite loop.
Write the algorithm for the sprite.
Repeatedly make it invisible, move somewhere random on the screen, and wait for one second.
Make it visible and wait for one second.
Here is my next one, sprite 2: bat 2.
How will the sprite move? Randomly.
Would there be any sounds? Our sound when clicked.
Type of repetition used.
Infinite loop.
Write the algorithm for the sprite.
Repeatedly make it invisible, move somewhere random on the screen, and wait for one second.
Make it visible and wait for two seconds.
Which backdrop will you use? Spooky forest.
So you can see this one has a longer wait time than bat 1, so it'll be visible for longer.
This bat will be easier to catch than the other bat.
sprite name, bat 3.
How will the sprite move? Randomly.
Will there be any sounds? Owl sound when clicked.
Type of repetition used.
Infinite, forever loop.
Write the algorithm for the sprite.
Repeatedly make it invisible, move somewhere random on the screen, and wait for one second.
Make it visible and wait for three seconds.
How will the game end? When all the bats have been caught.
You can see here, bat 3 has the longest wait time or three seconds.
This one will be the easiest bat to catch.
Fantastic.
That's super listening.
Let's summarise designing a game.
Game design can use repetition to control how sprites behave.
Loops are used in different ways in coding projects.
An algorithm can be used to plan the actions of each sprite.
A design template can help you choose a theme, decide what each sprite would do, and which repeated actions to include inside the loops.