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)):
       
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
####################引用数据库与函数###################### 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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值