## Introduction: How to Make Microbit Game

Hi, my name is Mohammed and in this instructable, I'm going to show you how to code a micro bit game step by step with block editor the game is a bit like Tetris.

## Supplies

A computer and a micro bit set

## Step 1: BUTTON A

First, you start by going to the "input category" and selecting the "On button A press".

## Step 2: BUTTON a STEP 2

Next, go to the category "logic" and select "if true then". Next put, "if true then" inside, "on button A press". then go to the category "logic" and scroll down to comparison. pick the first one you see (0 = 0). then put (0 = 0) inside the true in "if true then".

## Step 3: BUTTON a STEP 3

After you are done. Go to "variables" and make a variable (i recommend you to make poz for your variable. which means position). put that variable into the left number of "if true then" and make it so that the variable is greater than the other number (set the right number to 0).

## Step 4: BUTTON a STEP 4

then go to the category "LED" and choose "unplot x y" and put it under "if true then".

## Step 5: BUTTON STEP 5

After your done with that go to "variables" and choose the variable poz (or whatever u picked for the previous one) and put that variable in the left slot (x). Then change the right one to 4 (y).

## Step 6: BUTTON STEP 6

When you are done with that go to "variables" and choose. "change variable (poz) by number" put "change variable (poz) by number" under "unplot x y". set the number to -1 and the variable box to whatever you chose for "unplot x y" (poz).

## Step 7: BUTTON STEP 7

Next, go to the category "LED" and choose "plot x y". put "plot x y" under "change variable by number". for x go to variables and choose the variable for the previous step (poz) and for y set it to 4.

## Step 8: BUTTON B

Now that you are done with BUTTON A. right-click BUTTON A (what you did for the previous steps) and duplicate BUTTON A.

## Step 9: BUTTON B STEP 2

After you have duplicated BUTTON A. change ON BUTTON A PRESS to ON BUTTON B PRESS.

## Step 10: BUTTON B STEP 3

next, change the number in "if true then" to 4, the "unplot x y" number to 4, the "change variable by a number" number to 1 and the "plot x y" number to 4.

## Step 11: BUTTON B STEP 4

if you have followed the previous steps correctly you should be done with BUTTON B.

## Step 12: ON START

now that you are done with BUTTON B, let us start with ON START. first, go to "basic" and choose "ON START", next go to the category "variables" and choose "set variable to a number" and put "set variable to a number" inside, ON START. change the number to 2 and the variable to the one you put for BUTTON A (poz).

## Step 13: ON START STEP 2

