Commando Jump Game For The Micro:bit In JavaScript |
Written by Mike James | ||||
Tuesday, 16 February 2016 | ||||
Page 3 of 3
Endgame handlingWhile 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 ListingRather than give a complete block form of the program, it seems more useful to give the JavaScript version. If you want to you can copy and paste this into the JavaScript editor and switch to block view to see a complete block representation. The complete program is:
More InformationRelated ArticlesCommando Jump Game For The Micro:bit In Python Micro:bit Commando Jump In The Microsoft Block Editor Commando Jump Game For The Micro:bit In Touch Develop Getting Started With C/C++ On The Micro:bit Offline C/C++ Development With The Micro:bit BBC Micro:Bit Finally Ships to 1 Million For Free BBC micro:bit Your Next Computer? BBC Giving Away 1 Million Microcomputers Teach Code In School - Before It's Too Late! Four Generations - Video of BBC Micro
Comments
or email your comment to: comments@i-programmer.info
|
||||
Last Updated ( Saturday, 23 April 2016 ) |