Example #1
0
def main(skin, joy_index):
    pygame.display.init()
    pygame.joystick.init()

    joy = pygame.joystick.Joystick(joy_index)
    joy.init()
    mappings = configurator.load_mappings(skin)
    if joy.get_name() not in mappings:
        mapper.main(skin, joy_index)
    visualizer.main(skin, joy_index)
Example #2
0
def main(skin, joy_index):
    pygame.display.init()
    pygame.joystick.init()

    joy = pygame.joystick.Joystick(joy_index)
    joy.init()
    mappings = configurator.load_mappings(skin)
    if joy.get_name() not in mappings:
        mapper.main(skin, joy_index)
    visualizer.main(skin, joy_index)
Example #3
0
def play(n=3, mode='hiscore'):
    global begin
    global end
    global buzzerPx
    
    tol = 0.42
    n = 120    
    print ("It starts...")
    setScreenSize()
    print "Screen size:", screenSize
    findGame(buzzerPx[0], buzzerPx[1])
    print "Found game at:", getGamePos()
    getLineWidth()
    for i in range(n):
        if mode == 'farm':
            '''Finish level two and suicide n times'''            
            print "Starting game..."
            startGame(buzzerMenu)
            clickRatio((0.76, 0.58))
            time.sleep(0.1)
            findInit()
            print "Begin:", begin
            findTarget()
            print "End:", end
            for i in range(2):
                print "Starting level", i
                time.sleep(1)
                clickRatio((0.76, 0.58))
                time.sleep(0.2)
                print "Generating path..."
                waypoints = createWaypoints(tol, n, (n-10))
                print "Sorting waypoints..."
                waypoints = sortWaypoints(waypoints)
                print "Pruning path..."
                path = pruneWaypoints(waypoints)
                path = removeDuplicates(path)
                print "Fine-tuning path..."
                path = [(begin[0]-getGamePos()[0][0],
                         begin[1]-getGamePos()[0][1])]+path[3:-3]+[(end[0]-getGamePos()[0][0],
                         end[1]-getGamePos()[0][1])]
                path = removeDuplicates(pruneWaypoints(sortWaypoints(avgPath(path))))
                walk = [begin]
                for i in range(len(path)-1):
                    segment = interpolate(path[i], path[i+1], 1)
                    walk += segment
                walk = removeDuplicates(walk)
##                print "Plotting graph..."
##                visualizer.setData(path, tol, n,
##                                   (begin[0]-getGamePos()[0][0], begin[1]-getGamePos()[0][1]),
##                                   (end[0]-getGamePos()[0][0], end[1]-getGamePos()[0][1]),
##                                   4)
##                visualizer.main()
##                time.sleep(0.1)
                print "Traversing path.."
                clickAbs(begin)
                typeStr('cheese')
                traversePath(path[1:]+[(end[0]-getGamePos()[0][0],
                             end[1]-getGamePos()[0][1]),],
                             getGamePos()[0], False, 0.024)
                print "Level", i, "finished."
            sudicide(begin)
        
        if mode == 'hiscore':
            '''Play as hard as possible n times'''            
            print "Starting game..."
            startGame(buzzerMenu)
            clickRatio((0.76, 0.58))
            time.sleep(0.1)
            findInit()
            print "Begin:", begin
            findTarget()
            print "End:", end
            for i in range(10):
                print "Starting level", i
                time.sleep(1)
                clickRatio((0.76, 0.58))
                time.sleep(0.2)
                print "Generating path..."
                waypoints = createWaypoints(tol, n, (n-10))
                print "Sorting waypoints..."
                waypoints = sortWaypoints(waypoints)
                print "Pruning path..."
                path = pruneWaypoints(waypoints)
                path = removeDuplicates(path)
                print "Fine-tuning path..."
                path = [(begin[0]-getGamePos()[0][0],
                         begin[1]-getGamePos()[0][1])]+path[3:-3]+[(end[0]-getGamePos()[0][0],
                         end[1]-getGamePos()[0][1])]
                path = removeDuplicates(pruneWaypoints(sortWaypoints(avgPath(path))))
                walk = [begin]
                for i in range(len(path)-1):
                    segment = interpolate(path[i], path[i+1], 1)
                    walk += segment
                walk = removeDuplicates(walk)
                print "Plotting graph..."
                visualizer.setData(path, tol, n,
                                   (begin[0]-getGamePos()[0][0], begin[1]-getGamePos()[0][1]),
                                   (end[0]-getGamePos()[0][0], end[1]-getGamePos()[0][1]),
                                   4)
                visualizer.main()
                time.sleep(0.1)
                print "Traversing path.."
                clickAbs(begin)
                typeStr('cheese')
                traversePath(path[1:]+[(end[0]-getGamePos()[0][0],
                             end[1]-getGamePos()[0][1]),],
                             getGamePos()[0], False, 0.024)
                print "Level", i, "finished."