03 May 2022

Beat the Goalie (Blog by Steve Lewis)

Beat the Goalie is a great Scratch project that introduces students to sensing and broadcast blocks and shows how ‘if else’ statements are used to make decisions when a condition is met or not. It is a two-player game and provides scope for tinkering and adaptation. As with many projects on the Raspberry Pi website, Beat the Goalie provides a link to a starter project with the required sprites and background, allowing students to focus on developing their code.

The Starter Project

When I started this project with classes, many children reported their ball was bouncing around the stage rather than across the bottom. This was because their ball had touched the bottom edge and bounced upwards. The block ‘if on edge, bounce’ doesn’t differentiate between the side edges and the bottom edge.

(script to move the ball)

Misbehaving Soccer Ball

Unfortunately, when the ball is returned to its starting position it continues to bounce around the screen. We discovered that a way to rectify this was to add a new soccer ball sprite and copy the code across before deleting the original. This seemed to fix the problem and was a good introduction to copying code to new sprites.

Copying Scripts

To prevent this from happening in the future, I emphasised that sprites only move with code, and we added the ‘go to x: -200 y: -140’ block at the beginning of the project rather than as a debugging challenge later on. Once the ball moves towards the goal, we have a decision to make. Was it a goal or a save? Here, the ‘if else’ block makes the decision for us. We complete the first part together, choosing a sound and adding a broadcast block with the ‘save’ message. I then challenged the children to complete the script using the completed part of the ‘if else’ statement to help.

(incomplete script)

The next part of the project teaches the children how to create a timer using a variable. This is invaluable as a timer is integral to many different types of games and can be adapted and reused. Next, we need to add a ‘score’ variable. Depending on the ability of the class and the time available, I either challenge the children to complete this themselves or we talk through it together. This challenge tests the children’s understanding of their scripts. Can they identify the part that indicates when a goal has been scored and use it to control the variable? It only needs four blocks but involves a good deal of detective work.

(completed scripts to record a score)

At the end of the project, there is an opportunity for the children to change how the ball moves. Moving it left and right in response to key presses rather than simply bouncing.

We usually complete this activity with time for tinkering. Here, I show the children how they can add different sound effects or music. How to change sprite and add their existing code to new sprites. We also look at how the code can be used to create different games such as a food catching game, or a festive Christmas-themed game. These scripts can be adapted and reused in many different ways, forming the basis of a wide variety of games.

(present catch game)

(donut catch game – munching face courtesy of Theo)

Next month, we’ll look at the Boat Race project and how it can be used to create a variety of obstacle course-style games.

 

by Steve Lewis

@Steve_Lewis81

Sign up to our mailing list

Want to hear the latest news from Sony UK TEC? Keep up to date with our monthly newsletter.

SonyUKTEC
SonyUKTEC

@jrsisson1978 @SonyUK @sonyproeurope @SonyPro_AP Hi Jonathan, we're sorry to hear about the trouble experienced. Co… https://t.co/ex7pPNF5E4

SonyUKTEC

RT Calling all content creators📣 The Sony Vlog Challenge is back and we are excited to see what YOU create for a chanc… https://t.co/eGCuDJjG4b