summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-04-26 12:08:06 +0300
committerViljami Ilola <+@hix.fi>2024-04-26 12:08:06 +0300
commit54a17d969c85e150486e0960e90ab166e945c359 (patch)
treef76e57dddb2ad92fc043c48ea1bb118207b06c73
parent2d94bb60ff2fea09097d0e33dfd8b92aeef55531 (diff)
initial music
-rw-r--r--README.txt2
-rw-r--r--src/sliceitoff/assets/COPYRIGHTS.txt12
-rw-r--r--src/sliceitoff/assets/glass.mp3bin0 -> 30120 bytes
-rw-r--r--src/sliceitoff/assets/laser.mp3bin84622 -> 30000 bytes
-rw-r--r--src/sliceitoff/assets/pimpelipompeli.mp3bin0 -> 4869196 bytes
-rw-r--r--src/sliceitoff/assets/uhkapeli.mp3bin0 -> 6083664 bytes
-rw-r--r--src/sliceitoff/game/explodeout.py2
-rw-r--r--src/sliceitoff/game/game.py2
-rw-r--r--src/sliceitoff/game/level.py3
-rw-r--r--src/sliceitoff/game/mainmenu.py2
-rw-r--r--src/sliceitoff/sfx/sfx.py18
11 files changed, 39 insertions, 2 deletions
diff --git a/README.txt b/README.txt
index 06475b4..e3edc42 100644
--- a/README.txt
+++ b/README.txt
@@ -18,7 +18,7 @@ Installing:
License:
This project uses GPL-2 license. Assets have their licenses listed
- on `src/sliceitoff*/assets/LICENSES.txt`.
+ on `src/sliceitoff/assets/COPYRIGHTS.txt`.
Developement:
diff --git a/src/sliceitoff/assets/COPYRIGHTS.txt b/src/sliceitoff/assets/COPYRIGHTS.txt
index 07e9741..6c3c66b 100644
--- a/src/sliceitoff/assets/COPYRIGHTS.txt
+++ b/src/sliceitoff/assets/COPYRIGHTS.txt
@@ -1,6 +1,16 @@
*.fnt:
+
https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/gnufonts.html
GNU General Public License, Version 2
-laser.mp3:
+
+laser.mp3, glass.mp3:
+
Samples from pixabay. Pixabay & Charlie_Raven. Edited by me.
+
+
+pimpelipompeli.mp3, uhkapeli.mp3:
+
+ Music by me, Viljami Ilola (@vililola). Free to copy. Attribution
+ nice, but not necessary.
+
diff --git a/src/sliceitoff/assets/glass.mp3 b/src/sliceitoff/assets/glass.mp3
new file mode 100644
index 0000000..834adb0
--- /dev/null
+++ b/src/sliceitoff/assets/glass.mp3
Binary files differ
diff --git a/src/sliceitoff/assets/laser.mp3 b/src/sliceitoff/assets/laser.mp3
index 790b60e..2b26661 100644
--- a/src/sliceitoff/assets/laser.mp3
+++ b/src/sliceitoff/assets/laser.mp3
Binary files differ
diff --git a/src/sliceitoff/assets/pimpelipompeli.mp3 b/src/sliceitoff/assets/pimpelipompeli.mp3
new file mode 100644
index 0000000..24acf07
--- /dev/null
+++ b/src/sliceitoff/assets/pimpelipompeli.mp3
Binary files differ
diff --git a/src/sliceitoff/assets/uhkapeli.mp3 b/src/sliceitoff/assets/uhkapeli.mp3
new file mode 100644
index 0000000..cfc809c
--- /dev/null
+++ b/src/sliceitoff/assets/uhkapeli.mp3
Binary files differ
diff --git a/src/sliceitoff/game/explodeout.py b/src/sliceitoff/game/explodeout.py
index 34bd9fe..6cebec5 100644
--- a/src/sliceitoff/game/explodeout.py
+++ b/src/sliceitoff/game/explodeout.py
@@ -1,6 +1,7 @@
""" game.explodeout - For showing explogind effect and waiting for a key """
import pygame
+from sliceitoff.sfx import sfx
from .anykey import anykey
class ExplodeOutGroup(pygame.sprite.Group):
@@ -31,4 +32,5 @@ class ExplodeOutGroup(pygame.sprite.Group):
def do_fadeout(self):
""" Just kicks off exploding phase """
+ sfx.play("glass")
self.explode = True
diff --git a/src/sliceitoff/game/game.py b/src/sliceitoff/game/game.py
index a5009c5..c6a5fe0 100644
--- a/src/sliceitoff/game/game.py
+++ b/src/sliceitoff/game/game.py
@@ -47,6 +47,7 @@ class Game:
def show_highscores(self):
""" displays highscores and waits a key """
+ sfx.music("pimpelipompeli")
his = Show(hiscores_screen(str(self.hiscores)))
while his.active:
his.update(dt = self.clock.tick())
@@ -73,6 +74,7 @@ class Game:
def mainmenu(self):
""" menu where one select what to do """
+ sfx.music("pimpelipompeli")
menu = Mainmenu()
while menu.active:
menu.update(dt = self.clock.tick())
diff --git a/src/sliceitoff/game/level.py b/src/sliceitoff/game/level.py
index c3713ce..9f3121f 100644
--- a/src/sliceitoff/game/level.py
+++ b/src/sliceitoff/game/level.py
@@ -6,6 +6,7 @@ from sliceitoff.player import Player, Life
from sliceitoff.field import Field
from sliceitoff.enemies import Enemies
from sliceitoff.screens import levelup_screen, gameover_screen, level_screen
+from sliceitoff.sfx import sfx
from .gameplay import Gameplay
from .show import Show
@@ -32,6 +33,8 @@ class Level(pygame.sprite.Group):
stats = self.stats,
life = self.life)
+ sfx.music("uhkapeli")
+
def update(self, dt = 0):
""" Updates groups, calls gameplay and adds sprites for drawing """
self.empty()
diff --git a/src/sliceitoff/game/mainmenu.py b/src/sliceitoff/game/mainmenu.py
index edb1594..f9a70e0 100644
--- a/src/sliceitoff/game/mainmenu.py
+++ b/src/sliceitoff/game/mainmenu.py
@@ -4,6 +4,7 @@ import pygame
from sliceitoff.screens import mainmenu_screen
from sliceitoff.display import Scaling
+from sliceitoff.sfx import sfx
from .explodeout import ExplodeOutGroup
@@ -63,6 +64,7 @@ class Mainmenu(ExplodeOutGroup):
case pygame.K_ESCAPE | pygame.K_q | pygame.K_LEFT:
self.selection = MenuItems.QUIT
self.do_fadeout()
+ sfx.music(None)
return True
case pygame.K_UP:
self.selection -= 1
diff --git a/src/sliceitoff/sfx/sfx.py b/src/sliceitoff/sfx/sfx.py
index 15dd1a6..fd494b8 100644
--- a/src/sliceitoff/sfx/sfx.py
+++ b/src/sliceitoff/sfx/sfx.py
@@ -1,12 +1,16 @@
""" sfx.sfx - pygame.mixer initialization and sound effects handling """
+import os
from pathlib import Path
import pygame
+DEBUG = os.getenv("DEBUG")
+
class Sfx:
""" Sound Effects and Music? """
def __init__(self):
self.initialized = False
self.sound = {}
+ self.bgm = None
try:
pygame.mixer.pre_init(channels=2, buffer=512, frequency=48000)
except pygame.error:
@@ -20,6 +24,8 @@ class Sfx:
self.initialized = True
for mp3_file in Path(base_path).glob('*.mp3'):
self.sound[str(mp3_file.stem)] = pygame.mixer.Sound(mp3_file)
+ if DEBUG:
+ print("Loading sound:", mp3_file, str(mp3_file.stem))
except pygame.error:
pass
@@ -28,6 +34,18 @@ class Sfx:
if self.initialized:
self.sound[sample].play()
+ def music(self, music):
+ """ Plays sample as music. There is only one music at the time """
+ if not self.initialized:
+ return
+ if self.bgm == music:
+ return
+ if self.bgm:
+ self.sound[self.bgm].fadeout(500)
+ self.bgm = music
+ if self.bgm:
+ self.sound[self.bgm].play()
+
# Initialize only one time
try:
# pylint: disable = used-before-assignment