Hardware Reference
In-Depth Information
6. Click on the Sensing blocks palette and select the key space pressed block.
Place it into the hexagonal space on the forever if control block. Once you
have placed this block you will need to change space to a or the letter of the
key to which you assigned your marshmallow button-press in the previous part
of this project.
7. Add the variable block change counter by 1 inside the forever if block,
followed by the sound block play drum 48 for 0.2 beats . Change the
drum to 76 using the drop-down menu.
8. When the game begins, the counter will need to be reset to 0 to record the play-
er's score. Add another when clicked control block to the Scripts tab and
connect a set counter to 0 variable block to it.
9. Remember to save the work you have done so far by clicking File Save. hen
test that your game script written so far works, by clicking the icon and
using your marshmallow button to check if the counter records how many times
it is pressed. Don't forget that the Python script you created for the button
needs to be running too!
10. To give the player a time limit, you will need to add two more scripts. Add
another when clicked control block to the Scripts tab and connect the
sensing block reset timer to it. Underneath, connect a forever looping
control block, and a set timer to 0 variable block inside it. (You may need to
select Timer from the Variable block drop-down menu.)
Next click on the Operators blocks palette and select the round block. Place it
inside the set timer variable block where the value 0 is. hen add the sensing
block timer inside the empty space of the round operator block you just
placed.
his completed variable block should now read: set timer to round timer .
his script will reset the timer at the start of the game to 0, and then count
upwards every second.
11. he inal script will set the time limit for the game. Add a when clicked
control block to the Scripts tab, and connect a wait until control block to it,
followed by a stop all control block.
Drag the operators block _ = _ (equal to) and place it inside the wait until
hexagon space. In the left-hand space before the = sign, add the variable block
timer and on the right-hand side type the value 10 .
his script will wait until the timer reaches 10 seconds before stopping the game.
12. Finally, save your game by clicking File Save. hen test that your scripts work
by clicking the icon and using your marshmallow button to check whether
the counter records how many times it is pressed, and the timer counts up to 10
before stopping the game.
Search WWH ::




Custom Search