Add the ability to add an optional graphical logo for games. Tested with .png file.
This commit is contained in:
43
utils.py
43
utils.py
@@ -111,12 +111,51 @@ class Game:
|
||||
# Load sound effects
|
||||
self.sound
|
||||
|
||||
# Play intro sound if available
|
||||
# Play intro sound if available, optionally with visual logo
|
||||
if 'game-intro' in self.sound.sounds:
|
||||
self.sound.cut_scene('game-intro')
|
||||
self._show_logo_with_audio('game-intro')
|
||||
|
||||
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):
|
||||
"""Speak text using the speech system.
|
||||
|
||||
|
Reference in New Issue
Block a user