【发布时间】:2014-02-14 17:57:56
【问题描述】:
我目前正在使用 Python 3.2 在 Pygame 中重新制作“Flappy Bird”。我认为这对练习很有用,而且相对简单。然而,事实证明这很难。目前,我在绘制不同高度的矩形但将矩形保持在设置的高度时遇到问题。
这是我的管道类
class Pipe:
def __init__(self,x):
self.drawn = True
self.randh = random.randint(30,350)
self.rect = Rect((x,0),(30,self.randh))
def update(self):
self.rect.move_ip(-2,0)
def draw(self,screen):
self.drawn = True
pygame.draw.rect(screen,(0,130,30),self.rect)
我的while循环如下:
while True:
for event in pygame.event.get():
movey = +0.8
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key == K_SPACE:
movey = -2
x += movex
y += movey
screen.blit(background,(0,0))
screen.blit(bird,(x,y))
Pipe1 = Pipe(scrollx)
if Pipe1.drawn == True:
Pipe1.update()
else:
Pipe1 = Pipe(scrollx)
Pipe1.draw(screen)
scrollx -= 0.3
pygame.display.update()
我已经为此代码苦苦挣扎了一个多星期,非常感谢您提供的任何帮助。
【问题讨论】:
-
到底是什么问题?
标签: python pygame python-3.2 flappy-bird-clone