-1

So I'm working on a menu screen for an Indie Game I'm making I don't know too much about pygame and feel it would be fun to make a game and learn at the same time. But for some reason if you hover to the left of the exit game button it lights up I want it to be set exactly to the button size.


pygame.init()

white = (255, 255, 255)
black = (0, 0, 0)
button_light = (170, 170, 170)
button_dark = (100, 100, 100)

background = black
window = pygame.display.set_mode((1000, 600))
pygame.display.set_caption("Zero Dark Thirty")
window.fill(background)
pygame.display.flip()

width = window.get_width()
height = window.get_height()

small_font = pygame.font.SysFont('Corbel', 35)
quit_button = small_font.render('Exit Game', True, white)


while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if width / 2 - 50 <= mouse[0] <= width / 2 + 140 and height / 2 - 8 <= mouse[1] <= height / 2 + 40:
                pygame.quit()
    mouse = pygame.mouse.get_pos()

    if width / 2 - 75 <= mouse[0] <= width / 2 + 140 and height / 2 - 8 <= mouse[1] <= height / 2 + 40:
        pygame.draw.rect(window, button_light, [width / 2 - 80, height / 2 - 10, 150, 40])

    else:
        pygame.draw.rect(window, button_dark, [width / 2 - 80, height / 2 - 10, 150, 40])

    window.blit(quit_button, (width / 2 - 75, height / 2 - 8))
    pygame.display.update()

1 Answers1

0

In the code that checks to see if the mouse is over the button, it says width / 2 - 50 but in the code below that, it says width / 2 - 75 Try making those the same, and if that doesn't work tell me.

Pixeled
  • 316
  • 3
  • 10