Microbit tetris in python

microbit Tetris in python

I’ve finally got round to updating the online microbit python simulator in create.withcode.uk to catch up with some of the amazing new micropython features (such as speech and radio).

To celebrate, here are three different versions of the classic game tetris that you can simulate online in a virtual microbit or download to your device and play.

Microbit tetris in python
microbit tetris in python

First version

The first two tetris games weren’t made by me: the first was made by VivianePons and donated into the public domain after making it at PyCon2016.

It uses the microbit’s accelerometer to sense how much you tilt the device in order to move the blocks left and right. You can play it in the simulator by clicking on the accelerometer tab and changing the X slider left and right.

Second version

The second version of tetris comes from the excellent tutorial at 101 Computing. It uses buttons A and B to move the blocks and you get different shapes that you can rotate by pressing both buttons rather than a single dot:

Which version do you prefer? Can you combine the best bits of both programs? I think it’d be great it you could use the accelerometer like the first version but have the more complex blocks that you can rotate like the second one. Perhaps button A would rotate counter clockwise and button B clockwise. Post a comment with a link to your code if you’re able to improve on either of these projects and thanks to the original authors for sharing their code online.

 

Update 28/3/2017:

It seems that the second version doesn’t work any more with the current version of micropython for a micro:bit.

Please see below for a version of Tetris I’ve put together that works on both the simulator and an actual device.

There are four different types of blocks that fall down. You can move them by pressing A or B or rotate them by tilting the microbit left or right.

Have fun!

Create with code

Create.withcode.uk online python editor is now open source!

Create.withcode.uk is an online python editor that allows you to write, run, debug and share python code in your web browser. It launched in April 2016 to help students learn to write code on any device without having to install any specialist software.

Create.withcode.uk
Create.withcode.uk

In June 2016 I added a BBC microbit simulator to make it easier for my students to write, debug and share python code for a BBC micro:bit. Since then, I’ve been approached by a number of different people to see if they can adapt or extend some of the features on this site. All of the resources on this site are published under the Creative Commons share-alike license which means you’re free to use anything here for whatever purpose as long as you reference me as the original author. Up until now though, whilst create.withcode.uk has been free to use, the source code that makes it work hasn’t been openly available. I’m really grateful to those of you who have got in touch to request a feature or report a bug but I’ve been really impressed with the response to the site from people who have ideas of how to make it even better.

I’m pleased to announce that create.withcode.uk is now open-source. This means that if you can think of a way to improve the python editor or you spot a bug that needs fixing, you don’t have to wait for me to code it: you can jump right in and adapt / extend / improve it however you like. You’re free to use it for your own projects – I’d love to hear from you if you find a use for it.

You can find the source code for create.withcode.uk here.

If I had the time, I’d love to extend or adapt create.withcode.uk for the following:

  • self marking python tests that integrate with moodle
  • create 3d games and objects using python
  • interactive competitive python quizzes that integrate with moodle

The possibilities are endless (but time is very limited!) so hopefully going open source will allow someone to get creative and innovative without me holding them back!

 

 

Doodle jump python game for micro:bit

Doodle jump: microbit python game tutorial

This tutorial will talk you through how to write, test, debug and improve the python code for a doodle jump style game on a BBC micro:bit.

Challenging
Warning: this isn’t easy

This microbit python game tutorial is possibly a little too advanced for beginners so have a look at some of the other tutorials if you’re just getting started or jump straight in here if you’re feeling confident.

Doodle jump is a brilliantly simple but infuriatingly addictive game where you have to control a green alien by moving it left and right to jump up to the next platform, as the world falls away beneath it. The original game won an Apple design award and it quickly took the gaming world by storm. You can play it here (it’s likely to be blocked if you’re viewing this tutorial page in school). The challenge of this tutorial is to attempt to scale down the game so it still works on a 5×5 LED screen on the BBC micro:bit whilst still being fun to play.

 

Try it with code
Try the code

Below is a sample of the doodle jump game that we’ll create using this tutorial.

Press Ctrl + Enter to run the code, or click on the run button that appears when you click on the {+} button in the bottom right corner of the code editor.

Press button A to move left and button B to move right.

If you want to test the game on an actual micro:bit, plug it into your computer, run the code and click on Download HEX and save that file onto your micro:bit.