我用Python构建的NEAT系统创建了一个Flappy Bird游戏,遵循YouTube上的本教程:技术与蒂姆当我完成所有代码时,他运行它并使游戏正常运行,我的代码没有在屏幕上显示管道。我的代码如下:import pygame, neat, time, os, random##import all of the variables we'll need for AI runningpygame.font.init()##enables using fonts/text on screen.WIN_WIDTH = 500WIN_HEIGHT = 800##define the size of the window. We're working with a GUI for flappy bird AI.BIRD_IMGS = [pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bird1.png"))), pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bird2.png"))), pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bird3.png")))]##import the images of the bird from the images directory. There are three as to make up the states of flapping.PIPE_IMG = pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "pipe.png")))##import the texture for the pipes from the same directory.BASE_IMG = pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "base.png")))BG_IMG = pygame.transform.scale2x(pygame.image.load(os.path.join("imgs", "bg.png")))##repeat for the ground and the background. They are seperate pieces as to allow for handling the collision with the ground being death.STAT_FONT = pygame.font.SysFont("comicsans", 50)class Bird: ##define the bird and its system as a class. IMGS = BIRD_IMGS ##easier system for calling back to our list of bird images MAX_ROTATION = 25 ROT_VEL = 20 ANIMATION_TIME = 5 ##some definitions to do with making sure the bird can't just start spinning around aimlessly instead of looking like it should be going forward. def __init__(self, x, y): ##essentially telling the AI/game what the bird starts out as, and how to define each thing. self.x = x ##the distance forward on the screen self.y = y ##how high up on the screen the bird is self.tilt = 0 ##the angle the bird is at self.tick_count = 0 ##essentially handles all of the physics self.vel = 0 ##speed.
1 回答
红糖糍粑
TA贡献1815条经验 获得超6个赞
你已经缩进了太多次了。它应该是pipe.move()
if pipe.x + pipe.PIPE_TOP.get_width() < 0:
rem.append(pipe)
pipe.move() #enable pipe movement.
添加回答
举报
0/150
提交
取消