The Week Junior - Science + Nature

Beat the goalie

Code a football game to play with your friends.

-

How does it work?

This project uses a free online coding language called Scratch. By creating programmes using Scratch, you can improve your problem-solving skills. This activity teaches you how to build a two-player game and move your sprite from left to right.

Kick the football

1

On your computer, go to: rpf.io/beat-the-goalie-on to open the project in Scratch.

2

Select the football sprite and build the script pictured to the right. A script is a stack of coding blocks that makes a set of instructio­ns. Drag the colourcode­d blocks from the list on the left-hand side of your screen. Snap them together in the coding area in the middle.

3

To find the “set score” block, you will need to create a variable. Find Variables in the list and click “make a variable”. Label it “score”, and select “for all sprites”.

4

You will need to use the drop-down menu on the “key” and “touching” blocks. Select “space”, “a”, “d” and “Goalie” on the appropriat­e blocks.

5

When selecting the “broadcast” blocks, you will need to write your own message by selecting “New message”. Enter “save” for the first block and “goal” for the other.

6

Now, test your game by clicking the green flag. The ball should move from left to right when you hit “a” and “d” keys on a keyboard. Pressing the spacebar allows you to kick the ball towards the goal.

Move the goalie

1

Now it’s time to add some code so you can move your goalie to stop the ball.

2

First, select the goalie sprite. Then, build the script below.

3

Use the drop-down menus to select the correct variables for each block, and type in the words and numbers in the other boxes.

4

Make sure you check each line carefully.

5

Test your game by clicking the green flag. Your goalie should move when you press the arrow keys.

Set a timer

1

Finally, you can add a timer to the game by clicking on the stage sprite. This is the “Backdrops 1” icon on the far right of the screen.

2

Build the code below and fill in the correct numbers. You will also need to create a new variable. Name it “timer” and make sure to select “for all sprites”.

3

Check each line carefully before testing your game.

4

Get a friend to play striker, moving the ball with the “a” and “d” letters. You can control the goalie with the arrow keys. Pressing the spacebar shoots the ball. Will you save the shot, or will your opponent score a goal? Keep playing until the timer runs out, then swap over – the most goals wins!

 ?? ??
 ?? ?? Football sprite
Football sprite
 ?? ??
 ?? ??
 ?? ??
 ?? ?? What you will need:
 A computer  Scratch
What you will need:  A computer  Scratch
 ?? ??
 ?? ?? Goalie sprite
Goalie sprite
 ?? ?? Stage sprite
Stage sprite
 ?? ??

Newspapers in English

Newspapers from United Kingdom