diff options
author | Viljami Ilola <+@hix.fi> | 2024-04-20 22:09:23 +0300 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-04-20 22:09:23 +0300 |
commit | f4a064c1f36c7ab7993b30832dea386e4b79b49d (patch) | |
tree | a5ae7ff69f4959f09f47cb9fddc0dddb6c5c0f8e | |
parent | b9b64aa313a45ab53f856242b4ce5ddb151533fb (diff) |
sample loading and laser sound
-rw-r--r-- | pyproject.toml | 2 | ||||
-rw-r--r-- | src/sliceitoff/assets/laser.mp3 | bin | 0 -> 84622 bytes | |||
-rw-r--r-- | src/sliceitoff/game/gameplay.py | 2 | ||||
-rw-r--r-- | src/sliceitoff/sfx/sfx.py | 9 |
4 files changed, 12 insertions, 1 deletions
diff --git a/pyproject.toml b/pyproject.toml index 1920306..7b3d96e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sliceitoff" -version = "0.3-beta.4" +version = "0.3-beta.5" description = "Arcade game where one slices play area off while avoiding slicing happy faces." repository = "https://git.hix.fi/sliceitoff.git/" authors = ["Viljami Ilola <+@hix.fi>"] diff --git a/src/sliceitoff/assets/laser.mp3 b/src/sliceitoff/assets/laser.mp3 Binary files differnew file mode 100644 index 0000000..790b60e --- /dev/null +++ b/src/sliceitoff/assets/laser.mp3 diff --git a/src/sliceitoff/game/gameplay.py b/src/sliceitoff/game/gameplay.py index 49ff026..c756183 100644 --- a/src/sliceitoff/game/gameplay.py +++ b/src/sliceitoff/game/gameplay.py @@ -1,5 +1,6 @@ """ Reads user input and does actions when game play is on. """ import pygame +from sliceitoff.sfx import sfx class Gameplay: """ Logic of the playfield """ @@ -25,6 +26,7 @@ class Gameplay: if not zap_sprite: return False self.stats.add_score(-500) + sfx.play("laser") if pygame.sprite.spritecollideany(zap_sprite, self.enemies): self.life.lose_life() if self.stats.lose_life(): diff --git a/src/sliceitoff/sfx/sfx.py b/src/sliceitoff/sfx/sfx.py index f9347df..15dd1a6 100644 --- a/src/sliceitoff/sfx/sfx.py +++ b/src/sliceitoff/sfx/sfx.py @@ -1,10 +1,12 @@ """ sfx.sfx - pygame.mixer initialization and sound effects handling """ +from pathlib import Path import pygame class Sfx: """ Sound Effects and Music? """ def __init__(self): self.initialized = False + self.sound = {} try: pygame.mixer.pre_init(channels=2, buffer=512, frequency=48000) except pygame.error: @@ -16,9 +18,16 @@ class Sfx: try: pygame.mixer.init() self.initialized = True + for mp3_file in Path(base_path).glob('*.mp3'): + self.sound[str(mp3_file.stem)] = pygame.mixer.Sound(mp3_file) except pygame.error: pass + def play(self, sample): + """ Just plays named sample loaded from assets directory """ + if self.initialized: + self.sound[sample].play() + # Initialize only one time try: # pylint: disable = used-before-assignment |