def game_logic(screen, dt, player): global TRACES im = screen_grab(box=PLAYABLE_BOX) #return True #im = screen_grab(box=PLAYABLE_BOX) im_gray = ImageOps.grayscale(im) coords = get_coords() if coords[0] < 0 or coords[1] < 0: print "Mouse out" return False if im.getpixel(END_GAME_OK) == (232, 97, 1): return True if im.getpixel(GET_READY) == (244, 198, 0) or im.getpixel(START_BUTTON) == (217, 83, 14): return True diff_array = asarray(ImageChops.difference(im_gray,BACKGROUND_GRAY)) #grayscale_array_to_pygame(screen, diff_array) bird, pipes = find_elements(diff_array) draw_game(screen, bird, pipes) player.see(dt, bird, pipes) pygame.draw.rect(screen, BLUE, [player.x - 3, player.y - 3, 6, 6]) font = pygame.font.SysFont("monospace", 15) label = font.render("%d %d"%(player.speed_y, player.accel_y), 1, (255,255,0)) screen.blit(label, (10, FLOOR_Y + 26)) player.play() return True
def start_game(): im = screen_grab() if im.getpixel(END_GAME_OK) == (232, 97, 1): mouse_pos(*END_GAME_OK) left_click() time.sleep(.1) mouse_pos(*START_BUTTON) left_click() time.sleep(.1) left_click() time.sleep(.1) time.sleep(.5)
def see(self): """Capture the required area""" self.image = screen_grab(self.sct, BOX, False)