代码如下:
import pygame
import sys
import random
class Bird(object):
'''定义一个小鸟类'''
def __init__(self):
'''定义初始化方法'''
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 #self.birdY = self.birdY - self.jumpSpeed
else:
self.gravity += 0.2
self.birdY += self.gravity
self.birdRect[1] = self.birdY
class Pipeline(object):
def __init__(self):
pass
def updatePipeline(self):
pass
def createMap():
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,650
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()
pygame.quit()
把代码检查了几遍,都没有发现错误 不知道咋回事