import sys
import pygame
# 小鸟类
class Bird():
def __init__(self):
self.birdRect = pygame.Rect(65, 50, 50, 50)
self.birdStatus = [pygame.image.load("assets/1.png"),
pygame.image.load("assets/2.png"),
pygame.image.load("assets/3.png")]
self.status = 0
self.birdX = 120
self.birdY = 350
self.jump = False
self.jumpSpeed = 10 # 按一下空格键跳跃的高度
self.gravity = 5 # 不按空格键小鸟下降的速度
self.dead = False
def birdUpdate(self):
if self.jump:
self.jumpSpeed -= 1 # 跳跃高度速度减一
self.birdY -= self.jumpSpeed # 改变小鸟高度
else:
self.gravity += 0.2 # 小鸟不跳跃增加下降速度
self.birdY += self.gravity
self.birdRect[1] = self.birdY # 更改Y轴位置
# 管道类
class Pipeline():
def __init__(self):
self.wallx = 400 # 初始的x坐标
self.pineUp = pygame.image.load("assets/top.png")
self.pineDown = pygame.image.load("assets/bottom.png")
def updatePipeline(self):
self.wallx -= 5
if self.wallx < -80:
global score
score = score + 1
self.wallx = 400
def createMap():
screen.fill(0,100 ,0)
screen.blit(background, (0,0))
pygame.display.update()
# 主函数
if __name__ == '__main__':
pygame.init() # 初始化
pygame.font.init() # 字体初始化
font = pygame.font.SysFont('ziti.ttf', 50) # 设置字体和大小哦
size = width, height = 400, 650 # 给宽和高赋值
screen = pygame.display.set_mode(size) # 设置屏幕大小
clock = pygame.time.Clock() # 设置时钟
Piepline = Pipeline() # 实例化一个管道的对象
Bird = Bird() # 实例化一个小鸟的对象
score = 0 # 分数
while True:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if (event.type == pygame.KEYDOWN) and not Bird.dead:
Bird.jump = True
Bird.gravity = 5
Bird.jumpSpeed = 10
background = pygame.image.load("assets/background.png")
# 1.检查生命状态
# if checkDead():
# getResul()
# else:
createMap()
# 2.小鸟是否死亡
# 3.创建地图
pygame.quit()
harr - bird
最新推荐文章于 2023-12-23 16:44:06 发布

1315

被折叠的 条评论
为什么被折叠?



