def clickOnFirstBlock(screen): global gameCoords, score, previousLane for y_ in range(5, len(screen) - 5, 5): for i in range(4): if previousLane == i: continue w = gameCoords[2] - gameCoords[0] x = i * w / 4 + w / 8 y = len(screen) - y_ if screen[y][x] < 40: actualX = x + gameCoords[0] actualY = y + gameCoords[1] score += 1 if score > 1000: actualY += 10 if score > 1250: actualY += 10 if score > 1450: actualY += 10 if score > 1600: actualY += 20 for k in range(1700, 2500): if score > k: actualY += 10 else: break click(actualX, actualY) previousLane = i return
def shoot(): for y in range(len(screen)): for x in range(len(screen[y])): if screen[y][x] < 15: #found black pixel - [0-255] Tooclose = False #check if been here for pos in been_to: if dist(x, y, pos[0], pos[1]) < 66: Tooclose = True break if Tooclose: continue #not been to #moveMouseTo(x+game_coords[0],y+game_coords[1]) #testing print( "hit", x, y, ) click(x + game_coords[0] + 5, y + game_coords[1]) click(x + game_coords[0] + 5, y + game_coords[1]) #adding 3 and 5 since running too fast been_to.append([x, y]) print(len(been_to)) #time.sleep(0.01) if len(been_to) > 2: del been_to[0]
def zoomOut(): averageC = (game_coords[2] + game_coords[0]) // 2 click(averageC, 971) #click middle of timeline to select time.sleep(.1) press("n") #press home to go to beginning of timeline for x in range(2): #zoom out 11 times press('-') click(averageC, 971) #click middle of timeline to select
def takeScreenshot(): press('v') click(1300, 973) #time.sleep(.1) screen = np.array(ImageGrab.grab(bbox=game_coords) ) #takes screenshot of bounding box. screen is an image screen = cv2.cvtColor( screen, cv2.COLOR_BGR2GRAY ) #cv2.COLOR_BGR2GRAY translates rgb image to grayscale. converts the screen image array to grayscale return screen
def clickSquare (screen): global stepX, stepY, gameWidth, gameHeight, gameCoords for x in range(stepX, gameWidth, stepX * 2): for y in range(stepY, gameHeight, stepY * 2): if (screen[y][x]) < 10: actualX = x + gameCoords[0] actualY = y + gameCoords[1] click(actualX, actualY) # print("looking at x: {}, y: {}".format(x, y)) # print("pixel value: {}".format(screen[x][y])) # print("clicked at x: {}, y: {}".format(actualX, actualY)) time.sleep(0.05)
def prepareWindow(): #eventually should click to select specific tracks (currently wouldnt work if they aren't selected) will always be a certain distance away from blue pixel box around timeline workspace averageC = (game_coords[2] + game_coords[0]) // 2 click(averageC, 971) #click middle of timeline to select time.sleep(.1) press("n") #press home to go to beginning of timeline for x in range(11): #zoom in 11 times press('=') time.sleep(waitTime) for y in range(3): #zoom out 5 times press('-') time.sleep(waitTime) click(averageC, 971) #click middle of timeline to select
def clickOnBlack(screen, w, h, x_positions): global previous_column x0 = 1140 y0 = 150 for y in reversed(range(0, h, 5)): for x in x_positions: if x != previous_column: if screen[y][x] < 40: actual_y = y0 + y actual_x = x0 + x click(actual_x, actual_y) previous_column = x print('clicked at {}, {}'.format(actual_x, actual_y)) return 1 return 0
def shoot_some_fuckers(screen): global game_coords, previous_clicks, stage_no, no_of_clicks_this_level for y in range(238, len(screen) - 5, 2): for x in range(5, len(screen[y]) - 5, 2): if screen[y][x] < 10: actual_x = x + game_coords[0] actual_y = y + game_coords[1] click_bubble_range = 30 if stage_no == 3: click_bubble_range = 0 too_close = False for pos in previous_clicks: if dist(actual_x, actual_y, pos[0], pos[1]) < click_bubble_range: too_close = True break if too_close: continue click(actual_x, actual_y) no_of_clicks_this_level += 1 if stage_no == 0: # time.sleep(0.03) click(actual_x + 3, actual_y) no_of_clicks_this_level += 1 # time.sleep(0.03) max_previous_click_length = 3 if stage_no == 1: max_previous_click_length = 5 if stage_no == 2: max_previous_click_length = 5 if stage_no == 3: max_previous_click_length = 1 previous_clicks.append([actual_x, actual_y]) if len(previous_clicks) > max_previous_click_length: del previous_clicks[0] if stage_no < 2: return
def clickOnFirstBlock(screen): global gameCoords, score, previousLane for y_ in range(5, len(screen) - 5, 5): for i in range(4): if previousLane == i: continue w = gameCoords[2] - gameCoords[0] x = int(round(i * w / 4 + w / 8)) y = len(screen) - y_ if screen[y][x] < 50: actualX = x + gameCoords[0] actualY = y + gameCoords[1] score += 1 if score > 500: actualY += 45 if score > 700: actualY += 15 if score > 800: actualY += 20 if score > 900: actualY += 20 if score > 1100: actualY += 20 if score > 1200: actualY += 30 if score > 1350: actualY += 25 if score > 1600: actualY += 30 if score > 1700: actualY += 35 if score > 1800: actualY += 55 if score > 1900: actualY += 65 if score > 2000: actualY += 65 for k in range(1900, 2500): if score > k: actualY += 20 else: break click(actualX, actualY) previousLane = i return
def cutAndMove(): #press z at X1 click(X1 + game_coords[0] + playheadOffset, playheadY) press('z') time.sleep(clickTime) #increment by X1 to the right press('h') pyautogui.moveTo((game_coords[0] + game_coords[2]) / 2, playheadY + 15, duration=clickTime) pyautogui.drag(-X1, 0, 0.25, pyautogui.easeOutQuad) print("I moved this many pixels: ", X1) print("X1: ", X1) print("X2: ", X2) print("Cut location: ", X2 - X1 + game_coords[0] + playheadOffset) time.sleep(clickTime) #press q at X2-X1 click(X2 - X1 + game_coords[0] + playheadOffset, playheadY) #click playhead at X2 press('q') time.sleep(clickTime)
def begin(screen): global gameCoords, score, previousLane for y_ in range( 5, len(screen) - 5, 5 ): # YOU WILL HAVE TO GO THROUGH THIS FUNCTION! len(screen) = 600. We are iterating each 5 pixels vertically. for i in range(4): if previousLane == i: # this makes sure that the clicked lane isnt checked again continue w = gameCoords[2] - gameCoords[0] x = int(i * w / 4 + w / 8) # get the coords of the pixels to look at y = int( len(screen) - y_ ) # y is going to keep decreasing as we go further down the loop if screen[y][x] < 70: actualX = x + gameCoords[0] # stores the positions to click at actualY = y + gameCoords[1] score += 1 if score > 1000: # taking care of the mouse lag when the speeds increase a lot. actualY += 10 if score > 1250: actualY += 10 if score > 1450: actualY += 10 if score > 1600: actualY += 20 if score > 1750: actualY += 20 if score > 1900: actualY += 30 if score > 2100: actualY += 30 # the score could be improved by further calibrating the mouse speed at high scores click(actualX, actualY) previousLane = i return
def shoot_some_soldiers(screen): global game_coords global bubble global x_width global y_width for y in range(5, len(screen) - 5): if bubble[1] < y < bubble[3]: continue for x in range(5, len(screen[y]) - 5): if bubble[0] < x < bubble[2]: continue elif screen[y][x] < 10: actual_x = x + game_coords[0] + 2 actual_y = y + game_coords[1] # shoot twice click(actual_x, actual_y) time.sleep(0.05) click(actual_x, actual_y) # create bubble bubble = [x - x_width, y - y_width, x + x_width, y + y_width] return
#calibrator: #while True: # mouse_pos = queryMousePosition() # print(str(mouse_pos.x) + " " + str(mouse_pos.y)) # time.sleep(1) print("alright we good to go") lastClick = ((mouse_game_coords[0] + 10, mouse_game_coords[1] + 10)) #playOnce = False attempts = 0 while True: print("HI") #time.sleep(1) mouse_pos = queryMousePosition() #print(str(mouse_pos.x) + " " + str(mouse_pos.y)) click(mouse_game_coords[0] + 10, mouse_game_coords[1] + 10) if mouse_game_coords[0] < mouse_pos.x < mouse_game_coords[2] and mouse_game_coords[1] < mouse_pos.y < mouse_game_coords[3]: clicks = 0 start_time = time.time() #centerX = int(numBoxesX/2) * mouseBoxSize + 10 #centerY = int(numBoxesY/2) * mouseBoxSize + 10 move(lastClick[0], lastClick[1], mouse_game_coords[0] + 10, mouse_game_coords[1] + 10) click(mouse_game_coords[0] + 10, mouse_game_coords[1] + 10) #first click in the center clicks += 1 lastClick = (mouse_game_coords[0] + 10, mouse_game_coords[1] + 10) attempts += 1 time.sleep(calcSleep()) gameOver = False
def click_start_button(): for (x, y) in game_pixels: click(x, y+300)
def restart_click(self): click(self.restart_coords[0][0], self.restart_coords[0][1]) time.sleep(.2) click(self.restart_coords[1][0], self.restart_coords[1][1]) time.sleep(.2) self.move_mouse()
def window_click(self): click(self.select_coords[0], self.select_coords[1]) self.move_mouse()
for y in array: if screen[treesY[y]][x] == 89: return y return maxTimes time.sleep(START_DELAY) for i in range(10000): mousePos = queryMousePosition() screen = np.array(ImageGrab.grab(bbox=(863, 145, 1073, 602))) screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY) val = clicks(screen) print( "==========================================================================" ) print("Times : ", val[0]) print("Direction : ", val[1]) print( "==========================================================================" ) direction = btn[val[1]]["x"] times = val[0] for i in range(times): click(direction, btn[val[1]]["y"]) time.sleep(.05) time.sleep(.03)
def replay_click(self): click(self.replay_coords[0], self.replay_coords[1]) self.move_mouse()
def click_start_button(game_pixel_line=game_pixel_line, col_xs=col_xs): for i in range(len(col_xs)): click(col_xs[i], game_pixel_line[1])
def start_the_game(): for x in [2720, 2860, 3000, 3140]: click(x, 600)
def do_click(_x, _y): click(_x, _y)
GRAY = Coords(868, 59) LIGHTERGRAY = Coords(869, 82) # 10 seconds to get to paint time.sleep(10) offsetX = 200 offsetY = 200 x = 0 y = 0 currentColour = 'N' for row in data: for col in row: if 0 <= col[1] < 64: if currentColour != 'B': click(BLACK.xp, BLACK.yp) time.sleep(0.005) currentColour = 'B' click(y + offsetY, x + offsetX) elif 64 <= col[1] < 127: if currentColour != 'G': click(GRAY.xp, GRAY.yp) time.sleep(0.005) currentColour = 'G' click(y + offsetY, x + offsetX) elif 127 <= col[1] < 191: if currentColour != 'S': click(LIGHTERGRAY.xp, LIGHTERGRAY.yp) time.sleep(0.005) currentColour = 'S' click(y + offsetY, x + offsetX)
def upgrade_gun(): for i in range(40): click(804, 425) click(806, 425) for j in range(5): time.sleep(0.1) for i in range(200): click(718, 435) click(720, 435) click(720, 437) click(718, 437) click(918, 736)
actualY += 10 if score > 1600: actualY += 20 if score > 1750: actualY += 20 if score > 1900: actualY += 30 if score > 2100: actualY += 30 # the score could be improved by further calibrating the mouse speed at high scores click(actualX, actualY) previousLane = i return click(1000, 710) # clicks the start buttons, wherever they are, initalizing the game click(1130, 710) click(860, 710) click(760, 710) while True: mousePos = queryMousePosition() if gameCoords[2] > mousePos.x > gameCoords[ 0]: # make sure that the mouse is in the right position startTime = time.time() screen = np.array(ImageGrab.grab(bbox=gameCoords)) screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY) begin(screen) print("Frame took {} seconds.".format((time.time() - startTime)))
def pressStart(): mousePos = queryMousePosition() click(mousePos.get("x"), mousePos.get("y")) time.sleep(0.2)
def click_black_pixel(x, y, y_offset): click(x, y + y_offset)
def click_black_pixel(x_offset, y_offset, game_pixel_line=game_pixel_line): x = game_pixel_line[0] + x_offset y = game_pixel_line[1] click(x+50, y-y_offset)
while True: time.sleep(1) mousePos = queryMousePosition() # print(str(mousePos.x) + ", " + str(mousePos.y), flush=True) menu_screen = np.array(ImageGrab.grab(bbox=menuCoords)) menu_color = avgColor(menu_screen) # print(menu_color) if not (menu_color[0] < 120 and menu_color[0] > 110 and menu_color[1] < 120 and menu_color[1] > 110 and menu_color[2] < 120 and menu_color[2] > 110): print("INSIDE", flush=True) bobber_screen = np.array(ImageGrab.grab(bbox=bobberCoords)) # screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY) print(avgColor(bobber_screen), flush=True) # print(screen[393-bobberCoords[1]][959-bobberCoords[0]]) print("Throw bobber", flush=True) click(mousePos.x, mousePos.y) time.sleep(2) print("Start checking for dip", flush=True) nodip = True while nodip: bobber_screen = np.array(ImageGrab.grab(bbox=bobberCoords)) bobber_color = avgColor(bobber_screen) print(bobber_color, flush=True) if bobber_color[0] < 40: print("Reel in", flush=True) click(mousePos.x, mousePos.y) nodip = False
def drawCircle(x0, y0, r): x = r y = 0 err = 1 - x while (x >= y): click(x + x0, y + y0) click(y + x0, x + y0) click(-x + x0, y + y0) click(-y + x0, x + y0) click(-x + x0, -y + y0) click(-y + x0, -x + y0) click(x + x0, -y + y0) click(y + x0, -x + y0) y = y + 1 if (err < 0): err = err + 2 * y + 1 else: x = x - 1 err = err + 2 * (y - x + 1)