Merge pull request 'Audio added' (#5) from s464900/WMICraft:audio into audio

Reviewed-on: s464965/WMICraft#5
This commit is contained in:
Mateusz Konofał 2022-03-13 22:23:49 +01:00
commit 077574f298
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 models.knight import Knight
from models.monster import Monster
from sound.audioHandler import gamePlaylist
from ui.screens.credits import Credits
from ui.logs import Logs
from ui.screens.options import Options
@ -35,6 +36,8 @@ class Game:
click = False
def main_menu(self):
playlist = gamePlaylist()
playlist.menuAudio()
while True:
self.screen.blit(self.bg, (0, 0))
@ -92,6 +95,8 @@ class Game:
knights_list = pygame.sprite.Group()
knights_list.add(knight1)
knights_list.add(knight2)
playlist = gamePlaylist()
playlist.gameAudio()
while running:
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)