Return to repo list

gatemender

Arcade game about fixing warp gates. LibreJam Dec 2020 Entry.
Return to HMagellan.com

commit 70af09f6a71ab15437f1f310af9e58a98fbe6962
parent b093800183eb7195f6c35650f75ad3e525a72ab9
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon,  7 Dec 2020 13:33:05 -0600

added music from https://opengameart.org/content/5-chiptunes-action

Diffstat:
Adata/level3.ogg | 0
Adata/title_screen.ogg | 0
Mmain.py | 1+
Msrc/constants.py | 13+++++++++++++
Msrc/game.py | 11+++++++++++
5 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/data/level3.ogg b/data/level3.ogg Binary files differ. diff --git a/data/title_screen.ogg b/data/title_screen.ogg Binary files differ. diff --git a/main.py b/main.py @@ -2,6 +2,7 @@ import pygame from src import game pygame.init() +pygame.mixer.pre_init(44100, -16, 4, 1024) def main(): g1 = game.Game() diff --git a/src/constants.py b/src/constants.py @@ -36,6 +36,19 @@ IMAGE_FILES = { "Fix_Aura" : os.path.join("data", "fix_aura.png"), "Vortex" : os.path.join("data", "vortex.png") } +SOUND_FILES = { + "Main_Menu_Music" : os.path.join("data", "title_screen.ogg"), + "Game_Music" : os.path.join("data", "level3.ogg") + #"Shoot" : os.path.join("data", ""), + #"Fix" : os.path.join("data", ""), + #"Explode" : os.path.join("data", ""), + #"Damage" : os.path.join("data", ""), + #"Thrust" : os.path.join("data", ""), + #"Appear" : os.path.join("data", ""), + #"Click" : os.path.join("data", ""), + #"Pickup" : os.path.join("data", ""), + #"Flash" : os.path.join("data", "") +} FONTPATH = os.path.join("data", "computerspeak03.ttf") TURN_LEFT_KEY = pygame.K_a TURN_RIGHT_KEY = pygame.K_d diff --git a/src/game.py b/src/game.py @@ -18,6 +18,8 @@ class Game(object): # Loading self.images = { i : pygame.image.load(IMAGE_FILES[i]).convert() for i in IMAGE_FILES } self.keys = [ False for k in range(0, 256) ] + self.sounds = { s : pygame.mixer.Sound(SOUND_FILES[s]) for s in SOUND_FILES } + self.channels = [pygame.mixer.Channel(x) for x in range(0, pygame.mixer.get_num_channels() - 1)] # Game objects self.screen_draw_group = pygame.sprite.Group() @@ -138,8 +140,10 @@ class Game(object): def change_mode(self, mode): self.mode = mode + pygame.mixer.stop() if mode == MODES.Play: self.load_level() + self.play_sound("Game_Music", 0) elif mode == MODES.Transition: self.lives_text = self.font.render(str(self.lives), False, (255, 255, 255)) self.level_text = self.font.render("GATE " + str(self.level_factor), False, (255, 255, 255)) @@ -147,10 +151,17 @@ class Game(object): elif mode == MODES.GameOver: self.transition_timer = self.transition_timer_max elif mode == MODES.Menu: + self.play_sound("Main_Menu_Music", 0) self.lives = 2 self.score = 0 self.level_factor = 1 + def play_sound(self, soundname, channel = None, concurrent = True): + if channel != None and not self.channels[channel].get_busy(): + self.channels[channel].play(self.sounds[soundname]) + elif concurrent or self.sounds[soundname].get_num_channels() == 0: + self.sounds[soundname].play() + def render_hud(self): if self.mode == MODES.Play: self.num_alpha = self.font.render(str(self.ship.materials[MATERIALS.Alpha]), False, (255, 255, 255))