event = pygame.event.poll()
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            center = event.pos
            joy = event.pos
            down = True
        elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
            down = False
            joy = width / 2, height / 2
            center = width / 2, height / 2
        elif event.type == pygame.MOUSEMOTION and down:
            joy = event.pos

        if down:
            #Normilize joystick commands
            x = (joy[0] - width / 2.0) / radius
            y = -(joy[1] - height / 2.0) / radius

        else:  #decay the values after stick release
            if time.time() - last_decay > .1:
                x = x * DECAY
                y = y * DECAY
                last_decay = time.time()

        draw_joystick(center, joy, radius)
        sd.move(x=x, y=y, z=0)

finally:
    sd.release()
        event = pygame.event.poll()
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            center = event.pos
            joy = event.pos
            down = True
        elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
            down = False
            joy = width / 2, height / 2
            center = width / 2, height / 2
        elif event.type == pygame.MOUSEMOTION and down:
            joy = event.pos

        if down:
            #Normilize joystick commands
            x = (joy[0] - width / 2.0) / radius
            y = -(joy[1] - height / 2.0) / radius

        else:  #decay the values after stick release
            if time.time() - last_decay > .1:
                x = x * DECAY
                y = y * DECAY
                last_decay = time.time()

        draw_joystick(center, joy, radius)
        dd.move(x=x, y=y, z=0)

finally:
    dd.release()
示例#3
0
        event = pygame.event.poll()
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            center = event.pos
            joy = event.pos
            down = True
        elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
            down = False
            joy = width/2,height/2
            center = width/2,height/2
        elif event.type == pygame.MOUSEMOTION and down:
            joy =  event.pos

        if down:
            #Normilize joystick commands
            x = (joy[0] - width/2.0) / radius
            y = -(joy[1] - height/2.0) / radius

        else: #decay the values after stick release
            if time.time() - last_decay > .1:
                x = x*DECAY
                y = y*DECAY
                last_decay = time.time()

        draw_joystick(center,joy,radius)
        dd.move(x=x,y=y,z=0)

finally:
    dd.release()