当我的播放器类与我的平台类之一发生碰撞时,如何制作和结束屏幕?

所以我一直在尝试制作片尾画面,但我确实知道怎么做,我看过一些教程,但对我来说没有一个真正有意义。我也尝试过使用我的开始屏幕,但将其调高一点并将其放在不同的位置,但它不起作用。我正在尝试在我的播放器与我的其中一个平台发生碰撞时出现结束屏幕,但我不知道如何制作结束屏幕。


I do not know what to really put here but this is my start screen code 

##############################################

#START MENUE


def text_objects(text, font):

    textSurface = font.render(text, True, black)

    return textSurface, textSurface.get_rect()


def button(msg,x,y,w,h,ic,ac,action=None):

    mouse = pygame.mouse.get_pos()

    click = pygame.mouse.get_pressed()

    #print(click)

    if x+w > mouse[0] > x and y+h > mouse[1] > y:

        pygame.draw.rect(window, ac,(x,y,w,h))


        if click[0] == 1 and action != None:

            action()         

    else:

        pygame.draw.rect(window, ic,(x,y,w,h))


    smallText = pygame.font.SysFont("comicsansms",20)

    textSurf, textRect = text_objects(msg, smallText)

    textRect.center = ( (x+(w/2)), (y+(h/2)) )

    window.blit(textSurf, textRect)


def quitgame():

    pygame.quit()

    

def game_intro():


    intro = True


    while intro:

        for event in pygame.event.get():

            #print(event)

            if event.type == pygame.QUIT:

                pygame.quit()

                quit()

                

        window.fill((255,255,255))

        largeText = pygame.font.Font('freesansbold.ttf',115)

        TextSurf, TextRect = text_objects("Jump", largeText)

        TextRect.center = ((500/2),(500/2))

        window.blit(TextSurf, TextRect)


        button("GO!",100,350,100,50,green,darkgreen,main_loop)

        button("Quit",300,350,100,50,orange,darkred,quitgame)


        pygame.display.update()

        clock.tick(15)

        

############################################


烙印99
浏览 111回答 1
1回答

Helenr

这是一个可以帮助您的框架。与上面的评论相同。您需要一个布尔变量来跟踪何时显示结束屏幕(发生了不好的事情),然后使用它来决定在主循环中绘制哪个屏幕......def redrawwindow():    # basically what you have now...def draw_end_screen():    # make this new function such that it shows your end-screenrun=Trueend_condition=False   # a new boolean variable to keep track if collision (or something else happened)while run:    # basically what you have now....    # check for collision (in pseudo-code) check for game-ending events    if player1.collides_with_death...:        end_condition=True    if player1.falls_into_pit()...:        end_condition=True    # use the boolean variable to decide what to do next, and in next loop    if end_condition:        draw_end_screen()    else:        redrawwindow()    pygame.display.update()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python