pxt-calliope/docs/lessons/catch-the-egg-game/challenge.md

31 lines
756 B
Markdown
Raw Normal View History

# catch the egg game challenge
2016-05-09 19:32:02 +02:00
## Rebuild the game!
2016-05-09 19:32:02 +02:00
The blocks have been shuffled! Put them back together so that...
2016-05-09 19:32:02 +02:00
* an egg LED falls from the top of the screen, row by row.
* a basket LED is on the bottom row and can be moved by using the accelerometer `X` data.
* if the egg LED reaches the last row, reset the egg position to the first row.
2018-11-02 06:22:54 +01:00
```blocks
2016-05-09 19:32:02 +02:00
let basketX = 2
let eggX = 2
let eggY = 0
let accX = input.acceleration(Dimension.X)
basic.forever(function () {
2016-05-09 19:32:02 +02:00
basic.pause(300)
eggY += 1
led.plot(eggX, eggY)
2016-05-09 19:32:02 +02:00
basic.pause(300)
led.unplot(basketX, 4)
led.unplot(eggX, eggY)
2016-05-09 19:32:02 +02:00
})
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
if (eggY > 4) {
eggY = -1
eggX = Math.randomRange(0, 4)
}
led.plot(basketX, 4)
2016-05-09 19:32:02 +02:00
```