So I have made I game using pygame, the system I am using makes it so that the game() function is where the actual gameplay happens, I'm trying to make a health bar for the enemy you face but the if the function is not updating the health bar and the button doesn't even seem to be pressed as the 'click' sound effect is not playing any insight into why this may be the case would be greatly appreciated, I would also like to mention that as shown at the bottom I have made it so that the health total is shown when you hover over the health bar and this doesn't change with when clicking attack.
def game():
running = True
stopmusic()
pmusic("assets\\music\\battlemusic.mp3")
while running:
screen.fill((0, 0, 0))
sewer = pygame.image.load('assets\\backgrounds\\sewer.png')
screen.blit(sewer,(0,0))
mx, my = pygame.mouse.get_pos()
turn = 0
mob()
monster_health()
button_attack = pygame.Rect(150, 500, 200, 50)
button_potion = pygame.Rect(150, 600, 200, 50)
button_spell = pygame.Rect(450, 500, 200, 50)
button_suicide = pygame.Rect(450, 600, 200, 50)
healthbar_outline = pygame.Rect(45,45, 1190, 60)
healthbar = pygame.Rect(50,50, (how_much_health_bar), 50)
if button_attack.collidepoint((mx, my)):
if click:
global damage_done
pygame.mixer.Sound.play(click_sound)
damage_done = random.randint(1000,10000)
monster_health()
print(damage_done)
healthbar = pygame.draw.Rect(50,50, (how_much_health_bar), 50)
return(healthbar)
if healthbar.collidepoint((mx, my)):
pygame.draw.rect(screen, (255, 0, 0), healthbar)
draw_text((display_health), font, (255, 255, 255), screen, 550, 60)
else:
pygame.draw.rect(screen, (255, 0, 0), healthbar)