Python TypeError:int()参数必须是字符串、类似字节的对象或数字,而不是';非类型';。但是我写了int()

Python TypeError:int()参数必须是字符串、类似字节的对象或数字,而不是';非类型';。但是我写了int(),python,pygame,flappy-bird-clone,Python,Pygame,Flappy Bird Clone,我上传了一整段代码,我确信问题出在“def score_display”上,我做的和作者做的完全一样。但我得到的信息是错误的。在开始的时候,代码运行得很好,当我摔倒时,我犯错误的函数应该被实现,然后游戏中断并给出这个错误。谢谢(关于语法很抱歉) 导入pygame 导入系统,随机 def floor_repeation(): win.blit(地板表面,(地板x位置,588)) win.blit(地板表面,(地板x位置+576588)) def create_pipe(): 随机管道位置=随机选择

我上传了一整段代码,我确信问题出在“def score_display”上,我做的和作者做的完全一样。但我得到的信息是错误的。在开始的时候,代码运行得很好,当我摔倒时,我犯错误的函数应该被实现,然后游戏中断并给出这个错误。谢谢(关于语法很抱歉)

导入pygame
导入系统,随机
def floor_repeation():
win.blit(地板表面,(地板x位置,588))
win.blit(地板表面,(地板x位置+576588))
def create_pipe():
随机管道位置=随机选择(管道高度)
底部管道=管道表面。获取直线(中顶部=(700,随机管道位置))
顶部管道=管道表面。获取直线(中间底部=(700,随机管道位置-170))
返回底部管道,顶部管道
def移动_管道(管道):
对于管道中的管道:
管道中心X-=5
回流管
def牵引管(管道):
对于管道中的管道:
如果管道底部>=588:
win.blit(管道表面、管道)
其他:
flip\u pipe=pygame.transform.flip(pipe\u surface,False,True)
win.blit(翻转管道,管道)
def检查碰撞(管道):
对于管道中的管道:
如果bird_.Collide rect(管道):
死亡之声
返回错误
如果bird_rect.top=588:
返回错误
返回真值
def旋转鸟(bird1):
新鸟=pygame.transform.rotozoom(鸟1,-鸟移动*3,1)
归还新鸟
def bird_动画():
新的鸟=鸟框架[鸟索引]
new_bird_rect=new_bird.get_rect(中心=(100,bird_rect.centery))
返回新鸟,新鸟
def分数显示(游戏状态):
如果游戏状态==“主游戏”:
score_surface=game_font.render(str(int(score)),True,(255255))
score_rect=score_surface.get_rect(中心=(288,50))
win.blit(得分表面、得分直线)
如果游戏状态==“游戏结束”:
score_surface=game_font.render(f'score:{(int(score))}',True,(255255))
score_rect=score_surface.get_rect(中心=(288,50))
win.blit(得分表面、得分直线)
high_score_surface=game_font.render(f'high score:{(int(high_score))}',True,(255255))
high_score_rect=high_score_surface.get_rect(中心=(288250))
win.blit(高分表面、高分直线)
def更新评分(评分、高分):
如果分数>高分:
高分=分数
返回高分
pygame.mixer.pre_init(频率=44100,大小=16,通道=1,缓冲区=512)
pygame.init()
#pygame.set_标题(‘Flappy bird’)
win=pygame.display.set_模式((576700))
clock=pygame.time.clock()
game_font=pygame.font.font('04B_19.TTF',40)
#游戏有效
重力=0.25
鸟类运动=0
game_active=True
分数=0
高分=0
bg=pygame.image.load('assets/background day.png').convert()
bg=pygame.transform.scale2x(bg)
floor\u surface=pygame.image.load('assets/base.png'))
floor_surface=pygame.transform.scale2x(floor_surface)
楼层x位置=0
bird_downflap=pygame.transform.scale2x(pygame.image.load('assets/bluebird downflap.png')。convert_alpha())
bird_midflap=pygame.transform.scale2x(pygame.image.load('assets/bluebird midflap.png')。convert_alpha())
bird\u upflap=pygame.transform.scale2x(pygame.image.load('assets/bluebird upflap.png')。convert\u alpha())
bird_frames=[bird_downflap,bird_midflap,bird_upflap]
伯德指数=2
bird=bird\u帧[bird\u索引]
bird_-rect=bird.get_-rect(中心=(100350))
BIRDFLAP=pygame.USEREVENT+1
pygame.time.set_定时器(鸟笼,200)
#鸟
#bird=pygame.image.load('assets/bluebird midflap.png')。convert_alpha()
#bird=pygame.transform.scale2x(bird)
#bird_-rect=bird.get_-rect(中心=(100350))
pipe\u surface=pygame.image.load('assets/pipe green.png')
管道曲面=pygame.transform.scale2x(管道曲面)
管道列表=[]
SPAWNPIPE=pygame.USEREVENT
pygame.time.set_定时器(产卵管,1200)
管道高度=[200300400]
game_over_surface=pygame.transform.scale2x(pygame.image.load('assets/message.png')。convert_alpha())
game_over_rect=game_over_surface.get_rect(中心=(288350))
flap\u sound=pygame.mixer.sound('sound/sfx\u wing.wav'))
死亡之声=pygame.mixer.sound('sound/sfx\u hit.wav'))
score\u sound=pygame.mixer.sound('sound/sfx\u point.wav'))
得分\声音\倒计时=100
尽管如此:
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
pygame.quit()
sys.exit()
如果event.type==pygame.KEYDOWN:
如果event.key==pygame.K_空间和game_活动:
鸟类运动=0
鸟类运动-=6
拍打声音。播放()
如果event.key==pygame.K_空间和game_活动==False:
game_active=True
管道列表。清除()
bird_rect.center=(100350)
鸟类运动=0
分数=0
如果event.type==SPAWNPIPE:
管道列表。扩展(创建管道())
如果event.type==BIRDFLAP:
如果伯德指数<2:
伯德指数+=1
其他:
伯德指数=0
bird,bird_rect=bird_动画()
温·布利特(背景,(0,0))
如果游戏处于活动状态:
#鸟
鸟类运动+=重力
旋转鸟=旋转鸟(鸟)
鸟_-rect.centery+=鸟_运动
win.blit(鸟,鸟)
游戏激活=检查碰撞(管道列表)
#管道
管道列表=移动管道(管道列表)
绘制管道(管道列表)
分数+=0.01
分数显示(“主游戏”)
得分\声音\倒计时-=1

如果分数\u声音\u倒计时问题出现在
更新\u分数
中,当
分数时,您返回一个无。对不起,但我不明白,您能写下我应该改成什么吗?非常感谢,我解决了它。作为回报,我不得不删除一个标签。
import pygame
import sys, random


def floor_repetition():
    win.blit(floor_surface, (floor_x_pos,588))
    win.blit(floor_surface, (floor_x_pos + 576,588))



def create_pipe():
    random_pipe_pos = random.choice(pipe_height)
    bottom_pipe = pipe_surface.get_rect(midtop = (700, random_pipe_pos))
    top_pipe = pipe_surface.get_rect(midbottom = (700, random_pipe_pos - 170))
    return bottom_pipe, top_pipe


def move_pipes(pipes):  
    for pipe in pipes:
        pipe.centerx -= 5
    return pipes


def draw_pipes(pipes):
    for pipe in pipes:
        if pipe.bottom >= 588:
            win.blit(pipe_surface, pipe)
        else:
            flip_pipe = pygame.transform.flip(pipe_surface, False, True)
            win.blit(flip_pipe,pipe)

def check_collision(pipes):
    for pipe in pipes:
        if bird_rect.colliderect(pipe):
            death_sound.play()
            return False
    
    if bird_rect.top <= -100 or bird_rect.bottom >= 588:
        return False

    return True


def rotate_bird(bird1):
    new_bird = pygame.transform.rotozoom(bird1, -bird_movement * 3,1)
    return new_bird


def bird_animation():
    new_bird = bird_frames[bird_index]
    new_bird_rect = new_bird.get_rect(center = (100, bird_rect.centery))
    return new_bird, new_bird_rect

def score_display(game_state):
    if game_state == 'main_game':
        score_surface = game_font.render(str(int(score)), True,(255,255,255))   
        score_rect = score_surface.get_rect(center = (288,50))
        win.blit(score_surface, score_rect)

    if game_state == 'game over':
        score_surface = game_font.render(f'Score: {(int(score))}', True,(255,255,255))  
        score_rect = score_surface.get_rect(center = (288,50))
        win.blit(score_surface, score_rect)

        high_score_surface = game_font.render(f'High Score: {(int(high_score))}', True,(255,255,255))   
        high_score_rect = high_score_surface.get_rect(center = (288,250))
        win.blit(high_score_surface, high_score_rect)
        
