How to Make a Coin Game on micro:bit? – micro:bit Makecode Tutorial

microbit

In this tutorial we will learn how to create coin game on micro:bit. In this game, we will using two LED sprites – Coin and Catcher. The coin sprite is set to appear on the random positions. With the help of catch LED sprite, we will have to catch the coins to score the points. The catcher sprite in this game will be controlled by the accelerometer in a left-right and up-down manner.

robotics and microbit

Coin Game on micro:bit

In the following figure, you can see a LED sprite [coin] appearing at a random position and another LED sprite [catcher] is catching it. And after each successful catch, the score is increased by 1.

catch game on micro:bit

Now let us understand the steps involved in making the coin game on micro:bit.

How Do You Make a Coin Flipper Game in micro:bit?

The steps involved in making the coin flipper or coin catch game on micro:bit is explained below:

  1. Create a LED sprite [coin] at a random position
  2. Create a LED sprite [catcher] to the centre of the display.
  3. Determine the left, right, up and down tilt of Microbit.
  4. Keep score
  5. Add gameover

Microsoft MakeCode for micro:bit Login

The first step towards creating the micro:bit coin game is to login to the account. The detailed steps on how to login to micro:bit is explained below:

  • Step 1: Visit the official website of Microsoft MakeCode for micro:bit – makecode.microbit.org
  • Step 2: Click on the “New Project”. 
  • Step 3: Name your project and click on “Create”.
MakeCode for micro:bit login
  • Step 4: Now open the MakeCode UI as shown in the image given below.

Step 1: Creating a LED Sprite [Coin] at a Random Position

In this step, we are creating a coin LED sprite which will move randomly over the micro:bit display. The detailed steps on how to do this on micro:bit is explained below:

  • Click on the “Variables”, and then click on “Make a Variable”.
  • Name your variable “coin”.
  • Drag and drop the “set coin to” block.
  • And drag & drop the “create sprite at x y” block to the “set coin to” block.
  • Drag and drop the “pick random” block from math blocks and set its value from 0 to 4.
  • Set the brightness of the coin LED sprite. Drag & drop the “sprite set x to” block as shown below.
  • Click on the dropdown and select sprite to coin, x to brightness, and its value of 180.
  • Click on and you will see an LED sprite created at a random position.

Step 2: Create a LED Sprite [Catcher] to the Centre of the Display

As the next step, we are creating a LED sprite Catcher. The purpose of creating the LED sprite catcher is to display it to the centre. The detailed steps on how to do this are given below:

  • Click on the “Variables”, and then click on “Make a Variable”.
  • Name your variable “catcher.”
  • Drag and drop the “set catcher to” block and drag and drop the “create sprite at x & y” block to the “set catcher to” block.
  • Make the x and y values two and two so that the catcher sprite will be created at the centre of the micro:bit display.
  • Click on and you can see a catch LED sprite being created at the centre of the display.
  • Write a conditional statement to detect micro:bit tilt.
  • First, add a forever loop to check this condition every time.
  • Click on the “loops” and drag and drop the “while do” loop, then click on the dropdown and make it true.
  • Form the “Logic” drag and drop “if-then” block as shown below.
  • Drag & drop the greater than block to the “if-then” block as shown below.

Step 3: Determine the Left, Right, Up and Down Tilt of micro:bit

In this step, we will have to determine the left, right, up and down tilt of micro:bit. The detailed steps on how to do this are explained below:

  • Click on the “Input” and drag & drop the “acceleration (mg) x” block as shown below.
  • Make “acceleration (mg) x” greater than zero to determine the right tilt of minecraft.
  • If the microbit is tilted in the right direction, then move the catcher in the right direction.
  • Drag & drop the “sprite change x by” block and set its value to one.
  • Add a pause block as shown below.
  • Similarly, add a coding block to detect left-tilt and move the catcher left.
  • Make “acceleration (mg) x” less than zero to determine the left tilt of the minecraft.
  • Change the catch x value by a negative one.
  • Click on the “Input” and drag & drop the “acceleration (mg) x” block. Click on the dropdown and select y as shown below.
  • Make “acceleration (mg) y” greater than zero to determine the down tilt of Microbit.
  • If the microbit is tilted in the down direction, then move the catcher in the down direction.
  • Drag & drop the “sprite change x by” block, then click on the dropdown and select y, and set its value to one.
  • Add a pause block as shown below.
  • Similarly, add coding blocks to detect up-tilt and move the catcher up.
  • Make “acceleration (mg) y” less than zero to determine the up tilt of Microbit.
  • Change the catch y value to a negative value.

Step 4: Adding Score to micro:bit Catch Game

Here we will be determining the collision between coin and the catcher sprite. Using conditional statement we will determine whether the coin touched the catcher sprite or not. The detailed steps on how to add score to the micro:bit catch game is explained below.

  • Drag and drop the “if-then” block, and drag and drop the “is sprite touching” block, then click on the sprite and select “catcher” to the “if-then” block as shown below.
  • Click on the variables and drag and drop the catcher sprite to the “is sprite touching” block.
  • If the condition is true, drag and drop the “change score by” block.
  • And move the coin sprite at a random position. Drag & drop the “sprite set x to” block and set its value to random (from 0 to 4).
  • Drag & drop the “sprite set x to” block and click on the dropdown menu and select y.
  • Set its value at random (from 0 to 4).

Step 5: Adding Game Over

  • Add game over to do this and add the count down.
  • Drag & drop the “start countdown (ms)” block at the game’s start and set its value to 15,000.
  • Click on and tilt your micro:bit left-right, up-down to catch the coin.

Congratulations, You have completed the Coin game on micro:bit.

Coin Game in micro:bit Code

Wiingy Robotic Classes

Wiingy offers a complete beginner-friendly micro:bit coding course for children, which helps children to learn coding and robotics through fun projects. Each lesson of the Wiingy Robotic course will focus on teaching key ideas through the construction of enjoyable projects, robots, and experiments. Parents can also schedule a free demo class with the help of which they can understand how robotic classes will be taught to children.

robotics and microbit

We, at Wiingy, offer robotics classes for kids from Grade 1 to Grade 8 based on the BBC micro:bit. Robotics is the design, manufacturing, and usage of machines to duplicate or replicate the behaviours of human beings. Our online robotics programmes provide children with inquisitive minds with a learning tool to inspire creativity and encourage them to think beyond the box. Your child will learn how to programme, design, and construct their very own robots in our robotics classes with the help of the appropriate direction and encouragement.

Leave a Comment

Your email address will not be published.

Subscribe to our Blog today

SUBSCRIBE TO OUR BLOG NOW

You will receive regular updates on tutorials, articles, news and content on Science, Technology, Engineering and Mathematics.

 We’re committed to your privacy. Wiingy uses the information you provide to us to contact you about our relevant content, products, and services. You may unsubscribe from these communications at any time.