mirror of
https://github.com/BreizhHardware/project_sanic.git
synced 2026-01-18 16:47:25 +01:00
Feat(Cinematic) - Update play_cinematic method to accept level name; ensure cinematic plays only for Level 1 and improve event handling during playback.
This commit is contained in:
@@ -28,61 +28,62 @@ class Cinematic:
|
||||
self.player_image = pygame.transform.scale(self.player_image, (200, 200))
|
||||
self.princess_image = pygame.transform.scale(self.princess_image, (200, 200))
|
||||
|
||||
def play_cinematic(self, game_resources):
|
||||
"""Play the cinematic for level 1"""
|
||||
def play_cinematic(self, game_resources, level_name):
|
||||
"""Play the cinematic for levels"""
|
||||
if Cinematic.has_played_level1:
|
||||
return
|
||||
|
||||
screen = game_resources.displaysurface
|
||||
font = pygame.font.Font(None, 36)
|
||||
lore_text = [
|
||||
"Once upon a time in a land far away...",
|
||||
"A brave hero named Sanic...",
|
||||
"And a beautiful princess named Zeldo...",
|
||||
"Has been captured by the evil boss...",
|
||||
"Wheatly !!!",
|
||||
"Sanic must rescue Zeldo...",
|
||||
]
|
||||
if level_name == "Level 1":
|
||||
screen = game_resources.displaysurface
|
||||
font = pygame.font.Font(None, 36)
|
||||
lore_text = [
|
||||
"Once upon a time in a land far away...",
|
||||
"A brave hero named Sanic...",
|
||||
"And a beautiful princess named Zeldo...",
|
||||
"Has been captured by the evil boss...",
|
||||
"Wheatly !!!",
|
||||
"Sanic must rescue Zeldo...",
|
||||
]
|
||||
|
||||
# Initialize the mixer
|
||||
pygame.mixer.init()
|
||||
cinematic_voice = pygame.mixer.Sound("assets/sound/cinematic_voice.mp3")
|
||||
# Initialize the mixer
|
||||
pygame.mixer.init()
|
||||
cinematic_voice = pygame.mixer.Sound("assets/sound/cinematic_voice.mp3")
|
||||
|
||||
screen.fill((0, 0, 0))
|
||||
for i, line in enumerate(lore_text):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.KEYDOWN:
|
||||
return # Skip the cinematic if any key is pressed
|
||||
screen.fill((0, 0, 0))
|
||||
for i, line in enumerate(lore_text):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.KEYDOWN:
|
||||
return # Skip the cinematic if any key is pressed
|
||||
|
||||
# Play the voice audio
|
||||
cinematic_voice.play()
|
||||
# Play the voice audio
|
||||
cinematic_voice.play()
|
||||
|
||||
if "Sanic" in line:
|
||||
screen.blit(self.player_image, (100, 400))
|
||||
if "Zeldo" in line:
|
||||
screen.blit(self.princess_image, (700, 400))
|
||||
if "Wheatly" in line:
|
||||
for _ in range(46):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.KEYDOWN:
|
||||
return # Skip the cinematic if any key is pressed
|
||||
if "Sanic" in line:
|
||||
screen.blit(self.player_image, (100, 400))
|
||||
if "Zeldo" in line:
|
||||
screen.blit(self.princess_image, (700, 400))
|
||||
if "Wheatly" in line:
|
||||
for _ in range(46):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.KEYDOWN:
|
||||
return # Skip the cinematic if any key is pressed
|
||||
|
||||
boss_frame = self.boss_frames[self.boss_frame_index]
|
||||
boss_frame = boss_frame.convert("RGBA")
|
||||
boss_frame = pygame.image.fromstring(
|
||||
boss_frame.tobytes(), boss_frame.size, boss_frame.mode
|
||||
)
|
||||
boss_frame = pygame.transform.scale(boss_frame, (200, 200))
|
||||
screen.blit(boss_frame, (400, 400))
|
||||
pygame.display.flip()
|
||||
pygame.time.wait(100)
|
||||
self.boss_frame_index = (self.boss_frame_index + 1) % len(
|
||||
self.boss_frames
|
||||
)
|
||||
boss_frame = self.boss_frames[self.boss_frame_index]
|
||||
boss_frame = boss_frame.convert("RGBA")
|
||||
boss_frame = pygame.image.fromstring(
|
||||
boss_frame.tobytes(), boss_frame.size, boss_frame.mode
|
||||
)
|
||||
boss_frame = pygame.transform.scale(boss_frame, (200, 200))
|
||||
screen.blit(boss_frame, (400, 400))
|
||||
pygame.display.flip()
|
||||
pygame.time.wait(100)
|
||||
self.boss_frame_index = (self.boss_frame_index + 1) % len(
|
||||
self.boss_frames
|
||||
)
|
||||
|
||||
text_surface = font.render(line, True, (255, 255, 255))
|
||||
screen.blit(text_surface, (50, 50 + i * 40))
|
||||
pygame.display.flip()
|
||||
pygame.time.wait(2000)
|
||||
cinematic_voice.stop()
|
||||
Cinematic.has_played_level1 = True
|
||||
text_surface = font.render(line, True, (255, 255, 255))
|
||||
screen.blit(text_surface, (50, 50 + i * 40))
|
||||
pygame.display.flip()
|
||||
pygame.time.wait(2000)
|
||||
cinematic_voice.stop()
|
||||
Cinematic.has_played_level1 = True
|
||||
|
||||
@@ -46,7 +46,7 @@ class MapParser:
|
||||
|
||||
# If it's level 1, play the cinematic
|
||||
if map_data.get("name") == "Level 1" and not self.cinematic_played:
|
||||
self.cinematic.play_cinematic(self.game_resources)
|
||||
self.cinematic.play_cinematic(self.game_resources, map_data.get("name"))
|
||||
self.cinematic_played = True
|
||||
|
||||
# Create all game objects from map data
|
||||
|
||||
Reference in New Issue
Block a user