Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

Transcript

This add-on will show you how to get the receivers to pass the ball back to the starting point.

You can see in the example that whenever the sprite receives the ball, it immediately passes it back.

First, build the code to make the ball turn around.

Click the ball sprite to program it.

From motion, grab a turn right block and snap it below the repeat until loop inside the conditional that checks if the Space key is pressed.

This turn right block should turn the sprite all the way around to reverse its direction.

There are 360 degrees in a circle so half a circle is half of 360 or 180 degrees.

Enter 180 into the turn right block.

Now the ball sprite will go back to the starting point.

Drag out a second repeat until loop and snap it below the turn right block.

Inside the loop, drag another move block to make the sprite keep moving back in its original direction after it turns around.

Find the condition that makes the loop stop running at the right moment.

When the sprite touches an edge, you know it's back at its starting point.

Go to sensing, drag a touching block into the blank and select edge.

It's testing time.

Click the flag, then send the ball flying toward a receiver.

When it touches the receiver, it should bounce back.

Cool, test again by aiming for the edge.

The ball should bounce and come back, but it just jumps back to the start.

This is because your new loop stops before it can start moving the sprite.

It's still on an edge when the loop checks so it exits immediately.

Fix this by placing an extra move block right after the turn block.

That'll get the sprite away from the edge.

Great, test again.

If the go to block is still in the right place, then the ball sprite will reset after coming back to the start.

Finally, change the receiving costume back to the kicking one for each receiver sprite.

This makes them look like they kick the ball back.

Just select the sprite in the dropdown on the second switch costume block.

All right, here's the game plan.

Use a turn right and a second repeat until block to make the ball sprite bounce back.

Switch the receiver costume to the kicking costume when it touches the ball sprite.

Choose an Add-On
Never Ending Game
Make the receivers disappear and regenerate each time you pass to them.
Passing Back
The ball will always bounce back to the starting position.
Power/Receiver Speed
Add realistic variables with sliders that control the speed of the ball and the receiver sprites.
Keep Score
Count how many passes you complete.
arrow_backward Back
Next arrow_forward
Instructions
  1. Watch the introductory video.
  2. Scroll down to see the add-on choices.
  3. Select an add-on and start creating!
  4. Choose another add-on, and continue building.