|Written by Mike James|
|Tuesday, 16 February 2016|
Page 3 of 3
While the playGame function is complicated, the end game handling can be as complicated as you like. You could add a scoreboard, a best score, a play again, etc. For simplicity all we are going to do in the endGame function is to animate a final sequence depending on whether or not the commando got over the wall.
If the commando did get to the top of the wall within the time limit then an animation that moves the block horizontally and then down the "screen" is performed.
If it didn't make it, then the commando block simply falls back down.
If position==0 then the commando is over the wall and we call an animation function to move the LED to the far left. If the commando has or hasn't made it then the moveVertical function is used to drop the commando down from its current position to its final position.
The horizontal move is easy:
All we need is a for loop that flashes the LED on and off from 0,4 to 0,0.
The vertical move is almost as easy but we have to remember to drop the commando from what ever y position he is at back to y=4.
The commando starts at x,position and moves down to x,4.
That's it - game over.
You can now play commando jump on the BBC micro:bit.
What could you do next?
Add some sound as the commando struggles to get up the wall and falls back down or gets over.
Alter the difficulty level if the player wins and start the game again.
The complete program is:
or email your comment to: email@example.com
|Last Updated ( Saturday, 23 April 2016 )|