Lesson video

In progress...

Loading...

Hello, my name is Ms. Powell, and welcome to Computing.

I'm so pleased that you decided to join me here today.

In today's lesson, we'll be creating our own game using repetition.

Let's get started.

Hello, and welcome to today's lesson from the unit "Using repetition in programming to design a game." This lesson is called "Create a Game." And by the end of today's lesson, you'll be able to create 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 algorithm.

Algorithm.

This is a sequence of steps that can be followed to do a task.

The next word is debug.

Debug.

This is the process of finding and correcting errors in code.

Lesson outline.

Creating games.

This lesson split into two sections.

In the first section, we'll look at coding a game, and in the second section, we'll look at debugging and evaluating a game.

Let's get started with the first section, coding a game.

What is a sprite? Pause the video and have a quick think.

Lucas says, "A sprite is a graphic object that can be controlled by a programme." In Scratch, what kind of actions can a programme make a sprite carry out? Pause the video and have a think.

Jun says, "There are so many commands.

Your programme can make a sprite to move, rotate, hide, or show." Alex says, "Your code can make it wait, play a sound or change its appearance." All of a sprite's actions are controlled by code.

Here I have some code.

I've got the purple show block.

Wait one second.

Go to random position, hide and wait one second.

I can include that within a loop.

This is a forever loop.

Loops are used to repeat sections of code, so those blocks show, wait one second, go to random position, hide, wait one second, are now repeating continuously.

This is called repetition.

True or false? A loop helps you repeat code about writing it over and over.

Pause the video and have a quick think.

Is that true or false? The answer's true.

This can make your programming shorter and more efficient, and this might make it easier to debug if any problems arise.

Code a game.

In this lesson, you'll create a game in Scratch.

Your game will have three or more sprite.

Loops will be used to control the sprites.

When all the sprites are caught, the game will end.

We will use an algorithm to help you.

Use your game design sheet to create your programme.

Aisha says, "My game will have three sprites." Lucas says, "I'll use infinite loops in my code." And Jun says, "I will use the owl sound effect." If you do not already have a design, you can use the one that's included with this lesson.

Let's take a little look at my design.

I've got three sprites: sprite 1: bat 1; sprite 2: bat 2; and sprite 3, bat 3.

How will the Sprite move? Each sprite will move randomly.

Will there be any sounds? Each sprite will have an owl sound when clicked.

Type of repetition used.

Each sprite will have an infinite loop.

Write the algorithm for the sprite.

So for bat 1, repeatedly make it invisible.

Move somewhere random on the screen and wait for one second.

Make it visible and wait for one second.

For bat 2, make it invisible.

Move somewhere randomly on the screen and wait for one second.

Make it visible and wait for two seconds.

And for bat 3, repeatedly make it invisible.

Move somewhere random on the screen and wait for one second.

Make it visible and wait for three seconds.

You can see that bat 1 and bat 2 and bat 3 all have different values for the final wait.

Bat 1 waits one second, bat 2 waits two seconds, and bat 3 waits three seconds.

This means that bat 1 will appear and disappear faster than bat 2 and bat 3.

It will make it harder to catch.

Bat 3 will appear and disappears much slower, which will make it easier to catch as it will be visible on the screen for longer for the player to click on it.

Which backdrop will you use? Spooky forest.

And how will the game end? When all the bats have been caught.

This design is an algorithm that you can follow to create your game project.

If you look at the algorithm I've got here, repeatedly make it invisible, move somewhere random on the screen and wait for one second, make it visible and wait for one second.

I can use that to find the correct blocks in Scratch.

I've got my forever loop.

Within that, I have hide.

Go to random position.

Wait one second, show and wait one second.

This is my algorithm and I've chosen the matching blocks in Scratch.

I can also use this code.

When this sprite clicked, start sound owl and hide.

This matches my design plan.

Open the Scratch website on oak.

link/scratch.

The first step is to create a new project.

Use the create button to open a new Scratch project.

Add your sprites.

To open a Scratch sprite library, number one, hover over the cat button.

Number two, select the cat button to open the library.

Add your backdrop.

To open the Scratch backdrop library, number one, hover over the backdrop button.

Number two, select the backdrop button to open the library.

Use your game design to turn your algorithm into code.

Start your sections of code with event blocks.

Here are some examples of some event blocks.

When green flag is clicked, when space key pressed, when this sprite clicked.

Your game should start with the green flag.

Count-controlled and infinite loops are useful for different types of coding sequences.

You want your sprites to repeat their commands endlessly until the programme is stopped, so you'll use the infinite loop.

You might also use the count-controlled loop.

Here are the two loops in Scratch.

We've got the infinite loop, it says forever, and you can put your blocks that you want repeating inside.

And we've got the count-controlled loop.

It says repeat, and it has a space for your value.

You can put your blocks inside of this loop.

