Sunday, July 30, 2017

circling snake

It works... with a minor issue...

let yDelta = 0
let y: number[] = []
let xDelta = 0
let x: number[] = []
let rampUp = 0
let rampUpLimit = 4
basic.forever(() => {
    if (x[0] == 0 && y[0] == 0) {
        xDelta = 1
        yDelta = 0
    }
    if (x[0] == 4 && y[0] == 0) {
        xDelta = 0
        yDelta = 1
    }
    if (x[0] == 4 && y[0] == 4) {
        xDelta = -1
        yDelta = 0
    }
    if (x[0] == 0 && y[0] == 4) {
        xDelta = 0
        yDelta = -1
    }
    if (rampUpLimit < rampUp) {
        led.unplot(x[rampUpLimit], y[rampUpLimit])
        rampUp = rampUpLimit
    }
    led.plot(x[0], y[0])
    for (let index = rampUp; index >= 0; index--) {
        x[index + 1] = x[index]
        y[index + 1] = y[index]
    }
    rampUp = rampUp + 1
    basic.pause(100)
    x[0] = x[0] + xDelta
    y[0] = y[0] + yDelta
})
x = []
y = []

shooting target

No floating point allowed

let y = 0
let plane = 0
let x = 0
let increment = 0
basic.forever(() => {

})
input.onButtonPressed(Button.A, () => {
    basic.clearScreen()
    plane = Math.random(5)
    led.plot(plane, 4)
    increment = plane * 25
})
input.onButtonPressed(Button.B, () => {
    x = 0
    y = 0
    for (let i = 0; i < 5; i++) {
        led.plot(plane, y)
        basic.pause(100)
        led.unplot(plane, y)
        y = y + 1
    }
})

circling dot

let y = 0
let x = 0
let yDelta = 0
let xDelta = 0
basic.forever(() => {
    if (x == 0 && y == 0) {
        xDelta = 1
        yDelta = 0
    }
    if (x == 4 && y == 0) {
        xDelta = 0
        yDelta = 1
    }
    if (x == 4 && y == 4) {
        xDelta = -1
        yDelta = 0
    }
    if (x == 0 && y == 4) {
        xDelta = 0
        yDelta = -1
    }
    led.plot(x, y)
    basic.pause(100)
    led.unplot(x, y)
    x = x + xDelta
    y = y + yDelta
})