Audio added

This commit is contained in:
[matkonofal] 2022-03-13 15:50:29 +01:00
parent b647ba3423
commit bf0d2acb78
8 changed files with 22 additions and 0 deletions

View File

@ -7,6 +7,7 @@ from common.constants import GAME_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, FPS_COUNT,
from common.helpers import draw_text from common.helpers import draw_text
from models.knight import Knight from models.knight import Knight
from models.monster import Monster from models.monster import Monster
from sound.audioHandler import gamePlaylist
from ui.screens.credits import Credits from ui.screens.credits import Credits
from ui.logs import Logs from ui.logs import Logs
from ui.screens.options import Options from ui.screens.options import Options
@ -35,6 +36,8 @@ class Game:
click = False click = False
def main_menu(self): def main_menu(self):
playlist = gamePlaylist()
playlist.menuAudio()
while True: while True:
self.screen.blit(self.bg, (0, 0)) self.screen.blit(self.bg, (0, 0))
@ -92,6 +95,8 @@ class Game:
knights_list = pygame.sprite.Group() knights_list = pygame.sprite.Group()
knights_list.add(knight1) knights_list.add(knight1)
knights_list.add(knight2) knights_list.add(knight2)
playlist = gamePlaylist()
playlist.gameAudio()
while running: while running:
self.screen.blit(self.bg, (0, 0)) self.screen.blit(self.bg, (0, 0))

BIN
sound/1.ogg Normal file

Binary file not shown.

BIN
sound/2mm.ogg Normal file

Binary file not shown.

BIN
sound/3.ogg Normal file

Binary file not shown.

BIN
sound/4.ogg Normal file

Binary file not shown.

BIN
sound/5.ogg Normal file

Binary file not shown.

0
sound/__init__.py Normal file
View File

17
sound/audioHandler.py Normal file
View File

@ -0,0 +1,17 @@
from random import choice
from pygame import mixer
class gamePlaylist:
wavFiles = ["sound/2mm.ogg", "sound/3.ogg", "sound/4.ogg", "sound/5.ogg"]
wavMenu = ["sound/1.ogg"]
def gameAudio(self):
wavRandom = choice(gamePlaylist.wavFiles)
mixer.music.load(wavRandom)
mixer.music.play()
def menuAudio(self):
w = choice(gamePlaylist.wavMenu)
mixer.music.load(w)
mixer.music.play(-1)