This is more of a curiosity question, because I went back and managed to do what I wanted to do. The title was originally going to be something like 'Checking if an ordered tuple is in a tuple of ranges?'
Until now I've been checking mouse clicks using this code -
pos = pygame.mouse.get_pos()
if pos[0] > X and pos[0] < X2 and pos[1] > Y and pos[1] < Y2:
#Do this
#Separate function with same XY's
if pos[0] > X and pos[0] < X2 and pos[1] > Y and pos[1] < Y2:
#Do something else - could be used for mouse hover rather than click.
I was wondering how other people go about button detection, since sometimes more than one check is needed (in separate functions for example). Sometimes I will trigger an outside function, boolean or timer, or something along those lines. I've done that in the example below. But this can get messy too and I feel like there must be a simpler way.
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
gp = game.pos
#Initial gbh declaration
gbh = game.button_health = range(391, 527), range(179, 253)
if gp[0] in gbh[0] and gp[1] in gbh[1]:
player.skillpoints -= 1
player.health += 10
player.healthmax += 10
#Separate func.
gp = game.pos
gbh = game.button_health
if gp[0] in gbh[0] and gp[1] in gbh[1]:
blit(font.render(str(Z), True, BLACK), (X, Y))