python编写呆呆小鸟程序bird.py

时间:2021-11-10 22:47:58
【文件属性】:

文件名称:python编写呆呆小鸟程序bird.py

文件大小:3KB

文件格式:PY

更新时间:2021-11-10 22:47:58

python python游戏

####################引用数据库与函数###################### import pygame from random import randrange pygame.init() from time import sleep ######################定义变量########################### frame = 0 #当前在0帧处 map_width = 284 map_height = 512 #因为图片大小是284*512的 FPS = 60 pipes = [[200,4]] bird = [40,map_height//2-50] gravity = 0.2 velocity = 0 gameScreen = pygame.display.set_mode((map_width,map_height)) clock = pygame.time.Clock() bird_wing_up = bird_wing_up_copy = pygame.image.load("images/bird_wing_up.png") bird_wing_down = bird_wing_down_copy = pygame.image.load("images/bird_wing_down.png") background = pygame.image.load("images/background.png") pipe_body = pygame.image.load("images/pipe_body.png") pipe_end = pygame.image.load("images/pipe_end.png") #######################定义函数########################## def draw_pipes(): global pipes for n in range(len(pipes)): for m in range(pipes[n][1]): gameScreen.blit(pipe_body,(pipes[n][0],m*32))#一个小管子的高度是32 for m in range(pipes[n][1]+6,16): gameScreen.blit(pipe_body, (pipes[n][0], m * 32)) gameScreen.blit(pipe_end,(pipes[n][0],pipes[n][1] * 32)) gameScreen.blit(pipe_end,(pipes[n][0],(pipes[n][1]+5) * 32)) pipes[n][0] -= 1 def draw_bird(x,y): global frame if 0<= frame < 30: gameScreen.blit(bird_wing_up, (x, y)) frame += 1 elif 30<= frame <=60: gameScreen.blit(bird_wing_down, (x, y)) frame += 1 if frame == 60: frame = 0 def safe(): if bird[1]>map_height-35: print('you die ! fw') return False if bird[1] < 0: print('you die ! fw') return False if pipes[0][0]-30 < bird[0] < pipes[0][0]+79 : if bird[1]<(pipes[0][1]+1)*32 or bird[1]>(pipes[0][1]+4)*32: print("You die ! fw") return False return True def reset(): global bird,velocity, gravity, bird_wing_down, bird_wing_up, frame, map_width, map_height, FPS, pipes


网友评论