Like we did with the light sensor exercise, we're going to open a sprite that already has scripts associated with it. In this case, we'll use the gravity marbles.
As long as the slider's value is greater than 20, the marble rises. We can still use the right and left arrow keys to move the marbles across the stage.
This was another example where we substituted a keyboard input with a sensor value from the PicoBoard. This time we used a sprite that was configured to demonstrate gravity. As the slider measured a value of 20, the marble rose. When we reduced the slider value to less than 20, the marble dropped.
If we examine the gravity marble scripts, we learn that the marble will always fall unless it's acted on by some other force. In this case, the force that moves the marble up is the slider. Let the slider value fall below 20, and the marble falls -0.05 pixels at a time.
Stand up from your chair and jump up as high as you can. Grab a pencil and toss it to the ceiling. You know this story. Gravity grounds everything in real life.
When we design games with jumping sprites or falling objects, we can make the game more realistic by adding gravity. And it doesn't matter if we use a PicoBoard, an arrow key, or some other input.
18.227.111.197