Theory
๐โ๏ธ 7. Sensors: Making a reaction game
๐ฎ Create reaction test game:
- ๐น๏ธ Moveable light moves left to right.
- ๐ ฐ๏ธ Press A button when lights in middle for point.
- โ Press at wrong time to lose.
- ๐จ Create ‘sprite’ variable:
- ๐ Sprite: moveable item, like ‘Steve’ in Minecraft.
- ๐ Set sprite variable:
- ๐ Initialize sprite as 0.
- ๐ฎ Use ‘game’ menu:
- ๐ข Find ‘create sprite’ command.
- ๐ Place at coordinates x=2, y=2.
๐ข Each light on Microbit has unique coordinates.
๐ Light circled is 3,2 (x=3, y=2).
๐ฏ Can you determine the value of the center light?
- ๐ 2,2 because x = 2 and y = 2.
- ๐ป Create command…
- ๐จ Create sprite at centre of screen.
- ๐โโ๏ธ Make sprite move side to side.
- ๐ If sprite reaches screen edge, bounce back.
- โธ๏ธ Add pause to slow down sprite movement.
- ๐ฎ Adjust sprite speed based on number size.
- ๐ฎ Set actions for button A press and game win/loss.
- ๐ฃ Get “on button A pressed” from input menu.
- ๐ต Get “if true then ____________ else_______” from logic menu.
- ๐ฎ Determine conditions for scoring and game over.
- ๐ต Use “if 0 = 0” from logic menu.
- ๐ฎ Replace 0 with “sprite x” and 2.
- ๐ฎ Define actions based on sprite position.
- ๐ฃ Add “change score by 1” under “if sprite x = 2”.
- ๐ฎ Add “game over” under “else”.
ย The final code will look like this.
- ๐ฅ Download the game and try it out!
- ๐ Press A and B together to restart after losing.
- โฉ Adjust speed: Smaller number in pause command for faster pace.
- โช Adjust speed: Larger number in pause command for slower pace.