猿问

如何制作蟒蛇游戏,扑腾鸟的烟斗出现?

我用Python构建的NEAT系统创建了一个Flappy Bird游戏,遵循YouTube上的本教程:技术与蒂姆


当我完成所有代码时,他运行它并使游戏正常运行,我的代码没有在屏幕上显示管道。我的代码如下:



import pygame, neat, time, os, random

##import all of the variables we'll need for AI running

pygame.font.init()

##enables using fonts/text on screen.

WIN_WIDTH = 500

WIN_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.




 

叮当猫咪
浏览 70回答 1
1回答

红糖糍粑

你已经缩进了太多次了。它应该是pipe.move()if pipe.x + pipe.PIPE_TOP.get_width() < 0:&nbsp;&nbsp; &nbsp; rem.append(pipe)pipe.move() #enable pipe movement.
随时随地看视频慕课网APP

相关分类

Python
我要回答