-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sound.py
executable file
·87 lines (78 loc) · 2.95 KB
/
Sound.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
import jngl
import Somyeol
import random
import os
SOUND = "sound/"
class Sound(object):
def __init__(self, game):
self.game = game
self.sound_queue = set()
self.somyeol_count = 0
self.walk_sounds_playing = 0
self.sound_walk = False
self.sounds_playing = 0
self.sound_land = 0
self.playing_sounds = []
jngl.setVolume(50)
#Generate a list of all sound-files
self.sounds = []
dirList = os.listdir(SOUND)
for f in dirList:
if not f.endswith(".ogg"):
continue
self.sounds.append(SOUND+f)
def stopSounds(self):
for sound in self.sounds:
jngl.stop(sound)
def updateSoundsPlaying(self):
self.sounds_playing = 0
self.walk_sounds_playing = 0
self.playing_sounds = []
for sound in self.sounds:
if jngl.isPlaying(sound):
self.playing_sounds.append(sound)
if sound in Somyeol.Somyeol.sound_walk:
self.walk_sounds_playing += 1
else:
self.sounds_playing +=1
def playSounds(self):
self.somyeol_count = len(self.game.level.somyeols)
self.updateSoundsPlaying()
#Sounds that are used by alot of Somyeols get a special treatment (walking and jumping)
if jngl.keyDown(jngl.key.Up):
#Stop other sounds if jumping
for sound in Somyeol.Somyeol.sound_walk:
jngl.stop(sound)
for sound in Somyeol.Somyeol.sound_walk_crowd:
jngl.stop(sound)
#play other sounds...
for sound in self.sound_queue:
if sound in Somyeol.Somyeol.sound_walk:
if self.walk_sounds_playing >= self.somyeol_count:
continue
else:
if self.sounds_playing >= self.somyeol_count:
continue
if not sound in self.playing_sounds:
jngl.play(sound)
else:
#use the crowd sounds
if sound in Somyeol.Somyeol.sound_jump:
sound = Somyeol.Somyeol.sound_jump_crowd[random.randint(0,len(Somyeol.Somyeol.sound_jump_crowd)-1)]
if not jngl.isPlaying(sound):
jngl.play(sound)
elif sound in Somyeol.Somyeol.sound_walk:
sound = Somyeol.Somyeol.sound_walk_crowd[random.randint(0,len(Somyeol.Somyeol.sound_walk_crowd)-1)]
if not jngl.isPlaying(sound):
jngl.play(sound)
self.sound_queue.clear()
def getSound(self, list):
return list[random.randint(0,len(list))-1]
def addToQueue(self, sound):
if sound in Somyeol.Somyeol.sound_walk:
if self.walk_sounds_playing >= self.somyeol_count:
return
self.sound_queue.add(sound)
if __name__ == "__main__":
import main