catch the egg game challenges
Before we get started
Your starting code should look like this:
let basketX = 2
let eggX = 2
let eggY = 0
basic.forever(function() {
led.unplot(basketX, 4)
led.unplot(eggX, eggY)
eggY += 1
led.plot(eggX, eggY)
basic.pause(300)
let accX = input.acceleration(Dimension.X)
basketX = 2 + Math.min(2, Math.max(-2, Math.idiv(accX, 200)))
led.plot(basketX, 4)
if (eggY > 4) {
eggY = -1
eggX = randint(0, 4)
}
basic.pause(300)
})
Challenge 1
let basketX1 = 2
let eggX1 = 2
let eggY1 = 0
basic.forever(function() {
led.unplot(basketX1, 4)
led.unplot(eggX1, eggY1)
eggY1 += 1
led.plot(eggX1, eggY1)
basic.pause(300)
let accX = input.acceleration(Dimension.X)
basketX1 = 2 + Math.min(2, Math.max(-2, Math.idiv(accX, 200)))
led.plot(basketX1, 4)
if (eggY1 > 4) {
eggY1 = -1
eggX1 = randint(0, 4)
}
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.
Challenge 2
let basketX2 = 2
let eggX2 = 2
let eggY2 = 0
let fallingPause = 300
basic.forever(function() {
led.unplot(basketX2, 4)
led.unplot(eggX2, eggY2)
eggY2 += 1
led.plot(eggX2, eggY2)
basic.pause(300)
let accX2 = input.acceleration(Dimension.X)
basketX2 = 2 + Math.min(2, Math.max(-2, Math.idiv(accX2, 200)))
led.plot(basketX2, 4)
if (eggY2 > 4) {
eggY2 = -1
eggX2 = randint(0, 4)
}
if (eggY2 == 4) {
if (basketX2 == eggX2) {
game.addScore(1)
if (game.score() %5 == 0) {
}
} else {
game.removeLife(1)
}
}
basic.pause(300)
})
Challenge 3
let basketX3 = 2
let eggX3 = 2
let eggY3 = 0
let fallingPause1 = 300
basic.forever(function() {
led.unplot(basketX3, 4)
led.unplot(eggX3, eggY3)
eggY3 += 1
led.plot(eggX3, eggY3)
basic.pause(300)
let accX3 = input.acceleration(Dimension.X)
basketX3 = 2 + Math.min(2, Math.max(-2, Math.idiv(accX3, 200)))
led.plot(basketX3, 4)
if (eggY3 > 4) {
eggY3 = -1
eggX3 = randint(0, 4)
}
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!