clackmanager.py 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from pygame.mixer import Sound, Channel
  2. from pygame import mixer
  3. import random
  4. class Clackmanager:
  5. clacks = []
  6. channel1 = None
  7. channel2 = None
  8. def load(self):
  9. self.clacks.append(Sound("audio/clack_01.ogg"))
  10. self.clacks.append(Sound("audio/clack_02.ogg"))
  11. self.clacks.append(Sound("audio/clack_03.ogg"))
  12. self.clacks.append(Sound("audio/clack_04.ogg"))
  13. self.clacks.append(Sound("audio/clack_05.ogg"))
  14. self.clacks.append(Sound("audio/clack_06.ogg"))
  15. self.clacks.append(Sound("audio/clack_07.ogg"))
  16. self.clacks.append(Sound("audio/clack_08.ogg"))
  17. self.clacks.append(Sound("audio/clack_09.ogg"))
  18. self.clacks.append(Sound("audio/clack_10.ogg"))
  19. self.channel1 = Channel(0)
  20. self.channel2 = Channel(2)
  21. def play_clack(self):
  22. while True:
  23. clack = random.choice(self.clacks)
  24. if clack.get_num_channels() == 0:
  25. break
  26. if not self.channel1.get_busy():
  27. self.channel1.play(clack)
  28. print "played on 1"
  29. elif not self.channel2.get_busy():
  30. self.channel2.play(clack)
  31. print "played on 2"