我正在制作一个Flappy Bird游戏,每次小鸟独自一人,框架中没有管道时,游戏的速度会快得多,我尝试了更低的屏幕分辨率,但它仍然是一样的。当小鸟在管道之间移动时,游戏速度是正常的,之后速度会变慢。
尺寸:背景-700x1000,鸟-100x56,管道-150x525,pipe_reversed-150x525
import pygame
import random
pygame.init()
win = pygame.display.set_mode((700, 1000))
pygame.display.set_caption("Flappy Bird")
pipe_x = 1000
pipe_y = 500
movement = 0
x = 200
y = 500
gravity = 3
rotation = 30
rv_pipe = pygame.image.load(r'pipe_reversed.png')
pipe = pygame.image.load(r'pipe.png')
bg = pygame.image.load(r'background.jpg')
bird = pygame.image.load(r'bird.png')
icon = pygame.image.load(r'icon.jpg')
pygame.display.set_icon(icon)
while True:
win.blit(bg, (0,0))
pygame.time.delay(1)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
keys = pygame.key.get_pressed()
if keys[pygame.K_ESCAPE]:
pygame.quit()
if event.type == pygame.KEYDOWN:
gravity -= 10
if rotation > 70:
rotation = 45
#gravity
gravity += 0.1
y += gravity
if gravity >= 4:
gravity = 4
if gravity <= -3:
gravity = -3
#rotation
if rotation >= 20:
rotation = 20
if rotation <= -90:
rotation = -90
if gravity < 0:
rotation += 2
if gravity > 1:
rotation -= 0.5
#pipe
pipe_x -= 1
if pipe_x == -150:
pipe_x = 700
bird2 = pygame.transform.rotate(bird, rotation)
print (gravity)
win.blit(pipe, (pipe_x, pipe_y))
win.blit(rv_pipe, (pipe_x, pipe_y - 700))
win.blit(bird2, (x, y))
pygame.display.update()
better您可以设置时钟滴答频率来解决这个问题