The aim of this object is to give similar functionality to the joypad buttons as is available to
microbit.button_a
and microbit.button_b
. It also facilitates asynchronous vibration (no pause when vibrating).
This is acheived via method GAMEZIP.sleep
, you must not use
microbit.sleep
. If there are no sleeps in your program you must make
regular calls to GAMEZIP.sleep(0)
. GAMEZIP.sleep
polls the keys on the joypad and stops any vibration, if the duration has not
expired it sleeps for 50 micro seconds and loops.
The
GAMEZIP
object is made up of 6 KEY
objects:GAMEZIP.button_up
GAMEZIP.button_down
GAMEZIP.button_left
GAMEZIP.button_right
GAMEZIP.button_1
GAMEZIP.button_2
Keys have the following methods:
method | type | |
.is_pressed() | boolean | returns True if the button is pressed. |
.was_pressed() | boolean | returns True if the key has been pressed since reset or the last call to this method. |
GAMEZIP
has the following methods:method | |
.plot(x, y, color) | sets the LED at coordinates x, y to the color specified by a list or tuple in RGB format |
.clear_screen() | blanks all LED's, it's ususal to do this before plotting a new screen |
.show_screen() | updates the screen with the current plotted values. It's not enough just to plot your screen yon need to show it |
.play_tune(tune, wait = False) | plays the tune supplied such as music.ENTERTAINER . If wait is True this method will block until the tune has completed. |
.vibrate(duration, wait = False) | this method makes the joypad vibrate. If wait is True this method will block for the specified number of milli seconds. |
.reset_clock | this method starts or resets the clock to 0. |
.time | this method returns the number of elapsed seconds since the clock was last reset. This is an aproximate clock it may be a second or two slow. |
.sleep(duration) | this method scans the keys and stops asynchronous vibration whilst it sleeps for the given number of milli seconds. It is crucial to make regular calls to this method to give a good keypad response. |
To use a game you need to flash the microbit with
uflash
or copy
a microbit.hex
file over then use microFS to transfer the module
gamezip.py
and the program to become main.py
as in the
following example.
ufs put gamezip.py
ufs put battle-ships.py main.py
a demo of using the module
gamezip.py
. Move the sprite around the
screen using the arrow keys and change it's colour with the fire buttons.
Move the cursor left and right to select a primary colour, increase and decrease it's intensity with up and down. Reveal, the tuple to define the colour with either fire button, uses
gamezip.py
Turn your gamezip into a juke box, use up and down to change the tune. Uses
gamezip.py
A 2 player game for the gamezip and microbit version 2, you'll need two of each . Position your boats using the arrow buttons, rotate them with fire button 1, fix them with fire button one. When bombing your opponent the arrow keys move the bomb and fire button 2 drops it. Uses
gamezip.py
.
Use the arrow keys to guide snake around a massive room eating food, growing a longer and longer tail. Use the map on the microbit to find your next food. Snake is the bright dot, food the faint ones. Be warned food goes bad and turns to poison and the perimeter wall is made of stone. Avoid your tail and avoid stones, avoid poison, eat food. This is for version 2 microbits and uses
gamezip.py
.
Two weeks now has it's own repository at https://github.com/rhubarbdog/microbit-two-weeks