Some updates to 'catch the egg' (#1588)
This commit is contained in:
parent
54695601fa
commit
ec45f388df
@ -9,7 +9,7 @@ Variables
|
|||||||
## Quick Links
|
## Quick Links
|
||||||
|
|
||||||
* [activity](/lessons/catch-the-egg-game/activity)
|
* [activity](/lessons/catch-the-egg-game/activity)
|
||||||
* [tutorial](/lessons/catch-the-egg-game/tutorial)
|
* [challenge](/lessons/catch-the-egg-game/challenge)
|
||||||
* [quiz](/lessons/catch-the-egg-game/quiz)
|
* [quiz](/lessons/catch-the-egg-game/quiz)
|
||||||
* [quiz answers](/lessons/catch-the-egg-game/quiz-answers)
|
* [quiz answers](/lessons/catch-the-egg-game/quiz-answers)
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ basic.pause(300);
|
|||||||
input.acceleration(Dimension.X);
|
input.acceleration(Dimension.X);
|
||||||
Math.min(0,0);
|
Math.min(0,0);
|
||||||
Math.max(0,1);
|
Math.max(0,1);
|
||||||
Math.randomRange(0, 5);
|
Math.randomRange(0, 4);
|
||||||
game.addScore(1);
|
game.addScore(1);
|
||||||
game.score();
|
game.score();
|
||||||
game.removeLife(1);
|
game.removeLife(1);
|
||||||
|
@ -8,10 +8,10 @@ Your starting code should look like this:
|
|||||||
let basketX = 2
|
let basketX = 2
|
||||||
let eggX = 2
|
let eggX = 2
|
||||||
let eggY = 0
|
let eggY = 0
|
||||||
basic.forever(() => {
|
basic.forever(function() {
|
||||||
led.unplot(basketX, 4)
|
led.unplot(basketX, 4)
|
||||||
led.unplot(eggX, eggY)
|
led.unplot(eggX, eggY)
|
||||||
eggY = eggY + 1
|
eggY += 1
|
||||||
led.plot(eggX, eggY)
|
led.plot(eggX, eggY)
|
||||||
basic.pause(300)
|
basic.pause(300)
|
||||||
let accX = input.acceleration(Dimension.X)
|
let accX = input.acceleration(Dimension.X)
|
||||||
@ -19,30 +19,30 @@ basic.forever(() => {
|
|||||||
led.plot(basketX, 4)
|
led.plot(basketX, 4)
|
||||||
if (eggY > 4) {
|
if (eggY > 4) {
|
||||||
eggY = -1
|
eggY = -1
|
||||||
eggX = Math.randomRange(0, 5)
|
eggX = Math.randomRange(0, 4)
|
||||||
}
|
}
|
||||||
basic.pause(300)
|
basic.pause(300)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## ~avatar avatar impressed
|
|
||||||
|
|
||||||
## Challenge 1
|
## Challenge 1
|
||||||
|
|
||||||
|
### ~avatar avatar impressed
|
||||||
|
|
||||||
Let's use an **IF** statement to detect if the egg and the basket are lined up.
|
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!
|
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
|
```blocks
|
||||||
let basketX1 = 2
|
let basketX1 = 2
|
||||||
let eggX1 = 2
|
let eggX1 = 2
|
||||||
let eggY1 = 0
|
let eggY1 = 0
|
||||||
basic.forever(() => {
|
basic.forever(function() {
|
||||||
led.unplot(basketX1, 4)
|
led.unplot(basketX1, 4)
|
||||||
led.unplot(eggX1, eggY1)
|
led.unplot(eggX1, eggY1)
|
||||||
eggY1 = eggY1 + 1
|
eggY1 += 1
|
||||||
led.plot(eggX1, eggY1)
|
led.plot(eggX1, eggY1)
|
||||||
basic.pause(300)
|
basic.pause(300)
|
||||||
let accX = input.acceleration(Dimension.X)
|
let accX = input.acceleration(Dimension.X)
|
||||||
@ -50,7 +50,7 @@ basic.forever(() => {
|
|||||||
led.plot(basketX1, 4)
|
led.plot(basketX1, 4)
|
||||||
if (eggY1 > 4) {
|
if (eggY1 > 4) {
|
||||||
eggY1 = -1
|
eggY1 = -1
|
||||||
eggX1 = Math.randomRange(0, 5)
|
eggX1 = Math.randomRange(0, 4)
|
||||||
}
|
}
|
||||||
if (eggY1 == 4) {
|
if (eggY1 == 4) {
|
||||||
if (basketX1 == eggX1) {
|
if (basketX1 == eggX1) {
|
||||||
@ -65,23 +65,23 @@ basic.forever(() => {
|
|||||||
|
|
||||||
* Press the `run` button to test out your game.
|
* Press the `run` button to test out your game.
|
||||||
|
|
||||||
## ~avatar avatar encourage
|
|
||||||
|
|
||||||
## Challenge 2
|
## Challenge 2
|
||||||
|
|
||||||
|
### ~avatar avatar encourage
|
||||||
|
|
||||||
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.
|
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
|
```blocks
|
||||||
let basketX2 = 2
|
let basketX2 = 2
|
||||||
let eggX2 = 2
|
let eggX2 = 2
|
||||||
let eggY2 = 0
|
let eggY2 = 0
|
||||||
let fallingPause = 300 // ***
|
let fallingPause = 300
|
||||||
basic.forever(() => {
|
basic.forever(function() {
|
||||||
led.unplot(basketX2, 4)
|
led.unplot(basketX2, 4)
|
||||||
led.unplot(eggX2, eggY2)
|
led.unplot(eggX2, eggY2)
|
||||||
eggY2 = eggY2 + 1
|
eggY2 += 1
|
||||||
led.plot(eggX2, eggY2)
|
led.plot(eggX2, eggY2)
|
||||||
basic.pause(300)
|
basic.pause(300)
|
||||||
let accX2 = input.acceleration(Dimension.X)
|
let accX2 = input.acceleration(Dimension.X)
|
||||||
@ -89,7 +89,7 @@ basic.forever(() => {
|
|||||||
led.plot(basketX2, 4)
|
led.plot(basketX2, 4)
|
||||||
if (eggY2 > 4) {
|
if (eggY2 > 4) {
|
||||||
eggY2 = -1
|
eggY2 = -1
|
||||||
eggX2 = Math.randomRange(0, 5)
|
eggX2 = Math.randomRange(0, 4)
|
||||||
}
|
}
|
||||||
if (eggY2 == 4) {
|
if (eggY2 == 4) {
|
||||||
if (basketX2 == eggX2) {
|
if (basketX2 == eggX2) {
|
||||||
@ -104,21 +104,23 @@ basic.forever(() => {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## ~avatar avatar surprised
|
|
||||||
|
|
||||||
## Challenge 3
|
## Challenge 3
|
||||||
|
|
||||||
|
### ~avatar avatar surprised
|
||||||
|
|
||||||
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**.
|
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
|
```blocks
|
||||||
let basketX3 = 2
|
let basketX3 = 2
|
||||||
let eggX3 = 2
|
let eggX3 = 2
|
||||||
let eggY3 = 0
|
let eggY3 = 0
|
||||||
let fallingPause1 = 300
|
let fallingPause1 = 300
|
||||||
basic.forever(() => {
|
basic.forever(function() {
|
||||||
led.unplot(basketX3, 4)
|
led.unplot(basketX3, 4)
|
||||||
led.unplot(eggX3, eggY3)
|
led.unplot(eggX3, eggY3)
|
||||||
eggY3 = eggY3 + 1
|
eggY3 += 1
|
||||||
led.plot(eggX3, eggY3)
|
led.plot(eggX3, eggY3)
|
||||||
basic.pause(300)
|
basic.pause(300)
|
||||||
let accX3 = input.acceleration(Dimension.X)
|
let accX3 = input.acceleration(Dimension.X)
|
||||||
@ -126,13 +128,13 @@ basic.forever(() => {
|
|||||||
led.plot(basketX3, 4)
|
led.plot(basketX3, 4)
|
||||||
if (eggY3 > 4) {
|
if (eggY3 > 4) {
|
||||||
eggY3 = -1
|
eggY3 = -1
|
||||||
eggX3 = Math.randomRange(0, 5)
|
eggX3 = Math.randomRange(0, 4)
|
||||||
}
|
}
|
||||||
if (eggY3 == 4) {
|
if (eggY3 == 4) {
|
||||||
if (basketX3 == eggX3) {
|
if (basketX3 == eggX3) {
|
||||||
game.addScore(1)
|
game.addScore(1)
|
||||||
if (game.score()% 5 == 0) {
|
if (game.score()% 5 == 0) {
|
||||||
fallingPause1 = fallingPause1 - 25 // ***
|
fallingPause1 = fallingPause1 - 25
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
game.removeLife(1)
|
game.removeLife(1)
|
||||||
@ -140,7 +142,6 @@ basic.forever(() => {
|
|||||||
}
|
}
|
||||||
basic.pause(fallingPause1)
|
basic.pause(fallingPause1)
|
||||||
})
|
})
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Fantastic! Your game is now ready to show off.
|
Fantastic! Your game is now ready to show off.
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
# catch the egg game tutorial
|
# catch the egg game challenge
|
||||||
|
|
||||||
## Rebuild the game!
|
## Rebuild the game!
|
||||||
|
|
||||||
The blocks have been shuffled! Put them back together so that...
|
The blocks have been shuffled! Put them back together so that...
|
||||||
|
|
||||||
* an egg LED falls from the top of the screen, row by row.
|
* 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.
|
* 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.
|
* if the egg LED reaches the last row, reset the egg position to the first row.
|
||||||
@ -11,19 +12,19 @@ The blocks have been shuffled! Put them back together so that...
|
|||||||
let basketX = 2
|
let basketX = 2
|
||||||
let eggX = 2
|
let eggX = 2
|
||||||
let eggY = 0
|
let eggY = 0
|
||||||
basic.forever(() => {
|
let accX = input.acceleration(Dimension.X)
|
||||||
led.unplot(basketX, 4)
|
basic.forever(function () {
|
||||||
led.unplot(eggX, eggY)
|
basic.pause(300)
|
||||||
eggY = eggY + 1
|
eggY += 1
|
||||||
led.plot(eggX, eggY)
|
led.plot(eggX, eggY)
|
||||||
basic.pause(300)
|
basic.pause(300)
|
||||||
let accX = input.acceleration(Dimension.X)
|
led.unplot(basketX, 4)
|
||||||
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
led.unplot(eggX, eggY)
|
||||||
led.plot(basketX, 4)
|
|
||||||
if (eggY > 4) {
|
|
||||||
eggY = -1
|
|
||||||
eggX = Math.randomRange(0, 5)
|
|
||||||
}
|
|
||||||
basic.pause(300)
|
|
||||||
})
|
})
|
||||||
|
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||||
|
if (eggY > 4) {
|
||||||
|
eggY = -1
|
||||||
|
eggX = Math.randomRange(0, 4)
|
||||||
|
}
|
||||||
|
led.plot(basketX, 4)
|
||||||
```
|
```
|
Loading…
Reference in New Issue
Block a user