Exploring the PicoBoard sensors
Keep Moving
After the sprite moves, the script uses four more if ()
blocks to check the position of the sprite on the stage. To understand these four conditionals, you need to remember that the Scratch stage has the following boundaries: the left edge is x=-240, right edge is x=240, bottom edge is y=-180, and top edge is y=180.
The position checks in the four if () blocks are straightforward. As soon as the sprite passes the boundary coordinate, it will be repositioned to the same place on the opposite side of the stage using the set x to ()
or set y to ()
blocks. Here's an example: If the sprite moves off the stage at the (x,y) coordinates of (240,10), the script will reposition the sprite to (-240,10), and it will continue to move.
In many Scratch projects, you'll see the if on edge, bounce
block used to send the sprite back into the center of the stage. The script in Figure 4 provides an alternative way to handle the sprite on the edge of the stage and can be used in projects everywhere.
The overall movement shown in Figure 4 can be added to a variety of games, allowing the player to do things such as navigate a maze, dodge balls, or shoot other sprites.
But Wait, There's More
The PicoBoard includes additional sensors for sound and a push button, but I'll save those for a future project. If you're looking for some quick ideas to introduce those sensors, however, I like to use the sound sensor to "sync" my voice to a script's action on the stage, and the push button could be used to set up a hearing test. Happy Scratchin'.
Infos
- "Scratch Programming: Measuring and Graphing" by Michael Badger, Raspberry Pi Geek, issue 4, 2014, pg.88, http://www.raspberry-pi-geek.com/Archive/2014/04/Measuring-and-graphing-resistance-with-a-PicoBoard-and-a-thermistor/(language)/eng-US
- PicoBoard: https://www.sparkfun.com/products/11888
- Let's Play Music: http://www.letsplaykidsmusic.com/happy-birthday-easy-piano-music/
« Previous 1 2 Next »
Buy this article as PDF
Pages: 4
(incl. VAT)