[Pygame] Explain in detail the development of the Flappy Bird game

Load material (picture, sound effect)

Method 1:

# load image

Picture = pygame.image.load(“picture.png”)

# load music

Sound = pygame.mixer.Sound(sound.wav)

Call sound.play() to play the sound effect.

Method 2:

Use python's dictionary to look up pictures.

Use python's built-in module os (operating system) to provide some usage related to the operating system, use the os.listdir method to list all the files in the folder, and use os.splitext to split the file name and suffix. File name + suffix ("bird"+".png"), use os.path.join to join the file path, and finally use pygame to load the picture.

The filename of each image is the key used to look up in the dictionary, and the value is the image loaded by pygame.

Guess you like

Origin blog.csdn.net/laaa123mmm/article/details/128739049
Recommended