@@ -81,43 +81,47 @@ def load_images(bg_type: str = "day",
8181 """ Loads and returns the image assets of the game. """
8282 images = {}
8383
84- # Sprites with the number for the score display:
85- images ["numbers" ] = tuple ([
86- pyg_image .load (f"{ SPRITES_PATH } /{ n } .png" ).convert_alpha ()
87- for n in range (10 )
88- ])
89-
90- # Game over sprite:
91- images ["gameover" ] = pyg_image .load (
92- f"{ SPRITES_PATH } /gameover.png" ).convert_alpha ()
93-
94- # Welcome screen message sprite:
95- images ["message" ] = pyg_image .load (
96- f"{ SPRITES_PATH } /message.png" ).convert_alpha ()
97-
98- # Sprite for the base (ground):
99- images ["base" ] = pyg_image .load (
100- f"{ SPRITES_PATH } /base.png" ).convert_alpha ()
101-
102- # Background sprite:
103- images ["background" ] = pyg_image .load (
104- f"{ SPRITES_PATH } /background-{ bg_type } .png" ).convert ()
105-
106- # Bird sprites:
107- images ["player" ] = (
108- pyg_image .load (
109- f"{ SPRITES_PATH } /{ bird_color } bird-upflap.png" ).convert_alpha (),
110- pyg_image .load (
111- f"{ SPRITES_PATH } /{ bird_color } bird-midflap.png" ).convert_alpha (),
112- pyg_image .load (
113- f"{ SPRITES_PATH } /{ bird_color } bird-downflap.png" ).convert_alpha (),
114- )
115-
116- # Pipe sprites:
117- pipe_sprite = pyg_image .load (
118- f"{ SPRITES_PATH } /pipe-{ pipe_color } .png" ).convert_alpha ()
119- images ["pipe" ] = (img_flip (pipe_sprite , False , True ),
120- pipe_sprite )
84+ try :
85+ # Sprites with the number for the score display:
86+ images ["numbers" ] = tuple ([
87+ pyg_image .load (f"{ SPRITES_PATH } /{ n } .png" ).convert_alpha ()
88+ for n in range (10 )
89+ ])
90+
91+ # Game over sprite:
92+ images ["gameover" ] = pyg_image .load (
93+ f"{ SPRITES_PATH } /gameover.png" ).convert_alpha ()
94+
95+ # Welcome screen message sprite:
96+ images ["message" ] = pyg_image .load (
97+ f"{ SPRITES_PATH } /message.png" ).convert_alpha ()
98+
99+ # Sprite for the base (ground):
100+ images ["base" ] = pyg_image .load (
101+ f"{ SPRITES_PATH } /base.png" ).convert_alpha ()
102+
103+ # Background sprite:
104+ images ["background" ] = pyg_image .load (
105+ f"{ SPRITES_PATH } /background-{ bg_type } .png" ).convert ()
106+
107+ # Bird sprites:
108+ images ["player" ] = (
109+ pyg_image .load (
110+ f"{ SPRITES_PATH } /{ bird_color } bird-upflap.png" ).convert_alpha (),
111+ pyg_image .load (
112+ f"{ SPRITES_PATH } /{ bird_color } bird-midflap.png" ).convert_alpha (),
113+ pyg_image .load (
114+ f"{ SPRITES_PATH } /{ bird_color } bird-downflap.png" ).convert_alpha (),
115+ )
116+
117+ # Pipe sprites:
118+ pipe_sprite = pyg_image .load (
119+ f"{ SPRITES_PATH } /pipe-{ pipe_color } .png" ).convert_alpha ()
120+ images ["pipe" ] = (img_flip (pipe_sprite , False , True ),
121+ pipe_sprite )
122+ except FileNotFoundError as ex :
123+ raise FileNotFoundError ("Can't find the sprites folder! No such file or"
124+ f" directory: { SPRITES_PATH } " ) from ex
121125
122126 return images
123127
@@ -132,10 +136,14 @@ def load_sounds() -> Dict[str, pyg_mixer.Sound]:
132136 else :
133137 soundExt = ".ogg"
134138
135- sounds ["die" ] = pyg_mixer .Sound (AUDIO_PATH + "/die" + soundExt )
136- sounds ["hit" ] = pyg_mixer .Sound (AUDIO_PATH + "/hit" + soundExt )
137- sounds ["point" ] = pyg_mixer .Sound (AUDIO_PATH + "/point" + soundExt )
138- sounds ["swoosh" ] = pyg_mixer .Sound (AUDIO_PATH + "/swoosh" + soundExt )
139- sounds ["wing" ] = pyg_mixer .Sound (AUDIO_PATH + "/wing" + soundExt )
139+ try :
140+ sounds ["die" ] = pyg_mixer .Sound (AUDIO_PATH + "/die" + soundExt )
141+ sounds ["hit" ] = pyg_mixer .Sound (AUDIO_PATH + "/hit" + soundExt )
142+ sounds ["point" ] = pyg_mixer .Sound (AUDIO_PATH + "/point" + soundExt )
143+ sounds ["swoosh" ] = pyg_mixer .Sound (AUDIO_PATH + "/swoosh" + soundExt )
144+ sounds ["wing" ] = pyg_mixer .Sound (AUDIO_PATH + "/wing" + soundExt )
145+ except FileNotFoundError as ex :
146+ raise FileNotFoundError ("Can't find the audio folder! No such file or "
147+ f"directory: { AUDIO_PATH } " ) from ex
140148
141149 return sounds
0 commit comments