Introduction:

Go to work to touch fish have to play games!

If there is no

Then you certainly didn’t play a falling bird game

But it doesn’t matter

Muzi here is an enlarged picture for you to have an eye addiction:

​​

Look at this interface, it really smells like app game software!

This is a game that can be played by both adults and children

Really knock simple! Just click the space to start and then click the space to go through the pipe.

Of course… Xiaobian can only spread over 10 pipe pillars! I can’t take any more.

That’s because xiaobian set the speed fast ~~ more challenging ~ slow hand speed can also slow down a little sa!!

The body of the

Rules of the game: the birds need to smoothly avoid the pipe, can not collide, or it will show 0, updated birds to the first level again,

How many points will show how many points, to test your reflexes to play the game

Environmental installation:

import cfg
import sys
import random
import pygame
Copy the code

Import required image materials, set music, etc. :

Def main(): screen = initGame() # import audio sounds = dict() for key, value in cfg.audio_paths.items (): Sounds [key] = pygame.mixer.sound (value) # value in cfg.NUMBER_IMAGE_PATHS.items(): Number_images [key] = pygame.image.load(value).convert_alpha() # -- pipe_images = dict() pipe_images['bottom'] = pygame.image.load(random.choice(list(cfg.PIPE_IMAGE_PATHS.values()))).convert_alpha() pipe_images['top'] = Rotate (pipe_images['bottom'], 180) # -- Bird_images = dict() for key, value in cfg.BIRD_IMAGE_PATHS[random.choice(list(cfg.BIRD_IMAGE_PATHS.keys()))].items(): Bird_images [key] = pygame.image.load(value).convert_alpha() # -- backgroud_image = Pygame.image.load (random.choice(list(cfg.background_image_paths.values ()))). Convert_alpha () # -- other_images = dict() for key, value in cfg.OTHER_IMAGE_PATHS.items(): other_images[key] = pygame.image.load(value).convert_alpha()Copy the code

Since there is a pipeline that game need to score clearance is certainly not to meet the pipeline, meet directly update the bird in the restart.

# -- Collider for pipe in Pipe_sprites: If Pygame.sprite. Collide_mask (bird, pipe): Sounds ['hit']. Play () is_game_running = False # base_pos[-1]] is_dead = bird.update(boundary_values, float(clock.tick(cfg.FPS))/1000.) if is_dead: sounds['hit'].play() is_game_running = FalseCopy the code

Game start and end interface:

​​​​

Def startGame(screen, sounds, bird_images, other_images, backgroud_image, CFG): base_pos = [0, CFG.SCREENHEIGHT*0.79] base_diff_bg = other_images['base'].get_width() -backgroud_image.get_width () msg_pos = [(cfg.SCREENWIDTH-other_images['message'].get_width())/2, CFG.SCREENHEIGHT*0.12] bird_idx = 0 bird_idx_change_count = 0 bird_idx_cycle = itertools.cycle([0, 1, 2, 1]) bird_pos = [CFG SCREENWIDTH * 0.2, (cfg.SCREENHEIGHT-list(bird_images.values())[0].get_height())/2] bird_y_shift_count = 0 bird_y_shift_max = 9 shift = 1 clock = pygame.time.Clock() while True: for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_UP: return {'bird_pos': bird_pos, 'base_pos': base_pos, 'bird_idx': bird_idx} sounds['wing'].play() bird_idx_change_count += 1 if bird_idx_change_count % 5 == 0: bird_idx = next(bird_idx_cycle) bird_idx_change_count = 0 base_pos[0] = -((-base_pos[0] + 4) % base_diff_bg) bird_y_shift_count += 1 if bird_y_shift_count == bird_y_shift_max: bird_y_shift_max = 16 shift = -1 * shift bird_y_shift_count = 0 bird_pos[-1] = bird_pos[-1] + shift screen.blit(backgroud_image, (0, 0)) screen.blit(list(bird_images.values())[bird_idx], bird_pos) screen.blit(other_images['message'], msg_pos) screen.blit(other_images['base'], Base_pos) pygame.display.update() clock.tick(cfg.fps) def endGame(screen, sounds, showScore, score, number_images, bird, pipe_sprites, backgroud_image, other_images, base_pos, cfg): sounds['die'].play() clock = pygame.time.Clock() while True: for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_UP: return boundary_values = [0, base_pos[-1]] bird.update(boundary_values, float(clock.tick(cfg.FPS))/1000.) screen.blit(backgroud_image, (0, 0)) pipe_sprites.draw(screen) screen.blit(other_images['base'], base_pos) showScore(screen, score, number_images) bird.draw(screen) pygame.display.update() clock.tick(cfg.FPS)Copy the code

conclusion

New fans of falling Birds! Are there more than 66 pipe columns? Looking forward to JPG.

Xiaobian will continue to make persistent efforts to seek welfare for everyone! Remember triple Company oh your support is my motivation, Ollie to

Source code base: #959755565# Free project source code!!

                     

Welcome to previous articles:

1. Idiom Solitaire game project. 2. Tower Defense game project. 3. Memorizing card flip items. 4. Pac Man mini game project.

5. Alien invasion game project. 6. Count your game items. 7. Brain exercise games. 8. Garbage classification mini game project.

9. Thunder Fighter Game project. 10. My Rabbit game project. 11. Eight-note game project. 12. Jigsaw puzzle project.

13. Ski games. 14. Desktop pet projects. 15. Invincible little golden dinosaur. 16. Tank Wars game item.

17. Maze running project.

. Stay tuned for more at………..

Need before the game source code is also free to share ha, the need for private xiaobian!