Daniel Havlik
Published © CC BY-SA

Ausweichgame

Kleines Spiel für den Calliope Mini bei dem man Hindernissen ausweichen muss.

BeginnerFull instructions provided1 hour463
Ausweichgame

Things used in this project

Hardware components

Calliope mini
Calliope mini
×1

Software apps and online services

Calliope mini online editor

Story

Read more

Schematics

PXT Editor Screenshot

Code

Calliope Mini Ausweichspiel

JavaScript
Javascript-Code für http://pxt.calliope.cc/
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)

Credits

Daniel Havlik

Daniel Havlik

5 projects • 5 followers
Hacker, Maker, Tinkerer at Eigenbaukombinat Halle e.V., Software Engineer, Python Developer, Owner at gocept gmbh & co. kg.

Comments