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 are going to be learning how to modify a game.

Let's get started.

Welcome to today's lesson from the unit Using Repetition and Programming to Create a Game.

This lesson is called Modifying a Game, and by the end of today's lesson, you'll be able to modify an infinite loop in a given programme.

We'll be using these keywords throughout today's lesson.

Let's take a look at them.

The first word is decompose.

Decompose.

This means to break down a task into smaller, more achievable steps.

The next word is modify.

Modify.

This means to make changes to something.

And the last word is predict.

Predict.

This means to say what you think will happen before it happens, based on what you already know or can see.

This lesson is split into two sections.

In the first section, we'll analyse an existing game, and in the second section we'll modify a game code.

Let's get started with the first section.

Analyse an existing game.

In coding, what is a loop? Pause the video and have a quick think.

Do you know what that word means? Aisha says, "A loop is a chunk of code that repeatedly runs a section of the programme." Jun says, "A loop is a structure that makes code repeats." A account-controlled loop repeats a section of a programme a fixed number of times.

In Scratch, this is the a count-controlled loop.

Can you see it, here in yellow, it says repeat and there's a white circle.

In the white circle you can add a value, or a number.

This determines how many times a count-controlled loop repeats.

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.

Can you see it here, in the yellow, it says forever and this will run indefinitely until the programme is stopped.

Watch the video with two animated letters.

Which actions are being repeated? What is the difference between the two sprites? I'll play the video now.

Which actions are being repeated? Next costume and change colour.

Wait.

Move 10 steps.

If on edge, bounce.

What is the difference between the two sprites? Let's look at the H sprite.

The H sprite repeats 10 times.

Let's look at the I sprite.

The I sprite repeats forever in an infinite loop.

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

And this lesson you'll use infinite loops.

Other question here for you, true or false? An infinite loop stops after 10 repeats.

Pause the video and have a quick think, is that true or false? Well done for having a try.

The answer is false.

And why is that? An infinite loop repeats forever, until the programme is stopped.

To decompose means breaking a big problem into smaller parts.

Decomposition can help you to understand and work with complex problems, fix, change, and improve a project by looking at smaller parts, see what's happening in each part of a programme.

Open the Catch the Shark project on oak.

link/shark.

Look at this game closely.

Click on the sprites.

What features have been included? Think about backgrounds, sprites, and other game features.

Pause the video so you can open the link and answer the question.

What features are included in the game? Aisha says, "There are three shark sprites and an underwater background." Lucas says, "When you click on a shark, there's a sound effect and then the sprite disappears." Alex says, "I noticed the shark's sprites were hiding and then showing in random positions." Why does the shark sprite keep moving? Pause the video and have a quick think.

An infinite forever loop is being used to keep moving, showing and hiding the shark.

Well done for having a go.

The show and hide blocks are used to make a sprite visible or invisible.

These blocks are useful for animating your sprite.

This is how the shark sprites are made to appear and disappear.

This is what those blocks look like here in Scratch.

We have the purple hide and purple show block.

When you look closely at a project, you are decomposing it to find out which sprite moves, see what each sprite does, hide, show, move, bounce, match each part of the game to the code.

I have a task here for you.

You're doing really well.

I'd like you to analyse an existing game.

Play the Catch the Shark game on oak.

link/shark.

Decompose a game by spotting what each part does and how it was programmed.

Describe the background and sprites used.

What starts the game? What sounds play and when? How do the sprites move? What happens when you click on a sprite? Explain what kind of repetition is used, or loops.

So have a think.

Is it a count-controlled loop or an infinite loop? Pause the video so you can finish the task.

Let's take a look at the answers.

The design, the background is under the sea scene.

sprite is a shark.

Event to start again is a green flag.

Sounds are bite sounds.

sprite movement, shark appears in random positions.

When caught, shark disappears.

When caught, bite sound plays.

Type of repetition used is a forever infinite loop.

Well done.

You've done fantastically in the first section, analyse an existing game.

Let's move on to the second section, modify game code.

This is the programme for the black shark.

Aisha is changing the speed of the game.

She noticed that the shark is too fast and wants to slow it down.

She modifies the wait time at A from 1.

5 to three.

Modify is when you make changes to something.

Can you see here the blocks in Scratch? We've got when green flag clicked, then we have the forever loop.

