Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Collectathon Rush:
- FOR SIMULATED PLAY
- Just run in your browser sandbox! Simple does it.
- FOR PHYSICAL PLAY ON REAL HARDWARE
- You need a working micro:bit with a Micro-USB Connection, two alligator clips, and a buzzer that can play sound effects.
- *optional: battery pack*
- Links to purchase them across different platforms:
- Buzzer: https://www.adafruit.com/product/1536?gclid=Cj0KCQjw5JSLBhCxARIsAHgO2SfBh41s9bN6mcovQsB6yxvBV8Bfoq8y0ClzVbHU1YThy01veJggZjwaAlmZEALw_wcB
- micro:bit: https://microbit.org/buy
- Alligator Clips: https://www.adafruit.com/product/1008
- CONNECTING EVERYTHING UP:
- Buzzer: Take two alligator clips. Clip one of them to P0. Take the other one and connect it to the GND pin. Afterwards, take GND and connect it to the minus wire, and take P0 and connect it to the positive wire.
- micro:bit: Do I have to explain this one? You all already know how to do it.
- DOWNLOADING SOFTWARE
- Connect your micro:bit up to your computer with a Micro-USB cable, connect the micro:bit to your browser, and download the software onto it!
- ADDITIONAL INFO:
- This game is cross compatible with V1 and V2 micro:bit machines!
- CONTROLS:
- A to move horizontally.
- B to move vertically.
- A+B to sweep across the board in either vertical, or horizontal direction. (somewhat broken, will fix soon enough)
- */
- let player = game.createSprite(2, 2)
- let collectable = game.createSprite(randint(0, 4), randint(0, 4))
- let isMovingVertically = false //you need this, it's important ;)
- let sweepTime = 5000 //in pause time
- let playerX = 2;
- let playerY = 2;
- let movingOpposite = false
- input.onButtonPressed(Button.A, () => {
- if (isMovingVertically == true) {
- player.turnLeft(90)
- isMovingVertically = false
- if (player.isTouchingEdge()) {
- if (movingOpposite == false) {
- movingOpposite = true
- } else {
- movingOpposite = false
- }
- }
- if (movingOpposite == true) {
- player.ifOnEdgeBounce()
- player.move(1)
- music.playTone(Note.B, 25)
- playerX--
- } else {
- player.ifOnEdgeBounce()
- player.move(1)
- music.playTone(Note.B, 25)
- playerX++
- }
- } else {
- if (player.isTouchingEdge()) {
- if (movingOpposite == false) {
- movingOpposite = true
- } else {
- movingOpposite = false
- }
- }
- if (movingOpposite == true) {
- player.ifOnEdgeBounce()
- player.move(1)
- music.playTone(Note.B, 25)
- playerX--
- } else {
- player.ifOnEdgeBounce()
- player.move(1)
- music.playTone(Note.B, 25)
- playerX++
- }
- }
- })
- input.onButtonPressed(Button.B, () => {
- if (isMovingVertically == false) {
- player.turnRight(90)
- isMovingVertically = true
- if (player.isTouchingEdge()) {
- if (movingOpposite == false) {
- movingOpposite = true
- } else {
- movingOpposite = false
- }
- }
- if (movingOpposite == true) {
- player.ifOnEdgeBounce()
- player.move(1)
- music.playTone(Note.B, 25)
- playerY--
- } else {
- player.ifOnEdgeBounce()
- player.move(1)
- music.playTone(Note.B, 25)
- playerY++
- }
- } else {
- if (player.isTouchingEdge()) {
- if (movingOpposite == false) {
- movingOpposite = true
- } else {
- movingOpposite = false
- }
- }
- if (movingOpposite == true) {
- player.ifOnEdgeBounce()
- player.move(1)
- music.playTone(Note.B, 25)
- playerY--
- } else {
- player.ifOnEdgeBounce()
- player.move(1)
- music.playTone(Note.B, 25)
- playerY++
- }
- }
- })
- input.onButtonPressed(Button.AB, () => {
- if (isMovingVertically == true && sweepTime == 5000) {
- if (movingOpposite == true) {
- player.goTo(playerX, 0)
- } else {
- player.goTo(playerX, 4)
- }
- } else if (sweepTime == 5000) {
- if (movingOpposite == true) {
- player.goTo(4, playerY)
- } else {
- player.goTo(0, playerY)
- }
- }
- })
- basic.forever(() => {
- if (player.isTouching(collectable)) {
- game.addScore(1)
- collectable.goTo(randint(0, 4), randint(0, 4))
- music.playTone(Note.FSharp5, 100);
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement