亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當我的播放器類與我的平臺類之一發生碰撞時,如何制作和結束屏幕?

當我的播放器類與我的平臺類之一發生碰撞時,如何制作和結束屏幕?

烙印99 2023-04-18 17:09:52
所以我一直在嘗試制作片尾畫面,但我確實知道怎么做,我看過一些教程,但對我來說沒有一個真正有意義。我也嘗試過使用我的開始屏幕,但將其調高一點并將其放在不同的位置,但它不起作用。我正在嘗試在我的播放器與我的其中一個平臺發生碰撞時出現結束屏幕,但我不知道如何制作結束屏幕。I do not know what to really put here but this is my start screen code ###############################################START MENUEdef 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)        ############################################
查看完整描述

1 回答

?
Helenr

TA貢獻1780條經驗 獲得超4個贊

這是一個可以幫助您的框架。與上面的評論相同。您需要一個布爾變量來跟蹤何時顯示結束屏幕(發生了不好的事情),然后使用它來決定在主循環中繪制哪個屏幕......


def redrawwindow():

    # basically what you have now...


def draw_end_screen():

    # make this new function such that it shows your end-screen



run=True

end_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()


查看完整回答
反對 回復 2023-04-18
  • 1 回答
  • 0 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號