Scratch and Snap! enable students to create physical devices with the Hummingbird that interact with programs that also display information on the computer screen. Students can be challenged to create their own video game, complete with controller! One example is shown here, but students will come up with many other creative ideas.
In this game, two Hummingbird sensors are used to control the movement of a cat sprite on the screen. The user moves the cat to try to catch a mouse that appears at random screen locations. Hummingbird Pong, which is included in the Birdbrain Scratch .zip file, is another example of a game in which a Hummingbird sensor is used to control a sprite on the screen.
This game uses a controller that consists of two Hummingbird rotary knobs. One knob controls the vertical movement of the cat sprite, and one controls the horizontal movement.
Math operators can be used to transform the output of a Hummingbird sensor into x- and y-coordinates on the Scratch screen. In the expressions below, the value of the rotary knob on port 1 (0 to 100) determines the x-coordinate of the sprite (-240 to 240). The value of the rotary knob on port 2 (0 to 100) determines the y-coordinate of the sprite (-180 to 180). These expressions are placed within a go to block in Scratch.
At the start of the game, the mouse appears in a random position. The play must use the rotary knobs to move the cat to touch the mouse. When this happens, the player scores a point, and the mouse moves randomly to a new position. If the user scores 20 points within 30 s, he or she wins the game.
This project could be extended to add more features to the controller! For example, LEDs on the controller could flash when the user scores a point. A student could also incorporate another sprite as the “villain.” Collisions with the villain could cause the player to lose points. Vibration motors could even be added to the controller to provide force feedback when a player gains or loses points.