Skip to content

Instantly share code, notes, and snippets.

@cedricduriau
Last active February 12, 2022 10:22
Show Gist options
  • Save cedricduriau/7bb0165f80552783c2c53352eaa42d5e to your computer and use it in GitHub Desktop.
Save cedricduriau/7bb0165f80552783c2c53352eaa42d5e to your computer and use it in GitHub Desktop.
Piano Tiles 2 auto clicker bot.
"""
Piano Tiles 2 auto clicker bot.
This is an auto clicker bot for the online Piano Tiles 2 game.
I wrote this on a late night after watching a video of a similar project and
decided to give it a go myself. I'm fun at parties, trust me.
Dependencies:
- pyautogui
- fastgrab 0.2.0
Links:
- pyautogui: https://github.com/asweigart/pyautogui
- fastgrab: https://github.com/mherkazandjian/fastgrab/tree/0.2.0
- game: https://h5.4j.com/games/Piano-Tiles-2-Online/index.html?pubid=yiv&v=1546731466
- video: https://www.youtube.com/watch?v=wHRubMACen0
"""
# third party modules
import pyautogui
from fastgrab.screenshot import Screenshot
# clear default sec after every public call
pyautogui.PAUSE = 0
# game info
LEFT = 680
RIGHT = 1230
BLOCK_WIDTH = 140
BLOCK_COUNT = 4
FOCUS_POINTS = [int(LEFT + ((i * BLOCK_WIDTH) - (BLOCK_WIDTH / 2)))
for i in range(1, BLOCK_COUNT + 1)]
def is_match(color):
"""
Returns whether the color matches the rules to click.
:param color: RGB color to determine match for.
:type color: array[uint8]
:rtype: bool
"""
try:
value = sum(color.tolist())
except TypeError:
return False
return value < 5
if __name__ == "__main__":
while True:
# get mouse position
mouse_x, mouse_y = pyautogui.position()
# determine whether mouse is in game window
if RIGHT > mouse_x > LEFT:
# grab image
img = Screenshot().capture()
# get screen row information
try:
row = img[mouse_y]
except IndexError as e:
print(str(e))
continue
for focus_point in FOCUS_POINTS:
# get color at focus point
try:
color = row[focus_point]
except IndexError:
break
if is_match(color):
pyautogui.click(focus_point, mouse_y)
break
@Smoethingelse
Copy link

K

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment