Micro:bit Commando Jump Using MakeCode
Written by Sue Gee   
Monday, 09 April 2018
Article Index
Micro:bit Commando Jump Using MakeCode
Programming with MakeCode
playGame
Conclusion and Listing

Conclusion

There are plenty of opportunities for improving the game - put the play code inside another loop so that the player can have multiple goes, add some sound, add a scoring system that take time into account, and so on.

All of these improvements are possible, but without subroutines or functions the size of the block program gets bigger and bigger and eventually so big it is unwieldy. 

What does this game implementation tell us about the MakeCode Block Editor? The verdict has to be that it is really only suitable for smallish programs. The problem is that the code that it produces is Microsoft's TypeScript, which isn't quite JavaScript and clearly has a Microsoft bias. There is also the problem that the code isn't the simplest you can imagine for presenting to a beginner. Comparing it with microPython you have to admit that it might not be much harder to introduce the beginner to this Python dialect. It is surprising that, after so much time, we are still presenting teaching languages to complete beginners that are not easy to use.

The Listing

Rather 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:

let run = false
let t = 0
let man: game.LedSprite = null
let wall: game.LedSprite = null
let press = 0
let index = 0
function startGame() {
    countDown()
    drawPlayArea()
}
function countDown() {
    for (let index2 = 0; index2 <= 4; index2++) {
        basic.showNumber(5 - index2)
    }
    basic.showString("!")
    basic.pause(1000)
    basic.showString(" ")
}
function drawPlayArea() {
    for (let index3 = 0; index3 <= 4; index3++) {
        wall = game.createSprite(2, index3 + 1)
    }
}
function playGame() {
    press = 0
    man = game.createSprite(4, 4)
    t = input.runningTime()
    run = true
    while (input.runningTime() - t < 20000 && run) {
        moveMan()
        if (man.get(LedSpriteProperty.Y) == 0) {
            run = false
        }
    }
}
function moveMan() {
    if (press > 20) {
        man.change(LedSpriteProperty.Y, -1)
        press = 0
    }
}
function endGame() {
    if (!(run)) {
        moveHorizontal()
        game.addScore(1)
    }
    moveVertical()
    game.gameOver()
}
function moveHorizontal() {
    for (let index = 0; index <= 4; index++) {
        basic.pause(400)
        man.change(LedSpriteProperty.X, -1)
    }
}
function moveVertical() {
    for (let index = 0; index <= 4; index++) {
        basic.pause(400)
        man.change(LedSpriteProperty.Y, 1)
    }
}
input.onButtonPressed(Button.A, () => {
    press += 1
})
startGame()
playGame()
endGame()

More Information

https://www.microbit.co.uk/

Related Articles

Commando 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! 

UK Micros of the 1980s 

Four Generations - Video of BBC Micro 

 


Disk Drive Dangers - SMART and WMI

Getting access from an application to the hardware is never easy. If you want to know how well your disk drive is performing then there is a way of accessing the SMART data - including the temper [ ... ]



SNTP Time Class

SNTP is a network protocol for obtaining an accurate time and it is an interesting exercise to build an SNTP client. In this article the language used is C# but it is easy enough to generalise to a la [ ... ]


Other Projects


Firefox 1.0 Released 20 Years Ago
10/11/2024

A news item with the headline "Firefox browser takes on Microsoft" from 20 years ago has attracted renewed attention. It was originally published on the BBC News website on November 9th, 2004 rec [ ... ]



Rust 1.82 Improves Apple Support
24/10/2024

Following Rust's six-week release cycle, version 1.82 has been released with higher level support for Apple, and a new Info subcommand for Cargo.


More News

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

espbook

 

Comments




or email your comment to: comments@i-programmer.info

<ASIN:1871962455>



Last Updated ( Friday, 18 May 2018 )