def update_score(score, high_score):
    if score > high_score:
        high_score = score
        return high_score
pygame.mixer.pre_init(frequency = 44100, size = 16, channels = 1, buffer = 512)
pygame.init()

#pygame.set_caption('Flappy bird')

win = pygame.display.set_mode((576,700))
clock = pygame.time.Clock()
game_font = pygame.font.Font('04B_19.TTF',40)


# Game valiables
gravity = 0.25
bird_movement = 0
game_active = True
score = 0
high_score = 0

bg = pygame.image.load('assets/background-day.png').convert()
bg = pygame.transform.scale2x(bg)

floor_surface = pygame.image.load('assets/base.png')
floor_surface = pygame.transform.scale2x(floor_surface)
floor_x_pos = 0




bird_downflap = pygame.transform.scale2x(pygame.image.load('assets/bluebird-downflap.png').convert_alpha())
bird_midflap = pygame.transform.scale2x(pygame.image.load('assets/bluebird-midflap.png').convert_alpha())
bird_upflap = pygame.transform.scale2x(pygame.image.load('assets/bluebird-upflap.png').convert_alpha())
bird_frames = [bird_downflap, bird_midflap, bird_upflap]
bird_index = 2
bird = bird_frames[bird_index]
bird_rect = bird.get_rect(center = (100,350))


BIRDFLAP = pygame.USEREVENT + 1
pygame.time.set_timer(BIRDFLAP, 200)



# bird
#bird = pygame.image.load('assets/bluebird-midflap.png').convert_alpha()
#bird = pygame.transform.scale2x(bird)
#bird_rect = bird.get_rect(center = (100,350))

pipe_surface = pygame.image.load('assets/pipe-green.png')
pipe_surface = pygame.transform.scale2x(pipe_surface)
pipe_list = []
SPAWNPIPE = pygame.USEREVENT
pygame.time.set_timer(SPAWNPIPE, 1200)
pipe_height = [200,300,400]


game_over_surface = pygame.transform.scale2x(pygame.image.load('assets/message.png').convert_alpha())
game_over_rect = game_over_surface.get_rect(center = (288,350))

flap_sound = pygame.mixer.Sound('sound/sfx_wing.wav')
death_sound = pygame.mixer.Sound('sound/sfx_hit.wav')
score_sound = pygame.mixer.Sound('sound/sfx_point.wav')
score_sound_countdown = 100

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 and game_active:
                bird_movement = 0
                bird_movement -= 6
                flap_sound.play()

            if event.key == pygame.K_SPACE and game_active == False:
                game_active = True
                pipe_list.clear()
                bird_rect.center = (100,350)
                bird_movement = 0
                score = 0


        if event.type == SPAWNPIPE:
            pipe_list.extend(create_pipe())

        if event.type == BIRDFLAP:
            if bird_index < 2:
                bird_index += 1
            else:
                bird_index = 0

            bird, bird_rect = bird_animation()


    win.blit(bg, (0,0))

    if game_active:
        # bird
        bird_movement += gravity
        rotated_bird = rotate_bird(bird)
        bird_rect.centery += bird_movement
        win.blit(bird, bird_rect)
        game_active = check_collision(pipe_list)
        
        # pipes
        pipe_list = move_pipes(pipe_list)
        draw_pipes(pipe_list)

        score += 0.01
        score_display('main game')
        score_sound_countdown -= 1
        if score_sound_countdown <= 0:
            score_sound.play()
            score_sound_countdown = 100
    else:
        win.blit(game_over_surface,game_over_rect)
        high_score = update_score(score, high_score)
        score_display('game over')

    # floor
    floor_x_pos -= 1
    floor_repetition()
    if floor_x_pos <= -576:
        floor_x_pos = 0
    win.blit(floor_surface, (floor_x_pos,588))



    pygame.display.update()
    clock.tick(120)
Flappy bird.py:173: DeprecationWarning: an integer is required (got type float).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
  bird_rect.centery += bird_movement
Traceback (most recent call last):
  File "Flappy bird.py", line 190, in <module>
    score_display('game over')
  File "Flappy bird.py", line 65, in score_display
    high_score_surface = game_font.render(f'High Score: {(int(high_score))}', True,(255,255,255))   
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
def update_score(score, high_score):
    if score > high_score:
        high_score = score
    return high_score