矩形点击Pygame

时间:2018-08-08 09:52:16

标签: python pygame rectangles

我想做的是当用户单击“开始”,“控件”或退出时绘制一个新屏幕。第一个屏幕欢迎用户,并要求他们“单击此处开始游戏”,该按钮显示在按钮上。即使用户前进到下一页,上一个按钮也不可见,但是即使您单击该按钮先前所在的位置,即使我希望“开始”按钮具有该功能,它仍会带您进入下一页。我目前有下一页作为screen.fill(RED)只是为了测试代码。

#Main Menu Loop

while not done and display_menu:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                if rect4.collidepoint(event.pos):
                    start_page +1
        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                if rect1.collidepoint(event.pos):
                    start_page +=1
                if rect2.collidepoint(event.pos):
                    start_page +=2
                    if start_page == 4:
                        display_menu = False


    # Set the screen background
    screen.fill(BLACK)

    if start_page == 1:

        screen.blit(bg2, (0, 0))
        pygame.draw.rect(screen, RED, rect4)
        text = font3.render("Click HERE to start Game!", True, WHITE)
        screen.blit(text, [125, 400])

    if start_page == 2:

        screen.blit(bg, (0, 0))

        #Drawing the Button
        pygame.draw.rect(screen, BLACK, rect1)
        pygame.draw.rect(screen, BLACK, rect2)
        pygame.draw.rect(screen, BLACK, rect3)

        #Text in Button
        text = font3.render("START", True, WHITE)
        screen.blit(text, [335, 325])
        text = font4.render("CONTROLS", True, WHITE)
        screen.blit(text, [320, 425])
        text = font3.render("QUIT", True, WHITE)
        screen.blit(text, [335, 525])

    if start_page == 3:

        screen.fill(GREEN)

    if start_page == 4:

        screen.fill(RED)

    clock.tick(60)

    pygame.display.flip()

我愿意接受任何建议。谢谢

0 个答案:

没有答案