Another little project I wanted to do now that we had the OLED screen working correctly was to try and see if I could replicate this simple game that was put together by Giles Booth:
A detailed walkthough of how he did it is available on his blog – http://www.suppertime.co.uk/blogmywiki/2019/11/python-game-microbit-oled/
I decided to give this a try as it built on what I had just learnt with the OLED screen. It is also a step up in complexity as it requires the use of the Online Python editor for Micro:bit
This, taken from Giles’ post, explains how the program works.
“The program works by creating ‘stamps’ – like crude sprites – for 3 hazards (a duck, a ghost and a tortoise), all using graphics from the micro:bit’s own built-in 5×5 icons. This is a neat touch that avoids having to create your own bitmap graphics.
You move left and right using A and B buttons, and press A+B together to move forward – you can’t move backwards! When you reach the top you level up, complete 10 levels to win.”
Below is a video of my successful attempt and making the player move left and right.
The .HEX code can be found here: https://drive.google.com/file/d/1b902lEgcvfVLE45FJxXXMUUQpvnKYVbn/view?usp=sharing
I found that with the 3 obstacles moving at the same speed it was easy to complete the game. I decided to try editing the code to make the speeds different for the ‘ghost’ obstacle.
This is the part of the code that controls the movement of the obstacles. When the play is ‘alive’ the obstacles move 1 pixel every 300ms (interval rate not pictured) left or right depending on their position relative to pixels 58 and 3 :
As changing the interval rate would have made all 3 obstacles quicker tried adjusting the number of pixels the ‘ghost’ moved from 1 to 3:
As you can see in the below video, this had the desired effect of the ghost moving quicker but thew up new issues:
- one issue is that the ghost doesn’t start moving by 3 pixels until it reaches either position 3 or 58. This must mean there is an initial speed that is elsewhere in the code.
- Second, the ‘ghost’ leaves a kind of trail across the screen – this may be to do with the rate that the screen is refreshing. I was unable to determine whether the rate is programmed into the OLED at production or that something there is something in the python code controlling it.
I’ve not been able to resolve this issue but I have contacted Giles to see if he knows what the problem is.
The modified ‘speedy ghost’ version .HEX file can be found here: https://drive.google.com/file/d/1b902lEgcvfVLE45FJxXXMUUQpvnKYVbn/view?usp=sharing