Skip to content

Instantly share code, notes, and snippets.

@fgnass
Created August 18, 2018 13:48
Show Gist options
  • Save fgnass/7d51079cc234969bb14f46a55e718def to your computer and use it in GitHub Desktop.
Save fgnass/7d51079cc234969bb14f46a55e718def to your computer and use it in GitHub Desktop.
Microbit Game
let ball: game.LedSprite = null
let player: game.LedSprite = null
let score = 0
let lives = 0
input.onButtonPressed(Button.A, () => {
player.move(-1)
})
input.onButtonPressed(Button.B, () => {
player.move(1)
})
lives = 3
score = 0
player = game.createSprite(2, 4)
ball = game.createSprite(2, 0)
ball.set(LedSpriteProperty.Direction, 180)
basic.forever(() => {
basic.pause(200)
ball.move(1)
basic.pause(200)
if (ball.get(LedSpriteProperty.Y) == 4) {
if (ball.isTouching(player)) {
lives += -1
if (lives == 0) {
basic.showIcon(IconNames.No)
basic.showIcon(IconNames.Sad)
basic.showNumber(score)
lives = 3
score = 0
}
} else {
score += 1
}
ball.set(LedSpriteProperty.Brightness, 0)
basic.pause(1000)
ball.set(LedSpriteProperty.Y, 0)
ball.set(LedSpriteProperty.X, Math.random(5))
ball.set(LedSpriteProperty.Brightness, 100)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment