Create a penalty shootout game, can you score on the keeper?
Go to the Scratch website and create a new Scratch project. You can delete the cat sprite.
Go to the Scratch website using the link below and click on the 'Create' link in the blue bar at the top.
By default, each new project starts with the cat sprite already added. To delete the cat click on the x in the blue circle beside the cat in the sprite list.
Included with this step is a picture of a soccer goal, download this picture onto your computer and then upload it as a new backdrop in your project.
You can upload images as backdrops into your project. To upload a backdrop follow these steps:
The new backdrop will upload into your project and appear in the stage area.
Add the Soccer Ball sprite from the sprite library and give it the following code to set it up for the start of the game.
when green flag clicked
set size to (100) %
go to x (0) y (-130) // the bottom middle of the stage area
To add a sprite from the sprite library follow these steps:
You can use search box or the filter links (Animals, People, Fantasy etc) to locate your sprite.
To take a penalty shot you will click with your mouse the spot in the goal where you want to ball to go. This means that you will be clicking the backdrop so add the following code to the backdrop to broadcast a message.
when stage clicked
broadcast [shoot v]
Messages are a great way to start a piece of code at a particular time. To create a new message follow these steps:
Now let's make the ball move to the spot that you clicked.
When the ball receives the 'shoot' message. we will make the ball move towards where your mouse pointer is and also shrink the ball so that it looks like it's moving away from you.
Add the following code to the Soccer Ball sprite.
when I receive [shoot v]
point towards [mouse-pointer v]
repeat (30)
change size by (-2)
move (8) steps
end
Now let's add a goalkeeper! Add the Casey sprite from the sprite library and give it the following code to set it up for the start of the game.
when green flag clicked
set size to (70) %
switch costume to [casey-a v]
go to x (0) y (30) // in the middle of the goal
point in direction (90)
set rotation style [left-right v] // this keeps the sprite the right way up
To add a sprite from the sprite library follow these steps:
You can use search box or the filter links (Animals, People, Fantasy etc) to locate your sprite.
When the choose a spot and send the 'shoot' message we will make the goalkeeper dive to a random spot and try and save your shot.
Add the following code to the Casey sprite.
when I receive [shoot v]
switch costume to [casey-d v]
point in direction (pick random (-180) to (180))
move (100) steps
At the moment the keeper doesn't stop the ball when he makes a save so let's add the code to detect that.
Add the following code to the Soccer Ball sprite, underneath the move 8 steps block.
when I receive [shoot v]
point towards [mouse-pointer v]
repeat (30)
change size by (-2)
move (8) steps // add new code under here
if < touching [Casey v] ? > then
say [It's saved!!!] for (2) seconds
stop [this script v] // this stops the ball from moving
end
end
Now let's doing something similar for detecting if the ball hits the post.
Add the following code to the Soccer Ball sprite, underneath the if then block.
when I receive [shoot v]
point towards [mouse-pointer v]
repeat (30)
change size by (-2)
move (8) steps
if < touching [Casey v] ? > then
say [It's saved!!!] for (2) seconds
stop [this script v]
end
if < touching color [#ffffff] ? > then // get the colour of the post
say [It hits the post!!!] for (2) seconds
stop [this script v] // this stops the ball from moving
end
end
Some of the sensing blocks allow you to set a colour to decide what they should do.
< touching color [#3e7144] ?>
< color [#ff6666] is touching [#4d86c1] ?>
You can choose which colour to use by clicking on the colour in the block and either using 'Color', 'Saturation' and 'Brightness' sliders to set the color.
Or you can use the eye dropper tool to choose a colour.
Finally we just need to add the code for scoring a goal. We do this by adding a say Hello! for 2 secs block after the repeat block, because the code will reach here if the keeper didn't save it and it didn't hit the post so therefore it must be a goal!
Add the following new code to the Soccer Ball sprite, underneath the repeat block.
when I receive [shoot v]
point towards [mouse-pointer v]
repeat (30)
change size by (-2)
move (8) steps
if < touching [Casey v] ? > then
say [It's saved!!!] for (2) seconds
stop [this script v]
end
if < touching color [#ffffff] ? > then
say [It hits the post!!!] for (2) seconds
stop [this script v]
end
end
say [Goooaaallll !!!] for (2) seconds // add this block