let car_pos = 0
let hindernis_y = 0
let hindernis_x = 0
let speed = 0
let hindernis_unterwegs = false
basic.forever(() => {
if (!(hindernis_unterwegs)) {
led.unplot(hindernis_x, hindernis_y)
hindernis_y = 0
hindernis_x = Math.random(5)
led.plot(hindernis_x, hindernis_y)
hindernis_unterwegs = true
} else if (hindernis_unterwegs && hindernis_y < 3) {
led.unplot(hindernis_x, hindernis_y)
hindernis_y += 1
led.plot(hindernis_x, hindernis_y)
} else if (hindernis_unterwegs && hindernis_y == 3) {
hindernis_unterwegs = false
if (car_pos == hindernis_x) {
music.setTempo(120)
music.playTone(Note.G4, music.beat(BeatFraction.Whole))
music.playTone(Note.E4, music.beat(BeatFraction.Whole))
music.playTone(Note.C4, music.beat(BeatFraction.Whole))
basic.clearScreen()
basic.setLedColor(Colors.Red)
basic.showString("CRASH")
basic.pause(2000)
basic.setLedColor(Colors.Green)
speed = 200
car_pos = 2
led.plot(car_pos, 4)
music.setTempo(600)
} else {
led.unplot(hindernis_x, hindernis_y)
hindernis_y = 4
led.plot(hindernis_x, hindernis_y)
}
}
music.playTone(Note.C, music.beat(BeatFraction.Sixteenth))
basic.pause(speed)
speed += -1
})
input.onButtonPressed(Button.B, () => {
if (car_pos < 4) {
led.unplot(car_pos, 4)
car_pos += 1
led.plot(car_pos, 4)
}
})
input.onButtonPressed(Button.A, () => {
if (car_pos > 0) {
led.unplot(car_pos, 4)
car_pos += -1
led.plot(car_pos, 4)
}
})
music.setTempo(600)
speed = 200
car_pos = 2
led.plot(car_pos, 4)
basic.setLedColor(Colors.Green)
Comments
Please log in or sign up to comment.