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.
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.
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.
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
How can we help?
If you are looking for a Contract Electronics Manufacturing partner, submit your enquiry today and a member of our team will be in touch shortly.
Are you experiencing an issue with your Sony product? Tell us about it and our team of expert technicians will be in touch.
Are you looking for office space with fantastic amenities and 24/7 security? Enquire today with your requirements and our team will be in touch with information about our availability.
We are a socially aware business which seeks to support our local community You can submit your request today using the form on the right. Please note that we can only support requests within a 30 mile radius from our facility. Our committee reviews requests on a monthly basis, so please allow a few weeks for our team to respond.
To arrange a visit for your school as a part of our educational programs, please submit your inquiry today. Our committed team will respond with guidance regarding availability within a week.
Ready to join the Sony team? Please submit your CV and cover letter today using the form on the right and our recruitment team will be in touch.