猿问

我的代码没有显示错误,但现在我的 flappybird cosde 应该每 1.2 秒打印一次这个词

我的代码没有显示错误,但现在我的 flappybird cosde 应该每 1.2 秒打印一次管道一词,但事实并非如此,我不知道如何修复它,并检查了我代码中的每个单词,我什至重新编写了它 onec can有人请帮我编码:


import pygame, sys


def draw_floor():

    screen.blit(floor_surface, (floor_animation, 400))

    screen.blit(floor_surface, (floor_animation + 275,400))


pygame.init()


screen = pygame.display.set_mode((275,512))

clock = pygame.time.Clock()


gravity = 0.25

bird_movement = 0


bg_surface = pygame.image.load('C:/Users/cuerv/Downloads/flappy-bird-assets-master/flappy-bird-assets-master/sprites/background-day.png').convert()


floor_surface = pygame.image.load('C:/Users/cuerv/Downloads/flappy-bird-assets-master/flappy-bird-assets-master/sprites/base.png').convert()

floor_animation = 0


bird_surface = pygame.image.load('C:/Users/cuerv/Downloads/flappy-bird-assets-master/flappy-bird-assets-master/sprites/bluebird-midflap.png').convert()

bird_rect = bird_surface.get_rect(center = (100,256))


pipe_surface = pygame.image.load('C:/Users/cuerv/Downloads/flappy-bird-assets-master/flappy-bird-assets-master/sprites/pipe-green.png').convert()

pipe_list = []

SPAWNPIPE = pygame.USEREVENT

pygame.time.set_timer(SPAWNPIPE,1200)


while True:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            pygame.quit()       

            sys.exit()

        if event.type == pygame.KEYDOWN:

            if event.key == pygame.K_SPACE:

                bird_movement = 0

                bird_movement -= 7

                if event.type == SPAWNPIPE:

                    print("pipe")                   


    screen.blit(bg_surface, (0, 0))


    bird_movement += gravity

    bird_rect.centery += bird_movement

    screen.blit(bird_surface, (bird_rect))

    

    floor_animation -= 1

    draw_floor()

 

    if floor_animation <= -275:     #if floor = if the left surface is too to the left we are going to do soamething

        floor_animation = 0

    screen.blit(floor_surface, (floor_animation, 400))


    pygame.display.update()

    clock.tick(120)


LEATH
浏览 108回答 1
1回答

神不在的星期二

发生这种情况是因为您对SPAWNPIPE事件的检查在事件的检查范围内KEYDOWN。这可以通过以下方法解决:if event.type == pygame.KEYDOWN:&nbsp; &nbsp; if event.key == pygame.K_SPACE:&nbsp; &nbsp; &nbsp; &nbsp; bird_movement = 0&nbsp; &nbsp; &nbsp; &nbsp; bird_movement -= 7if event.type == SPAWNPIPE:&nbsp; &nbsp; print("pipe")
随时随地看视频慕课网APP

相关分类

Python
我要回答