Apr-19-2020, 12:38 AM
I don't know about the 2nd issue you had,
but the following might help you w/ the 1st issue:
button1("GO!", intro_button_width1, intro_button_height, 100, 50, green, bright_green, game_loop)
button1("Quit", intro_button_width2, intro_button_height, 100, 50, red, bright_red, quit)
mouse = pygame.mouse.get_pos()
if (intro_button_width1 + 100 > mouse[0] > intro_button_width1
and intro_button_height + 50 > mouse[1] > intro_button_height):
pygame.draw.rect(gameDisplay, bright_green, (intro_button_width1, intro_button_height, 100, 50))
else:
pygame.draw.rect(gameDisplay, green, (intro_button_width1, intro_button_height, 100, 50))
smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("GO!", smallText)
textRect.center = ((intro_button_width1 + (100 / 2)), (intro_button_height + (50 / 2)))
gameDisplay.blit(textSurf, textRect)
if (intro_button_width2 + 100 > mouse[0] > intro_button_width2
and intro_button_height + 50 > mouse[1] > intro_button_height):
pygame.draw.rect(gameDisplay, bright_red, (intro_button_width2, intro_button_height, 100, 50))
else:
pygame.draw.rect(gameDisplay, red, (intro_button_width2, intro_button_height, 100, 50))
**** button1 is defined as:
def button1(msg,x,y,w,h,ic,ac,action=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if x+w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(gameDisplay, ac,(x,y,w,h))
if click[0] == 1 and action != None:
action()
else:
pygame.draw.rect(gameDisplay, ic,(x,y,w,h))
Hopefully, this helps.
but the following might help you w/ the 1st issue:
button1("GO!", intro_button_width1, intro_button_height, 100, 50, green, bright_green, game_loop)
button1("Quit", intro_button_width2, intro_button_height, 100, 50, red, bright_red, quit)
mouse = pygame.mouse.get_pos()
if (intro_button_width1 + 100 > mouse[0] > intro_button_width1
and intro_button_height + 50 > mouse[1] > intro_button_height):
pygame.draw.rect(gameDisplay, bright_green, (intro_button_width1, intro_button_height, 100, 50))
else:
pygame.draw.rect(gameDisplay, green, (intro_button_width1, intro_button_height, 100, 50))
smallText = pygame.font.Font("freesansbold.ttf", 20)
textSurf, textRect = text_objects("GO!", smallText)
textRect.center = ((intro_button_width1 + (100 / 2)), (intro_button_height + (50 / 2)))
gameDisplay.blit(textSurf, textRect)
if (intro_button_width2 + 100 > mouse[0] > intro_button_width2
and intro_button_height + 50 > mouse[1] > intro_button_height):
pygame.draw.rect(gameDisplay, bright_red, (intro_button_width2, intro_button_height, 100, 50))
else:
pygame.draw.rect(gameDisplay, red, (intro_button_width2, intro_button_height, 100, 50))
**** button1 is defined as:
def button1(msg,x,y,w,h,ic,ac,action=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if x+w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(gameDisplay, ac,(x,y,w,h))
if click[0] == 1 and action != None:
action()
else:
pygame.draw.rect(gameDisplay, ic,(x,y,w,h))
Hopefully, this helps.