私は現在、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()
私はこのコードと 1 週間以上格闘してきました。