We hide, wait one second, go to random position, show, wait 1.

5 seconds.

Aisha would like to change this 1.

5 seconds to three seconds.

Aisha predicts what will happen.

Aisha says, "I predict that the shark will stay in one place longer and the game will be easier." Aisha now tests her programme to see if her prediction was correct.

Aisha says, "A longer wait slows the game down.

Changing wait times helps to control the game's difficulty." If the shark's moving around very quickly and only waiting for a short amount of time, it might be harder for a player to click on it.

However, if the shark is waiting longer in one place, it'd be easier for the player to click on it.

What would happen if A was 0.

1 seconds? Can you see here the code in Scratch? We've got when green flag is clicked, forever loop, hide, wait one second, go to random position, show, and wait 1.

5 seconds.

If we change that wait 1.

5 seconds to wait 0.

1 seconds, what would happen to the game? Is it A, the game would be harder, the sprite would not appear? Is it B, the game would be easier, the sprite would appear slower? Or is it C, the game would be harder, the sprite would appear faster? Pause the video and have a think.

What would happen to the game? The answer is C, the game would be harder, the sprite would appear faster.

0.

1 seconds is a shorter time than 1.

5 seconds.

What will happen if you replace the forever loop of a count-controlled loop? Lucas makes a prediction, "I predict that the count-controlled loop will cause the shark to stop appearing before the game is completely finished." Let's have a look at the code.

We've got when green flag clicked, forever loop, hide, wait one second, go to random position, show, and wait 1.

5 seconds.

If that forever loop was now a count-controlled loop, what would happen? Well, depending on the length of the game, the shark would eventually stop moving.

You could have a count-controlled loop with a very high value.

However, sometimes we have to think what is the most efficient code.

It might be more efficient to have a forever loop than a count-controlled loop with a really high value.

However, it does depend on how long the game is being played and what you need.

Lucas test his prediction and modifies the code.

The black shark stops appearing before the game is finished.

If we look at the code in Scratch, it says, when green flag clicked and we've changed the forever loop to repeat your value of five, hide, wait one second, go to random position, show, and wait 1.

5 seconds.

Hide, wait one second, go to random position, show, wait 1.

5 seconds repeats five times.

Lucas says, "A forever loop is more effective in this game than a count-controlled loop because I want the shark to keep appearing while the game is running.

True or false? Using a repeat 1,000 block is just as good as using a forever block to make a character keep doing something in a game.

Pause the video and have a quick think, is that true or false? Well done.

That's false.

Why is that? Even though a repeat 1,000 runs many times, a forever loop runs without an endpoint.

This is better for actions that need to continue the entire game.

It's more efficient to use a forever loop.

The Catch a Shark game is not finished.

There are still some features that were in the design but have not been coded.

We use the design to modify and finish the game.

Well done, super listening.

Open the modifying a game project design.

Lucas says, "There are four sprites in the project design, but only free in a game." Alex says, "You'll have to add a sea creature sprite to this game and programme it." Use the details in the fourth column to add your sprite.

To add a sea creature sprite, number one, hover over the cat button.

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

Number three, select animals to narrow down the search.

To find the sounds that come with this sprite, click on the sounds tab.

Can we see it there? It says sounds and it looks like a speaker.

Check the name of the sound to use in your code.

This sound is called ocean wave.

Click on the purple circle to look for more sounds.

You can duplicate the code from a shark sprite onto your new sprite.

This will save time.

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

We can then change the copied code, like adjusting the movement and wait times, to animate your sprite.

I have a task here for you.

I'd like you to give it a go.

Use the modifying a game project design to finish the game.

Create a new creature sprite.

Duplicate the code sequence from the shark by dragging it over to the new sprite.

Choose an appropriate sound from the design.

Change the wait times so that all of your sprites appear at different times.

Pause the video to try to task.

I'd like to give you some feedback.

Open the Catch a Shark example project on oak.

link/shark-example.

Here you can see all of the code for the sharks and also a new sea creature.

Wow, fantastic.

You did so well modifying a game.

Let's summarise.

Decomposition is used to break a programme into parts to help you identify which actions and sprites are controlled by loops.

You can predict how changes to wait times or loop types will affect a programme.

By modifying features, the gameplay can be changed.

The game was modified by adjusting loop values and reusing code of a new sprite to extend the game.