Skip to content

Instantly share code, notes, and snippets.

@bluemyria
Created July 5, 2017 11:07
Show Gist options
  • Save bluemyria/eb3a1c1c8dfe821c6ac16e7f87ca4fb0 to your computer and use it in GitHub Desktop.
Save bluemyria/eb3a1c1c8dfe821c6ac16e7f87ca4fb0 to your computer and use it in GitHub Desktop.
Space Invaders microbit
let Bullet: game.LedSprite = null
let Ship: game.LedSprite = null
let Invader: game.LedSprite = null
basic.forever(() => {
Invader = game.createSprite(Math.random(5), 0)
Invader.set(LedSpriteProperty.Brightness, 255)
for (let i = 0; i < 4; i++) {
Invader.change(LedSpriteProperty.Y, 1)
basic.pause(2000)
if (Invader.isTouching(Ship)) {
Invader.set(LedSpriteProperty.Brightness, 0)
Ship.set(LedSpriteProperty.Blink, 1)
basic.pause(5000)
}
if (Invader.get(LedSpriteProperty.Y) >= 4) {
Invader.delete()
}
}
})
basic.forever(() => {
if (input.acceleration(Dimension.X) < 0) {
Ship.change(LedSpriteProperty.X, -1)
basic.pause(150)
}
if (input.acceleration(Dimension.X) > 0) {
Ship.change(LedSpriteProperty.X, 1)
basic.pause(150)
}
if (input.buttonIsPressed(Button.A) || input.buttonIsPressed(Button.B)) {
Bullet = game.createSprite(Ship.get(LedSpriteProperty.X), Ship.get(LedSpriteProperty.Y))
Bullet.set(LedSpriteProperty.Brightness, 255)
for (let i = 0; i < 4; i++) {
Bullet.change(LedSpriteProperty.Y, -1)
if (Invader.isTouching(Bullet)) {
Bullet.set(LedSpriteProperty.Brightness, 0)
Invader.set(LedSpriteProperty.Blink, 3)
basic.pause(5000)
Invader.delete()
}
basic.pause(500)
if (Bullet.get(LedSpriteProperty.Y) <= 0) {
Bullet.set(LedSpriteProperty.Brightness, 0)
}
}
}
})
Ship = game.createSprite(2, 4)
Bullet = game.createSprite(0, 0)
Bullet.set(LedSpriteProperty.Brightness, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment