Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #A class to setup music in the MORT pygame
- import pygame
- import os.path
- pygame.mixer.init()
- class sounds:
- levelOnePath = "resources/" + "levelonemusic.ogg"
- levelTwoPath = "resources/" + "leveltwomusic.ogg"
- levelThreePath = "resources/" + "levelthreemusic.ogg"
- bossPath = "resources/" + "bossmusic.ogg"
- levelOnePathExists = os.path.exists(levelOnePath)
- levelTwoPathExists = os.path.exists(levelTwoPath)
- levelThreePathExists = os.path.exists(levelThreePath)
- def bkgrndMusic(self,level = 0):
- if pygame.mixer.Channel(1).get_busy():
- pygame.mixer.Channel(1).stop()
- if level == 1 and sounds.levelOnePathExists:
- pygame.mixer.Channel(1).play(sounds.levelOnePath, loops = -1)
- elif level == 2 and sounds.levelTwoPathExists:
- pygame.mixer.Channel(1).play(sounds.levelTwoPath, loops = -1)
- elif level == 3 and sounds.levelThreePathExists:
- pygame.mixer.Channel(1).play(sounds.levelThreePath, loops = -1)
- elif level == 4 and sounds.bossPathExists:
- pygame.mixer.Channel(1).play(sounds.bossPath, loops = -1)
- else:
- print "Error: The soundfile doesn't exist"
- if __name__ == "__main__":
- level = int(raw_input())
- soundobj =sounds()
- soundobj.bkgrndMusic(level)
Add Comment
Please, Sign In to add comment