import pygame
import sys
import random
class Bird(object):
"""定义一个鸟类"""
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/dead.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
class Pipeline(object):
"""定义一个管道类"""
def __init__(self):
"""定义初始化方法"""
pass
def updatePipeline(self):
"""水平移动"""
pass
def createMap(screen, background):
"""定义创建地图的方法"""
screen.fill((255, 255, 255))
screen.blit(background, (0, 0))
if Bird.dead:
Bird.status = 2
elif Bird.jump:
Bird.status = 1
screen.blit(Bird.birdStatus[Bird.status], (Bird.birdX, Bird.birdY))
Bird.birdUpdate()
pygame.display.update()
if __name__ == "__main__":
"""主程序"""
pygame.init()
size = width, height = 400, 720
screen = pygame.display.set_mode(size)
clock = pygame.time.Clock()
Pipeline = Pipeline()
Bird = Bird()
while True:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if (event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN) and not Bird.dead:
Bird.jump = True
Bird.gravity = 5
Bird.jumpSpeed = 10
background = pygame.image.load("assets/background.png")
createMap(screen, background)
pygame.quit()