I guess it's played over and over again because the condition of the if
clause stays True
; and probably it's True
for multiple block
objects in block_list
.
You should fix that in a way that makes sense for your application.
It's hard to give a good advice when you don't know the bigger picture, but maybe a simple flag will help you:
# somewhere
play_error_sound = True
...
for block in block_list:
if block.rect.y >= 650 and health >=25 and score < 70:
...
if play_error_sound:
play_error_sound = False
error.play()
# set play_error_sound to True once it is allowed to be played again
P.S.: consider loading your Font
only once at the start of your application, not over and over again in a loop. Also, you should cache all Surfaces created with font.render
, since font rendering is also a very expensive operation and can be a major performance bottleneck.