Python 主菜单到游戏过渡

Python 主菜单到游戏过渡,python,pygame,transition,Python,Pygame,Transition,这段代码将打开一个pygame窗口,并显示一张带有功能按钮的图片(主菜单),但我想知道是否有办法让代码跳到底部(def car(x,y):),在我按下Go按钮后游戏将从底部开始?如果有办法的话,我怎样才能做到这一点 import sys import pygame from pygame.locals import * pygame.init() size = width, height = 720, 480 speed = [2, 2] #Colours black = (0,0,0)

这段代码将打开一个pygame窗口,并显示一张带有功能按钮的图片(
主菜单
),但我想知道是否有办法让代码跳到底部(
def car(x,y):
),在我按下
Go
按钮后游戏将从底部开始?如果有办法的话,我怎样才能做到这一点

import sys
import pygame
from pygame.locals import *
pygame.init()

size = width, height = 720, 480
speed = [2, 2]


#Colours
black = (0,0,0)
blue = (0,0,255)
green = (0,200,0)
red = (200,0,0)
green_bright = (0,255,0)
red_bright = (255,0,0)

screen = pygame.display.set_mode(size)

#Pictures
BackgroundPNG = pygame.image.load(r"C:\Users\John\Desktop\Michael\BroomBatchPython__\BackgroundPNG.png")
carImg = pygame.image.load(r"C:\Users\John\Desktop\Michael\BroomBatchPython__\BV_Sp1.png").convert_alpha()


pygame.display.set_caption("Broom! || BETA::00.0.3")

clock = pygame.time.Clock()


def text_objects(text, font):
    textSurface = font.render(text, True, black)
    return textSurface, textSurface.get_rect()

def game_intro():

intro = True

while intro:
    for event in pygame.event.get():
        print(event)
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()

    print(mouse)
    print(click)

    screen.fill(blue)
    screen.blit(BackgroundPNG,(0,0))

    largeText = pygame.font.Font('freesansbold.ttf',115)
    TextSurf, TextRect = text_objects("V'Room!", largeText)
    TextRect.center = ((width/2),(height/2))
    screen.blit(TextSurf, TextRect)

    #Button
    #GO BUTTON | V

    if 75+100 > mouse[0] > 75 and 400+50 > mouse[1] > 400:
        pygame.draw.rect(screen, green_bright,(75,400,100,50))

        if click[0] == 1 and click != None:
            print("GO == 1 ! == None")
            car
    else:
        pygame.draw.rect(screen, green,(75,400,100,50))

    smallText = pygame.font.Font("freesansbold.ttf",20)
    TextSurf, TextRect = text_objects("GO", smallText)
    TextRect.center = ((75+(100/2)),(400+(50/2)))
    screen.blit(TextSurf, TextRect)

    if 550+100 > mouse[0] > 550 and 400+50 > mouse[1] > 400:
        pygame.draw.rect(screen, red_bright,(550,400,100,50))

        if click[0] == 1 and click != None:
            pygame.quit()
            quit()
    else:
        pygame.draw.rect(screen, red,(550,400,100,50))

    TextSurf, TextRect = text_objects("Exit", smallText)
    TextRect.center = ((550+(100/2)),(400+(50/2)))
    screen.blit(TextSurf, TextRect)

    pygame.display.flip()
    pygame.display.update()
    clock.tick(15)

game_intro()

#################################
def car(x,y):
    x = (width * 0.45)
    y = (height * 0.8)
    screen.blit(carImg, (x,y))

你犯了一个愚蠢的错误——调用函数
car
你需要括号和参数(例如10,10)

顺便说一下:最好先检查
click!=无
,下一步
单击[0]==1
。 如果
单击
,则首先检查
单击[0]==1
将显示错误。如果
check
None
且您首先选中
单击!=无
然后
不选中
单击[0]==1

if click != None and click[0] == 1:
    print("GO == 1 ! == None")
    car(10, 10) # parenthesis and arguments