Next, go to the category "variable" and make a new variable called score (that's what I recommend you to put). when you are done with that go to the category "variable" and choose "set variable to a number" put "set variable to a number" under the first "set variable to a number". then change the number to 0 and the variable to score for the second "set variable to a number".

## Step 14: ON START STEP 3

Next, go to the category "LED" and choose the more button. then click on "set brightness to a number" put that under the second "set variable to a number" and change the brightness to what you want but I recommend 1000.

## Step 15: ON START STEP 4

next, go to the category "LED" and choose "plot x y" put "plot x y" under "set brightness to a number". then go to variable and choose poz (or whatever you choose for your first variable) and put that variable in "x" and set "y" to 4.

## Step 16: THE MAIN GAME

Now that your done with ON START we can start with THE MAIN GAME. first go to the category "basics" and pick forever.

## Step 17: THE MAIN GAME STEP 2

Next go to the category "variables" and pick "set variable to number" put "set variable to number" inside "forever". when you are done with that go to the category "variables" again and make a new variable called empty. next go to the category called "math" and choose "pick random number to number" and put "pick random number to number" inside the number of "set variable to number". next change the numbers of "pick random number to number" to 0 for the first number and 4 for the second number.

## Step 18: THE MAIN GAME STEP 3

after you are done with that go to the category "loops" and pick "for variable from 0 to number do" put "for variable from 0 to number do" under "set variable to number". change the number to 4. next go to the category "variables" and make a new variable called "a" put "a" in the variable of "for variable from 0 to number do".

## Step 19: THE MAIN GAME STEP 4

next go to the category "loops" again and pick "for variable from 0 to number do" put "for variable from 0 to number do" inside the first "for variable from 0 to number do". change the number to 4. next go to the category "variables" and make a new variable called "ind" put "ind" in the variable of the second "for variable from 0 to number do". next go to the category "logic" and pick "if true then" put "if true then" inside the second "for variable from 0 to number do". and then go to the category "logic" and scroll down to comparison. pick the first one you see (0 = 0). then put (0 = 0) inside the true in "if true then". then for the first 0 change it to the variable "empty" and the second 0 to the variable "ind" then make the sigh in the middle of these two variables say "not equal to" (looks like an = sigh with a line down the middle). next go the category "LED" and pick "plot x y" put "plot x y" inside "if true then". change "x" to the variable "ind" and "y" to the variable "a"

## Step 20: THE MAIN GAME STEP 5

next go to the category "basic" and pick "pause (ms) number" put "pause (ms) number" under the second "for variable from 0 to number do". then go to the category "math" and pick "number minus number" put "number minus number" inside the true in "if true then". make the first number equal to 300 and put the variable "score" on the second number.

## Step 21: THE MAIN GAME STEP 6

next go to the category "loops" again and pick "for variable from 0 to number do" put "for variable from 0 to number do" under "pause (ms) number". change the number of "for variable from 0 to number do" to 4. next put "ind" in the variable of the third "for variable from 0 to number do". next go to the category "logic" and pick "if true then" put "if true then" inside the third "for variable from 0 to number do". and then go to the category "logic" and scroll down to comparison. pick the first one you see (0 = 0). then put (0 = 0) inside the true in "if true then". then for the first 0 change it to the variable "empty" and the second 0 to the variable "ind" then make the sigh in the middle of these two variables say "not equal to" (looks like an = sigh with a line down the middle). next go the category "LED" and pick "unplot x y" put "unplot x y" inside "if true then". change "x" to the variable "ind" and "y" to the variable "a"

## Step 22: THE MAIN GAME STEP 7

next go to the category "logic" and select "if true then" put " if true then" under the third "for variable from 0 to number do". then go to category "logic" and scroll down to "Boolean" and pick "blank and blank" then go to the category "logic" again and take 2 "number = to number" form the comparison section. then put each one of the "number = to number" on each side of the blanks form the "blank and blank". and then put that inside the "if true then". next for the left side "number = to number" put the variable "a" on the left number and 4 for the right number and in the middle the = sigh and for the right side "number = to number" put the variable "poz" on the left number and the variable "empty" for the right number and in the middle the not = to sigh. (if your a bit confused on how it should look like take a look at the picture)

## Step 23: THE MAIN GAME STEP 8

next (optional) go to the category "music" and pick "start melody (music) repeating (the amount of times)" put "start melody (music) repeating (the amount of times)" under the third "if true then". change the repeating amount to "once" and the music to "dadadum". next go to the category "basic" and pick "show icon" put "show icon" (make icon into a X) under the "start melody (music) repeating (the amount of times)", then go to the category "basic" again and go to "more" then pick "clear screen" put "clear screen" under "show icon". next go to the category "basic" and pick "show number 0" put "show number 0" under "clear screen". change the 0 in "show number 0" to the variable "score". next go to the category "variable" and pick "set variable to a number" put "set variable to a number" under "show number 0". then change the variable in "set variable to a number" to "score" and the number in "set variable to a number" to 0. next go to the category "variable" and pick "set variable to a number" put "set variable to a number" under the first "set variable to a number". then change the variable in the second "set variable to a number" to "poz" and the number in the second "set variable to a number" to 2. next go to the category "LED" and pick "plot x y" put "plot x y" under the second "set variable to a number". then change the "x" in "plot x y" to "poz" and the "y" in "plot x y" to 4. next go to the category basic and pick "pause (ms) number" put "pause (ms) number" under "plot x y". then change the number from "pause (ms) number" to 2000.

## Step 24: THE MAIN GAME STEP 9

next go to the category "game" form the advanced button and choose "change score by a number" put "change score by a number" in-between the first "for variable from 0 to a number" and the "forever". if you have followed these instruction correctly you should be done with the MAIN GAME (if your confused on any instructions look at the picturs).

## Step 25: BACKGROUND MUSIC (OPTIONAL)

next go to "control" which is in the advanced section and pick "run in background". then go to music and pick "start melody (music) repeating (the amount of times)" put "start melody (music) repeating (the amount of times)" inside "run in background". then make the "music" in "start melody (music) repeating (the amount of times)" whatever you want (I did funk) and the repeating in "start melody (music) repeating (the amount of times)" to "forever in background".

## Comments

2 years ago

thanks for sharing your code block tips!