move lessons out of web site
will move select lessons back to "educators" section
This commit is contained in:
148
olddocs/lessons/catch-the-egg-game/activity.md
Normal file
148
olddocs/lessons/catch-the-egg-game/activity.md
Normal file
@ -0,0 +1,148 @@
|
||||
# catch the egg game challenges
|
||||
|
||||
## Before we get started
|
||||
|
||||
Your starting code should look like this:
|
||||
|
||||
```blocks
|
||||
let basketX = 2
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX, 4)
|
||||
led.unplot(eggX, eggY)
|
||||
eggY = eggY + 1
|
||||
led.plot(eggX, eggY)
|
||||
basic.pause(300)
|
||||
let accX = input.acceleration(Dimension.X)
|
||||
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||
led.plot(basketX, 4)
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.random(5)
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar impressed
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's use an **IF** statement to detect if the egg and the basket are lined up.
|
||||
|
||||
Now that we know when an egg is caught, we can keep track of the score! We need to use the `add score` function built into the game library to add `1` point for every egg that is caught. However, let's not forget to `remove life` if an egg falls off the display before it's caught!
|
||||
|
||||
### ~
|
||||
|
||||
```blocks
|
||||
let basketX1 = 2
|
||||
let eggX1 = 2
|
||||
let eggY1 = 0
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX1, 4)
|
||||
led.unplot(eggX1, eggY1)
|
||||
eggY1 = eggY1 + 1
|
||||
led.plot(eggX1, eggY1)
|
||||
basic.pause(300)
|
||||
let accX = input.acceleration(Dimension.X)
|
||||
basketX1 = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||
led.plot(basketX1, 4)
|
||||
if (eggY1 > 4) {
|
||||
eggY1 = -1
|
||||
eggX1 = Math.random(5)
|
||||
}
|
||||
if (eggY1 == 4) {
|
||||
if (basketX1 == eggX1) {
|
||||
game.addScore(1)
|
||||
} else {
|
||||
game.removeLife(1)
|
||||
}
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
||||
|
||||
* Press the `run` button to test out your game.
|
||||
|
||||
### ~avatar avatar encourage
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Catching eggs gets easier with practice so let's make the eggs fall faster every 5 catches. We can do this by tracking how long the egg pauses in each position while falling with a global variable called **falling pause**. Let's create this variable and set it to `300` initially. Don't forget to also create a condition that will be true every 5 catches.
|
||||
|
||||
### ~
|
||||
|
||||
```blocks
|
||||
let basketX2 = 2
|
||||
let eggX2 = 2
|
||||
let eggY2 = 0
|
||||
let fallingPause = 300 // ***
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX2, 4)
|
||||
led.unplot(eggX2, eggY2)
|
||||
eggY2 = eggY2 + 1
|
||||
led.plot(eggX2, eggY2)
|
||||
basic.pause(300)
|
||||
let accX2 = input.acceleration(Dimension.X)
|
||||
basketX2 = 2 + Math.min(2, Math.max(-2, accX2 / 200))
|
||||
led.plot(basketX2, 4)
|
||||
if (eggY2 > 4) {
|
||||
eggY2 = -1
|
||||
eggX2 = Math.random(5)
|
||||
}
|
||||
if (eggY2 == 4) {
|
||||
if (basketX2 == eggX2) {
|
||||
game.addScore(1)
|
||||
if (game.score() %5 == 0) {
|
||||
}
|
||||
} else {
|
||||
game.removeLife(1)
|
||||
}
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar surprised
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Let's make the egg fall faster by decreasing the amount of time it pauses in each position by decreasing **falling pause** by `25` every 5 catches. Now, instead of pausing for 300 milliseconds we can pause for the value of **falling pause**.
|
||||
|
||||
```blocks
|
||||
let basketX3 = 2
|
||||
let eggX3 = 2
|
||||
let eggY3 = 0
|
||||
let fallingPause1 = 300
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX3, 4)
|
||||
led.unplot(eggX3, eggY3)
|
||||
eggY3 = eggY3 + 1
|
||||
led.plot(eggX3, eggY3)
|
||||
basic.pause(300)
|
||||
let accX3 = input.acceleration(Dimension.X)
|
||||
basketX3 = 2 + Math.min(2, Math.max(-2, accX3 / 200))
|
||||
led.plot(basketX3, 4)
|
||||
if (eggY3 > 4) {
|
||||
eggY3 = -1
|
||||
eggX3 = Math.random(5)
|
||||
}
|
||||
if (eggY3 == 4) {
|
||||
if (basketX3 == eggX3) {
|
||||
game.addScore(1)
|
||||
if (game.score()% 5 == 0) {
|
||||
fallingPause1 = fallingPause1 - 25 // ***
|
||||
}
|
||||
} else {
|
||||
game.removeLife(1)
|
||||
}
|
||||
}
|
||||
basic.pause(fallingPause1)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
Fantastic! Your game is now ready to show off.
|
||||
|
||||
* Press the `run` button to see your finished game!
|
58
olddocs/lessons/catch-the-egg-game/quiz-answers.md
Normal file
58
olddocs/lessons/catch-the-egg-game/quiz-answers.md
Normal file
@ -0,0 +1,58 @@
|
||||
# catch the egg game quiz answers
|
||||
|
||||
Programming a game of catch the egg using the accelerometer
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [catch the egg activity](/lessons/catch-the-egg-game/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the data type for the global variables 'basket' and 'egg'.
|
||||
|
||||
<br/>
|
||||
|
||||
'Basket' and 'egg' are stored as **Number**.
|
||||
|
||||
## 2. Write the code to plot the initial position of the egg and the basket using the variables 'egg x', 'egg y', and 'basket x'. The code should arrange the egg and basket as shown below.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let basketX = 2
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
led.plot(eggX, eggY)
|
||||
led.plot(basketX, 4)
|
||||
```
|
||||
|
||||
## 3. Write the three lines of code that moves the egg down. (You need to unplot the egg's current position, update its position variables, and plot its new position.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let basketX = 2
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
led.unplot(eggX, eggY)
|
||||
eggY = eggY + 1
|
||||
led.plot(eggX, eggY)
|
||||
```
|
||||
|
||||
## 4. . Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.random(5)
|
||||
}
|
||||
```
|
||||
|
30
olddocs/lessons/catch-the-egg-game/quiz.md
Normal file
30
olddocs/lessons/catch-the-egg-game/quiz.md
Normal file
@ -0,0 +1,30 @@
|
||||
# catch the egg game quiz
|
||||
|
||||
Programming a game of catch the egg using the accelerometer.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [catch the egg challenges](/lessons/catch-the-egg-game/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the data type for the variables 'basket' and 'egg'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code to plot the initial position of the egg and the basket using the variables 'egg x', 'egg y', and 'basket x'. The code should arrange the egg and basket as shown below.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the three lines of code that moves the egg down. (You need to unplot the egg's current position, update its position variables, and plot its new position.
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
29
olddocs/lessons/catch-the-egg-game/tutorial.md
Normal file
29
olddocs/lessons/catch-the-egg-game/tutorial.md
Normal file
@ -0,0 +1,29 @@
|
||||
# catch the egg game tutorial
|
||||
|
||||
### Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that...
|
||||
* 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.
|
||||
|
||||
```shuffle
|
||||
let basketX = 2
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX, 4)
|
||||
led.unplot(eggX, eggY)
|
||||
eggY = eggY + 1
|
||||
led.plot(eggX, eggY)
|
||||
basic.pause(300)
|
||||
let accX = input.acceleration(Dimension.X)
|
||||
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||
led.plot(basketX, 4)
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.random(5)
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
Reference in New Issue
Block a user