# Scratch Olympic Floor Exercise With PocketLab

198

2

This is a guide for putting together a Scratch game with a combo system that uses the PocketLab sensor as a controller. My game is based on the Olympic Floor Exercise competition, but this type of game can work with any kind of theming such as skateboarding, surfing, dancing, or skydiving.

Learn how to get Scratch connected to PocketLab here:http://support.thepocketlab.com/topic/scratch-getting-started-guide/.

What you will need:

• PocketLab sensor
• PocketLab ScratchX Chrome extension
• Windows 10 device

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Define Your Basic Moves

First, you will need to figure what kind of basic moves you want your character in the game to be able to perform. For my game, I used left turn, right turn, left roll, right roll, and jump. These are the moves that, when performed in sequence, will activate the combos that score the player points. You will want these moves to be simple and easy to implement.

## Step 2: Implement Your Basic Moves

Now you will need to write the scripts that animate the player sprite according to what you want to your basic scripts to do. For my jump move, I simply moved the sprite up a certain number of pixels, then moved it back down. For the rolls, I just rotated the sprite while changing the x position. The turns were accomplished by changing the sprites costume so that it looked as if it were shrinking then expanding to face the opposite direction.

## Step 3: Implement PocketLab Controls

My game makes use of two of the PocketLab's sensors: the accelerometer and the gyroscope. For the jump and roll inputs, I check to see which axis the Earth's gravity is accelerating the PocketLab along in order to determine its position. If the PocketLab is tilted right, it sends a right roll input. If it is tilted left, it sends a left roll input. If it is tilted forwards, then it sends a jump input. For turns, the game checks to see if the PocketLab is being rotated around the y-axis above a certain speed.

## Step 4: Implementing the Input Scripts

The input scripts are what are tie together the PocketLab controls and the basic moves in the game. When the input broadcast is received from the controls scripts, it should fire the broadcast that performs the appropriate basic move and then check to see if any combos have been performed. Having variables that describe the state of the player sprite, such as if it is rolling or jumping in the air, would be very convenient for detecting combos here. For example, a right roll input while the player is in the air would result in either a front flip or a back flip, depending on which direction the sprite is facing. When combo broadcast are fired, make sure you have a script that catches them and display a message of some kind or adds to the player's score.

Once you have the core of the combo system implemented, you can flesh out the game more by adding things like a timer, obstacles, etc.

If you'd like to look at the code of my game in full, you can click here: https://www.dropbox.com/s/imurzay9ch616xs/OlympicFloorExercise.sbx?dl=0