|Written by Mike James|
|Tuesday, 16 February 2016|
Page 1 of 3
The Micro:bit is quite a capable computer but it does have one limitation - it only has a 5x5 LED matrix display. What sort of game could you possibly program on that?!
In this project we resurrect a classic BBC Micro game on the BBC micro:bit. Games have always been a great way to get into programming and the micro:bit is no different.
Back in the days of the BBC Micro I was involved the development of a game called Commando Jump that was included in the book 21 Games for the BBC Micro. It was, by design, a very simple game intended to teach BBC Basic programming. It presented the player with a wall that the commando had to climb. The initial jump height was determined by the player's reaction time. After that they could make the commando scramble up the wall by pressing a key as fast as they could. The faster, the higher the commando climbed. If you reached the top of the wall before that time out then at the next level there was a higher wall. If you didn't make it the commando would slide down with a deflated noise.
A 5x5 LED display is just enough to implement this game. Not in all its many-colored glory but we can reproduce some of the original game play - and the temptation of re-implementing a game from the BBC Micro days on the BBC Micro:bit days was too good to miss!
All you do is enter the program into the editor, click the download icon and then copy the download onto the Micro:bit usb drive. When you connect the Micro:bit to your desktop computer it installs itself as a USB drive - this is the only communication the PC needs with the Micro:bit as any program copied there is immediately loaded and run.
Of you can just run the program in the emulator included at the rigth of the editor.
Blocks For The Programmer
My advice when you are assembling a complicated set of blocks - a for loop say - is to not try to put it into the whole program until you have assembled it. Use another area of the editor as an assembly area and when you have the block complete move it into place.
Finally pay special attention to where you place one block within another - you can easily misplace one and discover that your code isn't within the for loop or if statement in which you wanted it.
It does support functions so you can use modular programming, but I couldn't make the parameters of the function work reliably. While you can put a return into a function there is no faciltiy to put a return value.
What this means is that you have to create global variables to get data into and out of a function. This is not good news because this style of programming has long been known to be bad for anything but very small programs. Even a program as small as Commando Jump would benifit from being able to use parameters and return values.
There are also no sprites which is a huge problem but it does rule out the approach used in the Blocks Editor and Touch Develop.
There is a fadeTo command that allows you to set an LED to a particular intensity but for various reasons it seems advisable to keep the program as simple as possible.
What a beginner is supposed to make of this is difficult to see. The solution is to re-enter the variable and hope. Sometimes reentering the variable isn't easy or even possible because the list of variables and global variables doesn't remain in sync with what has been declered.
Another interesting problem is the way that the system will occationally fail to compile a program but without providing any clue as to what is wrong. The error mesage simply says a compile error has occure not where the error lies. There also seems to be no way to remove a variable once defined and renaming a variable can produce the sort of error described above.
A final, and very strange, problem in working with complex programs in the editor is that it doesn't seem to support a horizontal scroll. If your block gets so complex that it hangs over the edge screen - then you need a bigger screen.
So in this case Commando Jump is a game where a four-LED wall appears and the single-LED commando moves up one location for every ten presses of the button A. When it gets to the top, the commando sprite is animated horizontally and then down to its final position.
|Last Updated ( Saturday, 23 April 2016 )|