Daniel Stolba
Published © CC BY-NC-SA

Calliope-Pong

Ich habe das "Minispiel" von Ali als Basis benutzt, um eine Art "Pong" zu bauen.

IntermediateFull instructions provided1 hour358
Calliope-Pong

Things used in this project

Story

Read more

Code

Pong-Minispiel

JavaScript
Ich habe aus dem Minispiel von Ali ein Pong gebaut.
let block_y = 0
let block_x = 0
let pause = 0
let dir_y = 0
let punkte = 0
let dir_x = 0
let alive = false
let spieler_x = 0
input.onButtonPressed(Button.A, () => {
    spieler_x += -1
    if (spieler_x <= 0) {
        spieler_x = 0
    }
})
input.onButtonPressed(Button.B, () => {
    spieler_x += 1
    if (spieler_x >= 4) {
        spieler_x = 4
    }
})
alive = true
dir_x = Math.random(3) - 1
punkte = 0
dir_y = 1
pause = 800
block_x = Math.random(5)
block_y = -1
while (alive == true) {
    basic.clearScreen()
    led.plot(spieler_x, 4)
    led.plot(block_x, block_y)
    basic.pause(pause)
    block_y += dir_y
    block_x += dir_x
    if (block_x == -1) {
        music.playTone(330, music.beat(BeatFraction.Sixteenth))
        block_x = 1
        dir_x = 1
    }
    if (block_x == 5) {
        music.playTone(440, music.beat(BeatFraction.Sixteenth))
        block_x = 3
        dir_x = -1
    }
    if (block_y == -1) {
        music.playTone(196, music.beat(BeatFraction.Sixteenth))
        block_y = 1
        dir_y = 1
    }
    if (block_y == 4) {
        if (spieler_x == block_x - dir_x) {
            block_y = 2
            dir_y = -1
            music.playTone(523, music.beat(BeatFraction.Sixteenth))
            punkte += 1
            if (dir_x == 0) {
                if (block_x < 2) {
                    dir_x = -1
                } else {
                    dir_x = 1
                }
            }
        } else {
            alive = false
            music.playTone(165, music.beat(BeatFraction.Whole))
            music.playTone(131, music.beat(BeatFraction.Whole))
            basic.showNumber(punkte)
        }
    }
    pause += -5
}

Credits

Daniel Stolba

Daniel Stolba

0 projects • 1 follower
Thanks to Ali.

Comments