Now that the baseball moves towards the batter, it’s time to program the ball to sense andreact when the batter hits it. When the batter clicks the mouse, the batturns red. You'll program the ball to detect that it hits a swinging bat *if* it touchesthe *red* bat. From the "control" menu, drag out an “if/then”block. From the "sensing" menu, drag out a “touchingcolor” block, and place it in the “if” portion of the “if/then” block.
Set the "touching color" block to red. First, change the bat costume to the red bat. Then,select the baseball sprite again, click the color square, and click the red bat to changethe condition to “red.” Finally, click the bat sprite again, and the code will automaticallychange the costume back.
Alright, back to programming the ball. Place the “if/then” statement inside the“repeat until” loop, under the “move 10 steps” block.
Finally, tell the ball what to do if it is touching the red bat. When a baseball hitsa bat, it goes in the opposite direction. The repeat loop makes the ball keep movingin the same direction until it hits the edge of the screen.
To make the baseball move away from home plate, change its direction. Place a “point indirection” block inside the “if/then” block. Then click the dropdown, and select“up” or 0. Click the flag to test the game. Try missingthe baseball on purpose. The baseball goes past the bat and to the edge of the screenbefore returning to the pitcher’s mitt. Next, hit the baseball. If the batter swingsthe bat at the right time, the baseball moves away from home plate. Nice work!
Here's the game plan: Program the ball to sense if it is touchingthe bat after the batter swings using “if/then,” “touching color,” and “point in direction”blocks. In the next video, you'll use a *variable*to keep track of the number of pitches the batter hits.