| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
import pygame |
|---|
| 8 |
|
|---|
| 9 |
pygame.mixer.init() |
|---|
| 10 |
|
|---|
| 11 |
sndFxVolume = 255 |
|---|
| 12 |
musicVolume = 255 |
|---|
| 13 |
|
|---|
| 14 |
def setSndFxVolume(volume): |
|---|
| 15 |
if 0<=volume<=255: |
|---|
| 16 |
global sndFxVolume |
|---|
| 17 |
sndFxVolume = volume |
|---|
| 18 |
|
|---|
| 19 |
def setMusicVolume(volume): |
|---|
| 20 |
if 0<=volume<=255: |
|---|
| 21 |
global musicVolume |
|---|
| 22 |
musicVolume = volume |
|---|
| 23 |
|
|---|
| 24 |
class Sound: |
|---|
| 25 |
loops = 0 |
|---|
| 26 |
def __init__(self, filename): |
|---|
| 27 |
self.snd = pygame.mixer.Sound(filename) |
|---|
| 28 |
self.snd.set_volume(sndFxVolume) |
|---|
| 29 |
|
|---|
| 30 |
def start(self): |
|---|
| 31 |
self.snd.play(self.loops) |
|---|
| 32 |
|
|---|
| 33 |
class Music(Sound): |
|---|
| 34 |
"""For now Music is just another Sound, because I have no idea what |
|---|
| 35 |
fraca is trying to do by having two classes that do the same thing, |
|---|
| 36 |
and even though I could read the source I'm lazy |
|---|
| 37 |
(sorry for saying it was closed source though, Fraca)""" |
|---|
| 38 |
|
|---|
| 39 |
def __init__(self, filename, maxchan = 128, loop = False): |
|---|
| 40 |
"""maxchan is I have no clue, loop makes it loop""" |
|---|
| 41 |
Sound.__init__(self, filename) |
|---|
| 42 |
if loop: self.loops = -1 |
|---|
| 43 |
else: self.loops = 0 |
|---|
| 44 |
self.snd.set_volume(musicVolume) |
|---|
| 45 |
|
|---|
| 46 |
def stop(self): |
|---|
| 47 |
self.snd.stop() |
|---|