The micro:bit matrix (5) – tetris

I had 2 use cases for the matrix:

  1. Using the matrix as a canvas at events – letting kids create images and animations to show on the matrix.  Ex:bit is perfect for this (or will be, when adapted).
  2. Using the matrix as a screen – outputting the visuals from another app.  The 1000 micro:bit matrix had been used for Space Invaders and it looks good, so the bar is set quite high!

My hope was that I could use the same node code for both use cases, and the code discussed in chapter 3 already ticked off the first use case.

To test the second use case I set out to build a version of Tetris.

This was one of my most fun projects with Python, and I remember fondly the lengths I went to to squeeze it all onto 1 micro:bit.  Many sessions were sent shaving a fraction of memory use off to allow me to add new functionality.   The current version only has 5 different block shapes. due to memory constraints, and is missing an element of collision detection for the same reason!

Obviously the micro:bit screen is just not an option for Tetris, and I did not actually have a matrix assembled to test it on.  So, I decided to use REPL to test the output – each new ‘screen’ would be output to REPL as a print.  I had to call it ‘reptris’:

Above: As the shape descends it is represented by the number 7 – zeroes are shown to represent empty spaces on the grid.

Above: As the shapes come to rest at the bottom they are represented by “1”

I didn’t plan to release reptris (although I did – its here on GitHub) – the idea was to adapt it to run over the matrix.  I just couldn’t resist releasing it though, because:

  • It was so bad it was, well, very bad.  But in a good way – using REPL to output each frame – heh!
  • It was tetris, on a micro:bit, written in Python.  Don’t knock it till you’ve tried it!
  • During the process of developing it I realised that it could not work on the same node code as Use Case 1 – I would need to adapt the code specifically for Tetris.  I chose to focus on the first use case, then maybe revisit Tetris at a later time.

So, after a bit of a diversion it was back to the matrix…

Next: The micro:bit matrix (6) – structure

The micro:bit matrix saga currently consists of 6 chapters:

Leave a Reply

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