Introduction: Trampoline With PocketLab & ScratchX
Did you know that trampoline is an Olympic sport? In honor of this incredible event, I made a Scratch trampoline game that incorporates PocketLab data.
You will need:
- Magnet (I used one from the PocketLab Maker Kit, but any will do)
- Windows 10 device with Chrome (needed to run the ScratchX extension)
- PocketLab app from the Windows store
- PocketLab & ScratchX extensions for Chrome (click here for setup instructions)
- Knowledge of Scratch interface & blocks
Step 1: Game Overview & Variables
Here is a quick overview of the game you will be coding:
The objective of the game is to earn at least 10 points in 30 seconds by bouncing on the trampoline and doing flips and twists in midair. Start with the white side of the PocketLab (the side labeled with the xyz axes) facing you. To bounce the cat, you must move the PocketLab towards the magnet. The magnetic field will act as the trampoline--once the field reaches a certain value, the cat will bounce upward. Once the cat starts jumping, move the PocketLab away from the magnet and start spinning the PocketLab. Spin the PocketLab with your hands (or by throwing it up into the air) to make the cat flip and twist. You can flip by spinning the PocketLab on the Z axis, and twist by spinning the PocketLab on the Y axis. Make sure the cat lands on his feet--if he lands on his head, it will be game over!
There are four variables you should make for this game:
Timer: counts down from 30 seconds.
Score: adds points every time the cat does a flip or twist.
In Air: determines whether or not the cat is in the air (so that flips and twists are disabled while the cat is on the trampoline--if they weren't, accidental movement of the PocketLab could make you lose the game)
Spinning: determines whether or not the cat is spinning (helps separate the different moves)
Step 2: Game Setup, Backdrops, and Sprites
The cat, trampoline, and Greek theater background can be found in the default Scratch library. I also made a very simple game over backdrop that says "Press space to restart". When space is pressed, a message will be broadcast to start the game, which sets the cat and trampoline into their default positions.
Step 3: Bouncing
The cat will bounce upward when the magnetic field scalar is over a threshold value (so when you're moving the PocketLab towards the magnet, it's like bouncing off of a trampoline!). The value that I picked was based on my magnet from the PocketLab Maker Kit--feel free to adjust it if it's not to your liking or if you are using a different magnet.
When the threshold value is detected, the cat will jump. In my code, the jumping is simply the cat gliding from one y position to a higher y position.
Step 4: Flips, Twists, and Ending the Game
The cat is supposed to rotate 180 degrees for the flip, but I broke it up into 10 repeats of 18 degrees to make the movement smoother.
The game ends when the timer hits 30 seconds. The cat will say different things depending on whether the score is higher or lower than 10. The game can also end if the cat lands on his head, which the game will recognize if the cat is back at his starting position, at y = -68, and looking to the left or up.
Step 5: This Is What Your Final Code Should Look Like!
Step 6: Ideas for Improvements
Want to make the game even better? Here are some ideas!
- Make the game harder/easier by adjusting how much time you have and/or the score required to win
- Add flip and twist combos that are worth more points
- Draw medals or a sad face (depending on the score) for the game over backdrop
Participated in the
Maker Olympics Contest 2016