Activity – 2 (Beat the Goalie)

Introduction:

In this activity you will learn how to create a 2 player soccer game in which you have to score as many goals as you can in 30 seconds. 


Materials

Computer or laptop, scratch


Procedure:

  • Make sure you are signed into your scratch account.(see page 2)
  • In your search bar type in http://rpf.io/beat-the-goalie-on
  • At the top of your page press “Remix”.

  • We will now begin to code our soccer game
  • To begin this code you will first start off by dragging this block

into your blank working space. This block can be found under the events command

  • You will then drag this block and attach it to the first block

  • Click the sensing command and drag out this block

Put it in the empty space next to “repeat until”. Under the drop-down menu make sure you choose the one that says “space”.

  • Click the motion command and drag out this block

In the white circle type in “10”. Drag this block in between the “repeat until” block.

  • Drag this block:

and attach it to the previous block. Your code should look like this so far. 

  • As of right now, you should be able to click the green flag to test your activity. Your soccer ball should bounce along the bottom of the screen until the space bar is pressed.
  • Under the motion command, drag out this block

In the first circle type in -200. In the second circle type in -140. You will then drag and place this block underneath the “when… clicked” block. Make sure the block is above the “repeat until …” block.

  • You will then go under the control command and drag out this block.Attach this block to the “repeat until …” block. 
  • You will now go under the motion command and drag out this block

Put this block In between the orange “repeat…” block. Your code should look like this.

  • You will now drag this block

and attach it under the “repeat …” block.

  • You will then go under the sensing command and drag out this block

  You will place this block in between the empty space of “If… then”. In the drop down menu select “Goalie

  • You will then go under the sound command and drag out this block.

Place this block in the space under “if… then”. In the drop-down menu select “rattle”.

  • You will then go under the events command and drag out this block.

Place this block in the space under “else”. In the drop down menu click “new message” and type “Save”.

  • At this point your code should look something like this

  • You can now code your goalie to say “Save” when they receive the message. To do this, you will click on the goalie.

  • You should now have an empty work space. You will go under the events command and drag out this block.

In the drop down menu select “save”.

  • You will then go under the looks command and drag out this block.

In the first white circle type in “Save!” and in the second white circle type in “1”. You will then attach this block to the “When I receive…. block”

  • Test your code by trying to score a goal. If your goalie saves the goal they should say “save!”
  • We are now going to do a code so your goalie says “goal!” when a goal has been scored. To do this we will first start off by switching back to the soccer ball

  • We will be working on this area

  • You will first start off by dragging this block

from underneath “else” to underneath “start sound rattle…”

  • You will now go under the sound command and drag out this block. 

Place this block under “else”. In the drop down menu select “Cheer”

  • You will now go under the events command and drag out this block.

Under the drop-down menu, click “new message” you will then type in “Goal” and click save. Drag this block underneath “start sound… cheer

  • Your code should now look like this

  • You will now be adding a timer , so that the player has to score as many goals as they can in 30 seconds. 
  • You will click the variable command and press “Make a variable”. You will name this variable “Timer” and then press “For this sprite only” then press “ok” to save your variable
  • You will then go under the events command and drag out this block.

You can place this block anywhere on the blank working space because we are starting a new line of code.

  • You will then go under the variable command and drag out this block.

In the white circle you will type in “30”. You will then drag this block underneath the “When… clicked” block that you previously dragged out.

  • Next you will go under the control command and drag out this block. You will then place this block underneath the set Timer to … block.
  • This is what your code should look like

  • You will now go under the operations command and drag out this block.

In the second white circle you will type in “0”. You will then place this block in the empty space next to “repeat until …”

  • You will then go into the variable command and drag out this block.

You will place this block inside the first white empty circle.

  • You will then go under the control command and drag out this block.   Place this block in between the repeat until … block. In the white circle type in “1”
  • You will then go under the variable command and drag out this block. Place this block underneath the previous block. In white circle type in “-1”.
  • You only have the chance to score 1 goal. To have more than one chance, add a forever block around your soccer ball code.

  • Your code should look like this

  • It’s far too easy to score a goal. Let’s make a code so a second player can control the goalie. You will first click on the goalie sprite and add the following code…
  • You will go under the events command and drag out this block.

In the drop-down menu select “left arrow”. You can place this block anywhere because we are starting a new code.

  • You will then go under the motion command and drag out this block.

In the white circle type in “-10”. Place this block underneath the “when left arrow key pressed”. You can now press the left arrow key to test if your goalie moves.

  • We will now make our goalie move right. Go under the events command and drag out this block.

You can place this block anywhere because we are starting a new code.

  • You will then go under the motion command and drag out this block.

Attach it to the previous block you just dragged out. In the white circle type in “10”.

  • Your two codes should look like this

  • Your final code for the soccer ball should look like this

  • Your final code for the goalie should look like this