コード例 #1
0
def setup():
    global ducks, NUMDUCKS, numNotHidden, reticule, timer, PLAY_TIME
    global player_tuple, gameOn, timer_started, myPort

    if not MOUSE_INPUT:
        print "Select serial port of accelerometer gun"
        for i, port in enumerate(Serial.list()):
            print "[%d] %s" % (i, port)
        print ">> ",
        whichPort = int(raw_input().strip())
        myPort = Serial(this, Serial.list()[whichPort], 9600)
        myPort.bufferUntil(ord('\n'))

    print "Place NFC tag on reader."
    print "Press [ENTER] to continue..."
    raw_input()
    (status, player_tuple) = get_player()
    if status != 0:
        print "Error getting player."
        exit()
    elif player_tuple == None:
        print "New player!"
        #player_tuple = (0,0,0)
    else:
        print "Player found."
        print "Total: %d; High: %d" % (player_tuple[1], player_tuple[2])

    size(1400, 800)
    timer_started = False  # Hack to get timer to restart on first frame
    timer = Timer(10, 60, PLAY_TIME)
    timer.start()
    for i in range(NUMDUCKS):
        ducks.append(Duck(int(random(150, 1200)), 500))
    # print "DUCKS"
    # for duck in ducks:
    #     print duck
    #     print duck.x
    #     print duck.y
    #     print duck.dx
    #     print duck.dy
    reticule = Reticule(MOUSE_INPUT)
    gameOn = True
コード例 #2
0
 def __init__(self):
     """Initialise the micro:bit, would be good to find it automatically."""
     portName = Serial.list()[len(Serial.list()) - 1]
     port = Serial(this, portName, 115200)
     port.bufferUntil(10)
     self.port = port
     self.state = {'a': False, 'b': False}
     self.data = {
         'name': u'None',
         'accelerometer': PVector(0, 0, -64),
         'button_a': {
             'pressed': False,
             'down': False,
             'up': False
         },
         'button_b': {
             'pressed': False,
             'down': False,
             'up': False
         }
     }