This page describes an idea for a game inspired by Charlie.
The game involves moving a ship, shown on the bottom row of the matrix. The other pixel represents an asteroid/meteor that is falling towards the ship. The player controls the ship by pressing the A & B buttons and must avoid contact with the asteroid/meteor.
The block editor is not the most flexible of the code editors but is a nice place to start to get the basic idea working.
First, to make the ship and have it move left and right, we need a little bit of code like this,
Although, in most game development environments, we would need to stop the sprite moving off the edge of the screen, the micro:bit does not allow this to happen.
You can flash this script or test it in the simulator.
Now for the falling asteroids/meteors. You need to add to the loose block where you made the ship.
- To get more asteroids, you need to create more sprites at the start. Let's say you make 4 in total. You could create them on lower rows of the matrix but that does make it hard to start the game. Instead, before the while loop, create an asteroid, pause and then move it down a row. Create another, pause and move both asteroids down a row. Create a third one pause and move all three asteroids down a row. When you get to your last asteroid, start adding code to the while loop. Apart from the pause, everything else needs to be repeated for each asteroid.
- Add a simple scoring system. Add one to the score every time you move the asteroid(s) down a row. Remember to display the score when the game is over. Show score, pause, game over.
- Change the numbers in the pause to a variable that you set to 500 or 1000 at the start of the program, where you have set the ship variable. At the end of the while loop, if the score has reached a certain number, you could increase the speed.
- You can add a better start to the game with a title and some simple animation.
- Connect up a buzzer to the micro:bit and you can have some sounds in your game too.
- Consider converting your script to a Touch Develop script. You can then carry on working on it there. Touch Develop is a more fully developed programming environment. You get a lot of help when making statements and have access to more and more powerful statements.