What should go inside your loop for a sprite? Is it A, sprites? B, stages? C, commands? Or D, events? Pause the video and have a quick think.

Super thinking.

It's C, commands.

Begin by writing code for one sprite, then duplicating the code onto the other sprites.

To duplicate your code onto a new sprite, drag the code sequence down on top of the new sprite in the menu.

You could then change the code like adjusting the movement and wait times to animate your sprite.

Aisha says, "Does it matter which order the blocks go inside a forever loop? I've included all the correct blocks." Jun says, "The order of the blocks inside a loop can matter.

If the code runs in a different sequence, it might affect your game." I've got a task here for you.

Create your code from your algorithm using your design plan to help you.

Remember your project should have multiple sprites, have a backdrop, use loops to control repetition, and end when all of the sprites have been clicked on.

Pause the video to try the task.

Super work.

You've done really well in the first section code again.

Let's move on to the second section, debug and evaluate a game.

Did your game run successfully? Alex says, "My sprites all appear and disappear at the same time.

That isn't what I had planned." Aisha said, "You need to debug your programme." A bug is an error or mistake in your code that stops it from working properly or as expected.

I wonder what is wrong with Alex's programme.

It looks as if the sprites all appear and disappear at the same times, and this wasn't what he had planned in his algorithm.

I'm wondering if you can work out what could be the matter.

If they're all appearing and disappearing at the same time, something might be wrong with Alex's wait times.

He might have to check each sprite individually.

Perhaps when he duplicated the code, he forgot to change the wait times.

The process of finding and correcting bugs in code is called debugging.

Every programmer will need to debug their code.

It's a normal part of programming, even though it can feel really frustrating.

Alex looks carefully at his algorithm and code and discovers the bug.

"I need to update the wait value on my sprite, so they appear at different times." While you are coding, you should test your game carefully and debug any problems that you find.

So Alex needs to update the wait values on his sprite.

So if the value of the wait is shorter, then the sprite will move faster.

For example, if the value is one second, then the sprite will wait for one second.

It will appear and disappear faster, and that will make that sprite harder to catch.

However, if the value is higher such as three seconds, then that sprite will be waiting for longer.

The sprite will appear and disappear on the screen much slower.

That will give the player a greater chance of catching it and will make the game easier.

So if you want to make your game harder, you might have a short wait time.

And if you'd like to make your game easier, you might have a longer wait time.

Fill in the blanks.

Before your game is finished, you should always blank it to check it.

If something goes wrong in your code, you need to blank it to fix a problem.

After building your game, you can blank it to see what went well and what could be better.

Look at the words in the boxes: evaluate, test, and debug.

See if you can use them to fill in the blanks.

Well done for having a go.

Let's look at the answers.

Before your game is finished, you should always test it to check it works.

If something goes wrong in your code, you need to debug it to fix the problem.

After building your game, you can evaluate it to see what went well and what could be better.

How to test and debug your project.

Click the green flag in test all sprites.

Do they all move, hide, show and respond when clicked? Check if the loops are correct and not missing any blocks.

Debug any problems and look at your algorithm for clues.

You might also ask a friend to come and have a look at your programme.

Sometimes it's really useful if somebody else takes a look at your code and you might be able to help them debug theirs.

You test your game, but the sprite doesn't hide after showing.

What should you do? A, delete the whole project and start again.

B, check if the show block is missing or in the wrong place.

C, check if the hide block is missing or in the wrong place.

Pause the video and choose A, B, or C.

Well done.

The answer is C.

You should check if the hide block is missing or in the wrong place.

If your sprite doesn't hide after showing gives us a little clue that perhaps it's the hide block which we have an issue with.

The final step of this project is to evaluate what you've made.

This means checking your algorithm.

Have you included everything that you meant to? If something is missing, go back and add it.

Make sure your project is complete before sharing with others.

I have a task here for you.

I'd like you to debug and evaluate a game.

Test your game to check if it follows your algorithm.

If something doesn't work, debug the code by finding and fixing the problem.

When your game is working, evaluate it using the form in additional materials.

Tick the boxes that match what your game does.

Answer the questions to reflect on how well your game works and how you could improve it.

You can work with a partner or evaluate on your own.

Pause the video to finish the task.

I'd like to give you some feedback.

Open Task B - evaluate a game.

Aisha says, "All of your sprites used repetition in their code, I can see infinite loops." Lucas says, "Your game, Alex, had sprites that matched the background you chose." Alex says, "Next time, I want to get my chicken sprites to hide and show faster." Fantastic.

You've done so well today creating a game.

Let's summarise.

A Scratch game can use repetition.

You can follow an algorithm to add code to sprites using loops to repeat actions.

You can test coding projects and use debugging techniques to fix any problems in the code.

An evaluation is useful to reflect on how well the game worked and what could be improved.

Well, that was super listening and well done for finishing this unit.