MicroBit-Quick-Start-Teacher-Guide
MicroBit-Quick-Start-Teacher-Guide
MicroBit-Quick-Start-Teacher-Guide
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Quick</strong> <strong>Start</strong> <strong>Guide</strong> for <strong>Teacher</strong>sChallenge 3: Catch the egg gameProgramming a game of ‘catch the egg’ using the accelerometer in TouchDevelopPREVIEWOutcomeA ‘catch the egg’ game in which an egg (representedby a single LED) ‘falls’ from the top of the BBC micro:bitdisplay and can be caught in a moveable basket at thebottom of the display. The script includes code for theaccelerometer, which allows a user to control theposition of the basket when the device is tilted:- By default, the first ‘egg’ LED starts to drop fromthe centre of the top line of the display- The subsequent ‘eggs’ will then fall from randompositions at the top of the display.- The ‘basket’ will be moved by tilting theBBC micro:bit.Decomposing the problemThis challenge can be decomposed into six parts:1. Create the global variables for the game.2. Assign initial values to each of the global variables.3. Plot the starting positions of the LEDs.4. Create a forever loop to update the display regularly.5. Get the ‘egg’ to drop down the LED display.6. Change the position of the basket using theaccelerometer functionality.7. Use IF conditions to check the final position of the egg.TutorialsFor a video tutorial go to live.microbit.co.uk/start-guide/video-tutorials/catch-the-eggFor a guided coding tutorial go to live.microbit.co.uk/td/tutorials/catch-the-eggCreate the global variables for the gameGlobal variables are different to local variables (which only work inside a single loop).Global variables are accessible from any part of our program.01<strong>Start</strong> by opening a new browser window and typinglive.microbit.co.uk in the address bar. Click onCreate Code. In TouchDevelop, click New project.Type in a name for your script, such as Catchthe egg. Click on create.02We’re going to start by creating a number of globalvariables that will be accessible from any part ofour program. To begin, click on the script button inthe top-right corner.20