Skip to content

Please update your browser

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

arrow_back Over the Plate


In this add-on, you will program the baseball so it looks like it’s getting bigger as it comes at you and getting farther away after it's hit.

First, program the baseball to look like it’s coming towards you. Objects look bigger as they get closer. To make the baseball grow, go to the “looks” menu, and place a “change size by” block inside the “repeat until” loop. Be careful where you put it – it has to be inside the “repeat until” loop but outside the “if” block. The ball should get bigger little by little, so put a small number in the “change size by” block.

Click on the flag to test it. The baseball looks like it’s moving toward you! But, when you hit it with the bat, it still grows. That doesn’t look quite right!

The baseball should only repeat growing until it touches the bottom of the stage OR the bat. Remove the "touching edge" condition, but keep it in the scripts area. From the operators menu, drag out an "OR" block and place it inside the "repeat until" loop. On one side, place the "touching edge" condition. Then, right click the "touching color" block, and select "duplicate" to copy it. Place the copy on the other side of the "or" block.

Reset the baseball’s size at the beginning of each pitch using the "set size to" block from the "looks" menu. Again, make sure you put this block in the right place. Place it right at the top of the outermost “repeat” loop. This block sets the size to a specific percentage. Enter a small number in this block to start, so the baseball has room to grow.

This example uses 10.

The sprite will only grow *until* it hits the edge OR the red bat. Test the code by clicking the flag. Wait! The baseball does nothing once it's hit. That's because the sprite stops moving once it hits the bat. To fix this, remove the "if/else" statement from inside the "repeat until" loop. Place it *under* the “repeat until” loop instead.

Now, the ball will move and grow until it hits the red bat or the edge. If the repeat loop stops because the ball touches the red bat, the number of hits will increase, and the ball will change direction to go back up.

Next, make the baseball move away after it is hit. From the "control" menu, drag out a new "repeat until" loop, and place it after the "wait" block inside the "if" block. From the "sensing" menu, place a "touching" condition in the new repeat until loop. From the dropdown, choose "edge." Place a "move 10 steps" block inside the “repeat until” loop. Click the flag to run the code. When the baseball is hit, it moves up until it hits the edge of the screen.

Finally, make the baseball look smaller as it moves away from you. From the looks menu, place a "change size by" block inside the new "repeat until" loop. To make the baseball appear larger, you changed the size by a positive number. To make it appear smaller, change the size by a negative number. Test this code by clicking the flag. Now, the baseball looks like it's coming towards the batter, and when the batter hits it, it looks like the baseball moves farther away. Here's the game plan: To make the baseball look like it's getting closer, add a "change size by" block after the "move” block. Remove the "touching edge" block from the first "repeat until" loop, and replace it with an "or" block, a "touching edge," and a "touching color" block. Move the "if” statement under the "repeat until" loop. Resize the baseball using a "set size to" block. Make the ball look like it’s moving away after being hit using "repeat until," "touching edge," "move," and "change size by" blocks.

Choose an Add-On
Program a celebration for when the batter achieves a perfect batting average.
Over the Plate
Make the baseball look more realistic as it approaches or moves away from the plate.
High Score
Tell the batter if it has beaten the best batting average so far.
Out of this Ballpark
Program the sound of a cheering crowd.
In the Big Leagues
Make the pitcher tell a story before the game starts.
Going through the Motions
Animate the pitcher so it looks like he or she is moving.
arrow_backward Back
Next arrow_forward
  1. Choose an add-on and click "Watch" to learn how to customize your project.
  2. When you finish, come back to the add-ons screen, and try another add-on!