-
-
Save will-moore/4c79a901bb79a695f7e0601565e28793 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 missile: game.LedSprite = null | |
let opponentsmissile: game.LedSprite = null | |
let score = 0 | |
let nummissles = 0 | |
let player: game.LedSprite = null | |
let switchxposition = 0 | |
input.onButtonPressed(Button.A, () => { | |
player.change(LedSpriteProperty.X, -1) | |
}) | |
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(score) | |
basic.pause(2000) | |
} else { | |
basic.pause(100) | |
} | |
} | |
opponentsmissile.set(LedSpriteProperty.Brightness, 0) | |
} | |
if (name == "winner") { | |
score += 1 | |
basic.showNumber(score) | |
basic.pause(2000) | |
} | |
}) | |
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)) | |
} | |
}) | |
input.onButtonPressed(Button.B, () => { | |
player.change(LedSpriteProperty.X, 1) | |
}) | |
player = game.createSprite(2, 4) | |
score = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment