3. Make the Ball Sprite Bounce
In this video, you’ll make the ball sprite bounce around the screen. There are a lot of blocks in the “motion” menu in Scratch that make the sprite move in different ways.
The simplest way for a sprite to move is in the direction it's already facing.
Click on the ball sprite. From the “motion” menu, drag out the “move” block. Click on it. The sprite moves, but only once. It needs to keep moving.
In activity 2, you used a “repeat” block to make the sprites repeat their change costume action. But, that made the action happen a specific number of times, then stop. In this project, the ball should keep moving. From the “control” menu, place the “forever” block around the “move” block. Click this stack and test it. The ball sprite moves... until it hits an edge. Computer scientists call problems in their code “bugs.” The “if on edge, bounce” block from the motion menu will fix this bug, so the ball can keep moving. If you click on it, it seems to do nothing. But, when you place it inside the forever loop, the ball sprite starts bouncing around the stage. Pretty sweet. Right now, the ball will start moving in a predictable direction, which makes the game easier. To make the ball start moving in a random direction, from the “motion menu” place a “point in direction” block on top of the forever loop. To make it choose a random direction, from the “operators” menu, place a “pick random” block inside the “point in direction” block. Tinker with the numbers in the “pick random” block until you find ones you like. This example uses -45 and 45. Finally, make the ball sprite start moving when the flag is clicked. Place a “when flag clicked" block at the top of the block stack. Click the flag. The ball sprite will start moving.
Here’s the game plan: Make the sprite move with the “move” block.
Make it move forever with the “forever” block and bounce with the “if on edge, bounce” block. make the ball start moving in a random direction using “point in direction” and “pick random” blocks.
And finally, add a “when flag clicked” block to the top.
After the ball sprite is bouncing around the stage, move on to the next video to get the athlete sprite into the action.