Add the ability to add an optional graphical logo for games. Tested with .png file.
This commit is contained in:
46
display.py
46
display.py
@@ -88,13 +88,55 @@ def initialize_gui(gameTitle):
|
|||||||
Speech.get_instance().speak("Error loading sounds.", False)
|
Speech.get_instance().speak("Error loading sounds.", False)
|
||||||
soundData = {}
|
soundData = {}
|
||||||
|
|
||||||
# Play intro sound if available
|
# Play intro sound if available, optionally with visual logo
|
||||||
from .sound import cut_scene
|
from .sound import cut_scene
|
||||||
if 'game-intro' in soundData:
|
if 'game-intro' in soundData:
|
||||||
cut_scene(soundData, 'game-intro')
|
_show_logo_with_audio(soundData, 'game-intro')
|
||||||
|
|
||||||
return soundData
|
return soundData
|
||||||
|
|
||||||
|
def _show_logo_with_audio(soundData, audioKey):
|
||||||
|
"""Show visual logo while playing audio intro.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
soundData (dict): Dictionary of loaded sounds
|
||||||
|
audioKey (str): Key of the audio to play
|
||||||
|
"""
|
||||||
|
# Look for logo image files in common formats
|
||||||
|
logoFiles = ['logo.png', 'logo.jpg', 'logo.jpeg', 'logo.gif', 'logo.bmp']
|
||||||
|
logoImage = None
|
||||||
|
|
||||||
|
for logoFile in logoFiles:
|
||||||
|
if os.path.exists(logoFile):
|
||||||
|
try:
|
||||||
|
logoImage = pygame.image.load(logoFile)
|
||||||
|
break
|
||||||
|
except pygame.error:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if logoImage:
|
||||||
|
# Display logo while audio plays
|
||||||
|
screen = pygame.display.get_surface()
|
||||||
|
screenRect = screen.get_rect()
|
||||||
|
logoRect = logoImage.get_rect(center=screenRect.center)
|
||||||
|
|
||||||
|
# Clear screen to black
|
||||||
|
screen.fill((0, 0, 0))
|
||||||
|
screen.blit(logoImage, logoRect)
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
# Play audio and wait for it to finish
|
||||||
|
from .sound import cut_scene
|
||||||
|
cut_scene(soundData, audioKey)
|
||||||
|
|
||||||
|
# Clear screen after audio finishes
|
||||||
|
screen.fill((0, 0, 0))
|
||||||
|
pygame.display.flip()
|
||||||
|
else:
|
||||||
|
# No logo image found, just play audio
|
||||||
|
from .sound import cut_scene
|
||||||
|
cut_scene(soundData, audioKey)
|
||||||
|
|
||||||
def display_text(text):
|
def display_text(text):
|
||||||
"""Display and speak text with navigation controls.
|
"""Display and speak text with navigation controls.
|
||||||
|
|
||||||
|
43
utils.py
43
utils.py
@@ -111,12 +111,51 @@ class Game:
|
|||||||
# Load sound effects
|
# Load sound effects
|
||||||
self.sound
|
self.sound
|
||||||
|
|
||||||
# Play intro sound if available
|
# Play intro sound if available, optionally with visual logo
|
||||||
if 'game-intro' in self.sound.sounds:
|
if 'game-intro' in self.sound.sounds:
|
||||||
self.sound.cut_scene('game-intro')
|
self._show_logo_with_audio('game-intro')
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def _show_logo_with_audio(self, audioKey):
|
||||||
|
"""Show visual logo while playing audio intro.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
audioKey (str): Key of the audio to play
|
||||||
|
"""
|
||||||
|
# Look for logo image files in common formats
|
||||||
|
logoFiles = ['logo.png', 'logo.jpg', 'logo.jpeg', 'logo.gif', 'logo.bmp']
|
||||||
|
logoImage = None
|
||||||
|
|
||||||
|
for logoFile in logoFiles:
|
||||||
|
if os.path.exists(logoFile):
|
||||||
|
try:
|
||||||
|
logoImage = pygame.image.load(logoFile)
|
||||||
|
break
|
||||||
|
except pygame.error:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if logoImage:
|
||||||
|
# Display logo while audio plays
|
||||||
|
screen = pygame.display.get_surface()
|
||||||
|
screenRect = screen.get_rect()
|
||||||
|
logoRect = logoImage.get_rect(center=screenRect.center)
|
||||||
|
|
||||||
|
# Clear screen to black
|
||||||
|
screen.fill((0, 0, 0))
|
||||||
|
screen.blit(logoImage, logoRect)
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
# Play audio and wait for it to finish
|
||||||
|
self.sound.cut_scene(audioKey)
|
||||||
|
|
||||||
|
# Clear screen after audio finishes
|
||||||
|
screen.fill((0, 0, 0))
|
||||||
|
pygame.display.flip()
|
||||||
|
else:
|
||||||
|
# No logo image found, just play audio
|
||||||
|
self.sound.cut_scene(audioKey)
|
||||||
|
|
||||||
def speak(self, text, interrupt=True):
|
def speak(self, text, interrupt=True):
|
||||||
"""Speak text using the speech system.
|
"""Speak text using the speech system.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user