D'ante McCain
Published © GPL3+

My Light Timer Game

How fast can you press each light before the timer runs out.

IntermediateFull instructions provided3 hours149
My Light Timer Game

Story

Read more

Code

My Code

Java
input.buttonA.onEvent(ButtonEvent.Click, function () {
    timerRunning = 1
    index = 0
    counter = 0
    stripCounter = 0
    light.setAll(0x000000)
    strip.setAll(0x000000)
    whichColor = color1
    music.baDing.play()
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
    timerRunning = 1
    index = 0
    counter = 0
    stripCounter = 0
    light.setAll(0x000000)
    strip.setAll(0x000000)
    whichColor = color2
    music.pewPew.play()
})
input.touchA2.onEvent(ButtonEvent.Down, function () {
    timerRunning = 1
    index = 0
    counter = 0
    stripCounter = 0
    light.setAll(0x000000)
    strip.setAll(0x000000)
    whichColor = color3
    music.jumpUp.play()
})
input.touchA5.onEvent(ButtonEvent.Down, function () {
    timerRunning = 1
    index = 0
    counter = 0
    stripCounter = 0
    light.setAll(0x000000)
    strip.setAll(0x000000)
    whichColor = color4
    music.magicWand.play()
})
let whichColor = 0
let stripCounter = 0
let strip: light.NeoPixelStrip = null
let timerRunning = 0
let index = 0
let color4 = 0
let color3 = 0
let color2 = 0
let color1 = 0
let counter = 0
let timer = 10
counter = 0
color1 = Colors.Red
color2 = Colors.Blue
color3 = Colors.Green
color4 = Colors.Yellow
index = 0
timerRunning = 0
strip = light.createStrip(pins.A1, 30)
forever(function () {
    if (timerRunning == 1) {
        light.setPixelColor(counter, whichColor)
        strip.setPixelColor(stripCounter, whichColor)
        index += 1
        counter += 1
        stripCounter += 1
        pause(200)
        if (counter == 10) {
            light.setAll(0x000000)
            counter = 0
        }
        if (stripCounter == strip.length()) {
            strip.setAll(0x000000)
            stripCounter = 0
        }
        if (index == timer) {
            music.wawawawaa.playUntilDone()
            for (let i = 0; i < 3; i++) {
                light.setAll(0x000000)
                strip.setAll(0x000000)
                pause(200)
                light.setAll(whichColor)
                strip.setAll(whichColor)
                pause(200)
            }
            index = 0
            timerRunning = 0
        }
    }
})

Credits

D'ante McCain
4 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.