Created
December 7, 2016 19:07
-
-
Save gingemonster/89f4eb986609ef477559d762765a4ebd to your computer and use it in GitHub Desktop.
Micromonsters Episode 7 - WarGames code
This file contains 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
let opponentsmissile: game.LedSprite = null | |
let missile: game.LedSprite = null | |
let switchxposition = 0 | |
let player = game.createSprite(2, 4) | |
let nummissles = 0 | |
input.onButtonPressed(Button.A, () => { | |
player.change(LedSpriteProperty.X, -1) | |
}) | |
input.onButtonPressed(Button.B, () => { | |
player.change(LedSpriteProperty.X, 1) | |
}) | |
input.onButtonPressed(Button.AB, () => { | |
if (nummissles < 1) { | |
nummissles += 1 | |
serial.writeNumber(nummissles) | |
missile = game.createSprite(player.get(LedSpriteProperty.X), player.get(LedSpriteProperty.Y)) | |
while (missile.get(LedSpriteProperty.Y) > 0) { | |
missile.change(LedSpriteProperty.Y, -1) | |
basic.pause(100) | |
} | |
missile.set(LedSpriteProperty.Brightness, 0) | |
nummissles += -1 | |
radio.sendValue("missileX", missile.get(LedSpriteProperty.X)) | |
} | |
}) | |
radio.onDataPacketReceived(({receivedString: name, receivedNumber: value}) => { | |
switchxposition = Math.abs(value - 4) | |
if (name == "missileX") { | |
opponentsmissile = game.createSprite(switchxposition, 0) | |
basic.pause(100) | |
while (opponentsmissile.get(LedSpriteProperty.Y) < 4) { | |
opponentsmissile.change(LedSpriteProperty.Y, 1) | |
if (opponentsmissile.isTouching(player)) { | |
radio.sendValue("winner", 1) | |
basic.showNumber(game.score()) | |
basic.pause(2000) | |
} else { | |
basic.pause(100) | |
} | |
} | |
opponentsmissile.set(LedSpriteProperty.Brightness, 0) | |
} | |
if (name == "winner") { | |
game.addScore(1) | |
basic.showNumber(game.score()) | |
basic.pause(2000) | |
} | |
}) |
Hello!
You did not program in blocks? Because i don't know Java Script...
You can paste it into the Java Script editor and then transfer it back to blocks in the Microsoft MakeCode editor.
I can’t figure out how to paste it /import into MakeCode
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello!
You did not program in blocks? Because i don't know Java Script...