#!/usr/bin/env python3.7 # This is for macOS to play Piano Tiles 2 on BlueStacks. # To be specific, I ran this on my Macmini6,1 # You will likely have to change y and tileWidth in this code. # This code will stop on its own after you lose. # To prematurely stop Piano Tiles 2, you can press "esc" during run. # I mostly want to use this on the Master hall, # which means that I don't have to worry about programming long clicks for long tiles # because time (not score) is important, and I don't have to worry about things # like slider tiles! # For Pianist Challenge... # Orange slidey tiles, starburst tiles, and huge multi-click tiles cause problems. # Songs that produce sparkly graphics for every tap can cause problems. # I needed to first do `sudo port install py37-pyobjc` (requires MacPorts) # or `sudo pip-3.7 install pyobjc` import Quartz.CoreGraphics as CG import struct import time # tap mindlessly (True) or intelligently (False) # Mindless tapping should allow the rare combo (tap-many-times) tiles to be completed mindlessTaps = False # start with Piano Tiles 2 (in BlueStacks) on upper-left of screen # x increases left to right from 0 to width-1 (measured in pixels) # y increases top to bottom from 0 to height-1 (measured in pixels) #y = 400 #tileWidth = 101 y = 670 #y = 800 tileWidth = 135 x1 = 15 # don't start at center of tile else long tiles can give problems x2 = x1 + tileWidth x3 = x1 + 2*tileWidth x4 = x1 + 3*tileWidth region = CG.CGRectMake(x1, y, 3*tileWidth+1, 1) # 1 screenshot is faster than 4 tiny ones # since rgb aren't exactly 0 on tiles (partly due to BlueStacks and also due to long tiles), # set a tolerance that is an integer less than 256 cap = 20 # After how many cycles to stop? # Set this high if game in BlueStacks often pauses for a few moments. # I usually don't have to wait for this since the code can stop in other ways. # Having this is VERY important else you can stuck not being able to use your computer! stopCounter = 1000 # How long to pause between mouse down and mouse up? # Increase this value if clicks are not registering. There is some randomness to whether or not they register. For me, it is the game's or Bluestack's or macOS's ability to refresh the screen fast enough ultimately limits me to not going much over 30 tiles/s, so don't worry about making this number a bit too large. # Decrease this value if counter that is printed at each click is regularly 1. iPause = 15000 # A pause with more precision but less accuracy than time.sleep() # On my crappy computer, each iteration takes about 3e-7 seconds. def pause(n): i = 0 ii = 0.0 while i2: print("More than 2 tiles were found, so quitting!") print("This is likely due to the screen going black for a moment at end of game.") quit() # A minor fix to deal with slow screen update when tapping double tiles. if (state==[0,1,0,1] and stateNow==[0,0,0,1]) or (state==[1,0,1,0] and stateNow==[0,0,1,0]): stateNow = state if (stateNow != state and stateNow != [0,0,0,0]): print(stateNow, counter) counter = 0 if not mindlessTaps: if stateNow[0]: clickk(x1,y) if stateNow[1]: clickk(x2,y) if stateNow[2]: clickk(x3,y) if stateNow[3]: clickk(x4,y) state = stateNow print("Timed out!")