Starting With MicroBit

What its Microbit?

Microbit is an intermediate programming language that helps to develop Java through Blocks. And experiment with the device both virtually and physically.

Cach the ball

Today we have been doing different tutorials, to better understand how programming languages work at a more basic level.

Simple Animation

Researching with my partner we saw that there was also the possibility of programming with python. https://python.microbit.org/

But nothing here about Blocks, Just Coding and Export.

But if I have seen that there is much more documentation in some aspects

Stay On!(Balance) MicroBit

After doing several tutorials and a little curiosity how this small machine worked. I decided to try to make a game on my own using only the Acelorometer as Input.

The Game mechanics its simple

  1. If Player stay on the mid Led, you add Point To your Score.
  2. If Player stay arround but not in walls nothing happens. (still alive).
  3. If Player collision with walls lose Lives.

Getting Started

I’ve started initializing my variables. Score to 0 which is the player’s initial score, I set the position of the Sprite to X:2 Y:3. I have decided to put it in this position and not in the middle so that the player does not start picking up points and has to move from the beginning.

Index

And to finish the beginning of the game I set the Game variable as true and the Equilibrium variable to 10 that count how many time the sprite colision with walls.

Now let’s go with the Block forever. I’ve decided to put it all inside a While.
That later I will talk about how to balance the rest of the points.
So in the While, I create a Variable called XMov, to move my sprite by X and call the acceleration input (mg) of X.

Reading the Documentation I saw that this input (acceleration (mg)) returns a range of +/-2000.

Then I check if XMov is -50, if it is the case I change the direction of Sprite from X to -1 and so I get the sprite to move to the left.
and pause so the game doesn’t go so fast.

I repeat the same previous action but this time I check if it is over 50 and change X sprite by 1 to go to the right. I decided to put 50 because if I put it lower the sensivity was too high and could not be controlled.

We also repeated the same action for Y.

Move sprite on X
Move Sprite on Y

And now that we have the movement of the sprite we will check when we want to increase the score or remove balance. I have done it with Several if. the First check if the Sprite is in the coordinates 2.2. If so, add Score, Score +3 (I like the number 3) and put a happy Sprite.

If not, I paused the game a little bit so that the player if he leaves the wall quickly does not lose life. And then I check if Sprite is at X=0, or Y=4, or X=4 or Y=0. If any of the above if true it means that the sprite is touching the wall therefore to the balance variable the rest -1, and I put the fail icon.

If equilibrium reaches 0 it exits While, erases the screen, and then shows the string “Score” and the Variable Score.

Reset Game

ahh I also set the A+B entry to Reset the game.

This would be the beginning, after here you could add more levels of difficulty the longer you are without dying. changing the sensivity.

My first contact with something more structured made in microbit, has been a small challenge, I have encountered difficulties in how to manage the walls but in the end I managed to make it work after several tests and calibrations.

Leave a Reply

Your email address will not be published. Required fields are marked *