Skip to content

Commit

Permalink
[FEATURE] Abstracted audio channel selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickname2002 committed Jul 2, 2023
1 parent 0d48ef1 commit 7ac8e42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions jorcademy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
screen_title: str = "JorCademy Engine"
background_color: tuple = (0, 0, 0)
draw_buffer: list = []
audio_channel_count: int = 0

# Initialize audio component
pygame.mixer.init()
Expand Down Expand Up @@ -85,14 +86,17 @@ def image(url: str, x: float, y: float, scale: float, rotation=0) -> None:

# Load new sound
def load_sound(path: str):
sound: Audio = Audio(path)
global audio_channel_count
sound: Audio = Audio(audio_channel_count, path)
audio_channel_count += 1
return pygame.mixer.Sound(sound.filepath)


# Play audio
def play_sound(sound: pygame.mixer.Sound, channel: int):
if not pygame.mixer.Channel(channel).get_busy():
pygame.mixer.Channel(channel).play(sound)
def play_sound(audio_obj: Audio):
sound = pygame.mixer.Sound(audio_obj.filepath)
if not pygame.mixer.Channel(audio_obj.channel).get_busy():
pygame.mixer.Channel(audio_obj.channel).play(sound)


# Wait for new action
Expand Down
3 changes: 2 additions & 1 deletion primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,6 @@ def draw(self, context: pygame.display):

# Representing an audio object
class Audio:
def __init__(self, path):
def __init__(self, channel: int, path: str):
self.filepath = path
self.channel = channel

0 comments on commit 7ac8e42

Please sign in to comment.