arrow_back Passing Back
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 a 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 three hundred sixty degrees in a circle, so a half-circle is half of three hundred sixty, or one hundred eighty degrees.
Enter one hundred eighty 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 a 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." 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 next 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 kicked the ball back. Just select that sprite in the dropdown on the second "switch costume" block. 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.