Steady hand game advanced
{% trans 'Sorry, your browser does not support canvas -- please either update your browser or submit your requirements by phone or email.' %}


Loading Blockly...

Step 1 /8


You have been provided with a version of the previous code. You will now learn how to finish the code to detect the start and finish positions of the course.

First setup the emulator.

Click on the cog at the top right of CodeBug.

Tick the Show leg controls box.

Click Apply button.

The emulator will show the status of CodeBug’s legs with blue arrows. An arrow pointing towards the leg is an input, away from the leg is an output.

Step 2 /8

Game over until reset

We need to continuously scroll the Game over message when the game is lost.

From the Loops menu take a repeat while true block and snap it inside your if block.

Now drag your scroll sprite block, that scrolls your Game over message, and snap it into this new repeat while true block.

Step 3 /8

Reset the game

We now want to let the player reset the game if they have lost by touching the wand to the reset croc-clip at the start of the course.

Click on the true block of your new repeat while true loop and drag and drop it into the the waste bin at the top right of the workspace, or just press the Delete key.

From the Logic menu drag in a not block and snap it to your if block.

From the Inputs/Outputs menu drag a leg grounded block and snap it to your not block. Click the block’s drop down menu to change the leg to 3.

This means the message will loop until leg 3 is connected to GND.

Step 4 /8

Configure leg

To sense the reset, we need to configure CodeBug’s leg 3 to be an input.

Click the cog on your start block.

In the window that appears, tick the checkbox next to leg 3 input/output.

Click the cog again to close the window.

Step 5 /8

Set to input

We want to set leg 3 to a digital input.

Select the drop down menu next to “leg 3 as” on your start block, and select digital input.

Step 6 /8

Testing the code so far

It is always good to regularly test your code so the cause of errors are clearer and easier to debug.

Download your program so far onto CodeBug, or test it on the emulator.

Test that:

Game over continuously scrolls when the wand touches the course.

The Game over text stops scrolling when the wand touches the reset croc-clip.

And that Game over continuously scrolls again when the wand touches the course.

When testing that Game over scrolls when the wand touches the course, we did this twice because the conditions we different for each check. The first test is when the game first starts, the second is when the game has been reset.

Step 7 /8

Looking for Winners

We should now check whether the winning croc-clip at the end of the wavy course has been touched.

Click on your if block on your workspace (the one that says leg 1 grounded).

Press the keyboard keys Ctrl C and then Ctrl V. (cmd instead of Ctrl on Apple).

This will copy and paste this if block and all the code inside it.

Drag and snap this new if block below the if block you just copied it from.

Change the number of the leg grounded block in your new if block to 2.

Tick the leg 2 input/output checkbox of your start block configuration and set it to a digital input.

Change the Game over text of your new if block to Winner.

When the wand touches the finish line croc-clip (if the game is not over), this code will continuously scroll Winner, until reset by touching the wand to the reset croc-clip.

Step 8 /8

Download to CodeBug

Download your program to CodeBug and test your code. Get a friend to play to see if any errors occur (this is called beta testing).