Guest User

Untitled

a guest
Oct 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #A class to setup music in the MORT pygame
  2.  
  3. import pygame
  4. import os.path
  5.  
  6. pygame.mixer.init()
  7.  
  8. class sounds:
  9. levelOnePath = "resources/" + "levelonemusic.ogg"
  10. levelTwoPath = "resources/" + "leveltwomusic.ogg"
  11. levelThreePath = "resources/" + "levelthreemusic.ogg"
  12. bossPath = "resources/" + "bossmusic.ogg"
  13.  
  14. levelOnePathExists = os.path.exists(levelOnePath)
  15. levelTwoPathExists = os.path.exists(levelTwoPath)
  16. levelThreePathExists = os.path.exists(levelThreePath)
  17.  
  18. def bkgrndMusic(self,level = 0):
  19. if pygame.mixer.Channel(1).get_busy():
  20. pygame.mixer.Channel(1).stop()
  21. if level == 1 and sounds.levelOnePathExists:
  22. pygame.mixer.Channel(1).play(sounds.levelOnePath, loops = -1)
  23. elif level == 2 and sounds.levelTwoPathExists:
  24. pygame.mixer.Channel(1).play(sounds.levelTwoPath, loops = -1)
  25. elif level == 3 and sounds.levelThreePathExists:
  26. pygame.mixer.Channel(1).play(sounds.levelThreePath, loops = -1)
  27. elif level == 4 and sounds.bossPathExists:
  28. pygame.mixer.Channel(1).play(sounds.bossPath, loops = -1)
  29. else:
  30. print "Error: The soundfile doesn't exist"
  31.  
  32. if __name__ == "__main__":
  33. level = int(raw_input())
  34. soundobj =sounds()
  35.  
  36. soundobj.bkgrndMusic(level)
Add Comment
Please, Sign In to add comment