BBC microbit games
Published: 17 Jul 2016
My first game programmed for the BBC Microbit with Anthony Finch.
CLICK BATTLE
Two players, one button each. When the arrow points to your button click it as fast as possible repeatedly until it points to your opponent. If you click when the arrow points away from your button you lose points. Most points wins!
Here is the full python code that can be used with the BBC microbit python editor to compile and play.
# Add your Python code here. E.g.
from microbit import *
import random
aCount = 0
bCount = 0
maxGameTime = 30000
# 0 is player a 1 player b
currentPlayer = 0
# a and b player screen
aImage = Image()
aImage = Image('00900:09000:90000:09000:00900:')
bImage = Image()
bImage = Image('00900:00090:00009:00090:00900:')
# a and b click player screen
aClickImage = Image()
aClickImage = Image('99900:99000:90000:99000:99900:')
bClickImage = Image()
bClickImage = Image('00999:00099:00009:00099:00999:')
# display get reay on screen
display.scroll('GET READY')
# delay saying Go!
sleep(500)
# display Go! on screen
display.scroll('GO!')
while True:
while running_time() < maxGameTime:
delay = random.randrange(1000,5000)
while delay > 0:
display.show(aImage)
if button_a.is_pressed():
aCount = aCount + 1
display.show(aClickImage)
if button_b.is_pressed():
bCount = bCount - 1
delay = delay - 1
delay = random.randrange(1000,5000)
while delay > 0:
display.show(bImage)
if button_b.is_pressed():
bCount = bCount + 1
display.show(bClickImage)
if button_a.is_pressed():
aCount = aCount - 1
delay = delay - 1
display.clear()
if aCount > bCount:
display.scroll("PLAYER 1 WINS!")
else:
display.scroll("PLAYER 2 WINS!")
# display.get_pixel(x, y, val)
Referrences:
Next experiment: javascript automata