Now for some music! Feel it! No pictures here and in the free version no pictures allowed.
Before the while loop, add
#Play music infintely till the game runs MUSICFILE = "background_music.mp3" INFINITE = -1 pygame.mixer.music.load(MUSICFILE) pygame.mixer.music.play(INFINITE)
The code loads the music file and runs it again and again in a loop, till we stop it.
In the game over part of the code.
GAMEOVERMUSIC = "gameover.mp3" PLAYONCE = 0 if(len(wall_group.sprites()) == 0): print("game over") pygame.mixer.music.stop() pygame.mixer.music.load(GAMEOVERMUSIC) pygame.mixer.music.play(PLAYONCE)
The code stops the background music, loads the game over music and plays it only once this time (PLAYONCE = 0).
Now, what if we need to add levels to our game, by making the wall structure more difficult to break?
Ready for the last challenge?