Last active
August 19, 2018 18:28
-
-
Save timb-machine/de966986d3fc096a26acdaa23c644200 to your computer and use it in GitHub Desktop.
micro:bit Space Invaders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://makecode.microbit.org/45205-27183-13795-15925 | |
let score = 0 | |
let delay = 0 | |
let highscore = 0 | |
let onscreen = 0 | |
let clearscreeen: Image = null | |
let ship: Image = null | |
input.onButtonPressed(Button.A, () => { | |
if (onscreen == 1) { | |
game.addScore(1) | |
basic.showString("SUCCESS!") | |
basic.pause(500) | |
} | |
}) | |
ship = images.createImage(` | |
. . # . . | |
. # # # . | |
# # # # # | |
# # # # # | |
. # . # . | |
`) | |
clearscreeen = images.createImage(` | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
`) | |
basic.showString("Space Invaders!") | |
ship.showImage(0) | |
basic.pause(100) | |
clearscreeen.showImage(0) | |
highscore = 0 | |
while (true) { | |
basic.showString("READY?") | |
basic.pause(100) | |
game.setScore(0) | |
for (let i = 0; i < 5; i++) { | |
delay = Math.random(501) | |
onscreen = 1 | |
ship.showImage(0) | |
basic.pause(delay) | |
onscreen = 0 | |
clearscreeen.showImage(0) | |
basic.pause(1000) | |
} | |
if (game.score() > highscore) { | |
highscore = game.score() | |
basic.showString("HIGH SCORE!") | |
basic.pause(500) | |
} else { | |
basic.showString("GAME OVER!") | |
basic.pause(500) | |
score = game.score() | |
basic.showNumber(score) | |
basic.pause(500) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment