diff options
author | Viljami Ilola <+@hix.fi> | 2024-04-20 21:39:07 +0300 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-04-20 21:39:07 +0300 |
commit | b9b64aa313a45ab53f856242b4ce5ddb151533fb (patch) | |
tree | 43bd21e0a3381af5524ad2045d09c8c603610eb6 | |
parent | 72f91db6e553b797dd879c4ed40360bfd54fd923 (diff) |
sfx subpackage
-rw-r--r-- | src/sliceitoff/assets/fonts.lst | 4 | ||||
-rw-r--r-- | src/sliceitoff/game/game.py | 5 | ||||
-rw-r--r-- | src/sliceitoff/sfx/__init__.py | 2 | ||||
-rw-r--r-- | src/sliceitoff/sfx/sfx.py | 28 | ||||
-rw-r--r-- | src/sliceitoff/text/fonts.py | 2 |
5 files changed, 37 insertions, 4 deletions
diff --git a/src/sliceitoff/assets/fonts.lst b/src/sliceitoff/assets/fonts.lst index 19690fa..58e14a5 100644 --- a/src/sliceitoff/assets/fonts.lst +++ b/src/sliceitoff/assets/fonts.lst @@ -1,2 +1,2 @@ -lcd assets gnufonts UTIL GNUFONTS LCD.FNT -8x8 assets gnufonts UTIL GNUFONTS 8X8.FNT +lcd gnufonts UTIL GNUFONTS LCD.FNT +8x8 gnufonts UTIL GNUFONTS 8X8.FNT diff --git a/src/sliceitoff/game/game.py b/src/sliceitoff/game/game.py index 832ab76..7a91ede 100644 --- a/src/sliceitoff/game/game.py +++ b/src/sliceitoff/game/game.py @@ -14,6 +14,7 @@ from sliceitoff.screens import ( instructions1_screen, instructions2_screen) from sliceitoff.hiscores import HiScores +from sliceitoff.sfx import sfx from .mainmenu import Mainmenu, MenuItems from .level import Level @@ -23,12 +24,14 @@ from .initials import Initials class Game: """ This is the whole game. """ def __init__(self): + assets_path = Path(__file__).parent.parent.resolve().joinpath('assets') pygame.init() + sfx.init(assets_path) self.clock = pygame.time.Clock() self.display = Display() self.stats = None self.hiscores = HiScores() - Fonts.load_fonts( Path(__file__).parent.parent.resolve() ) + Fonts.load_fonts(assets_path) pygame.mouse.set_visible(False) def __del__(self): diff --git a/src/sliceitoff/sfx/__init__.py b/src/sliceitoff/sfx/__init__.py new file mode 100644 index 0000000..c2256bc --- /dev/null +++ b/src/sliceitoff/sfx/__init__.py @@ -0,0 +1,2 @@ +""" sfx - sound effects loading and playing """ +from .sfx import sfx diff --git a/src/sliceitoff/sfx/sfx.py b/src/sliceitoff/sfx/sfx.py new file mode 100644 index 0000000..f9347df --- /dev/null +++ b/src/sliceitoff/sfx/sfx.py @@ -0,0 +1,28 @@ +""" sfx.sfx - pygame.mixer initialization and sound effects handling """ +import pygame + +class Sfx: + """ Sound Effects and Music? """ + def __init__(self): + self.initialized = False + try: + pygame.mixer.pre_init(channels=2, buffer=512, frequency=48000) + except pygame.error: + pass + + def init(self, base_path): + """ To be called after pygame is initialized. Actual mixer init and + sample loading happens here """ + try: + pygame.mixer.init() + self.initialized = True + except pygame.error: + pass + +# Initialize only one time +try: + # pylint: disable = used-before-assignment + # This is intented behaviour + sfx +except NameError: + sfx = Sfx() diff --git a/src/sliceitoff/text/fonts.py b/src/sliceitoff/text/fonts.py index 5743e2a..9f267b3 100644 --- a/src/sliceitoff/text/fonts.py +++ b/src/sliceitoff/text/fonts.py @@ -11,7 +11,7 @@ class Fonts: @staticmethod def load_fonts(base_path): """ loads fonts from list """ - filename_fontlist = os.path.join(base_path, "assets", "fonts.lst") + filename_fontlist = os.path.join(base_path, "fonts.lst") with open(filename_fontlist, "r", encoding="utf-8") as fontlist_file: for line in fontlist_file: name, *path = line.strip().split() |