我收到了一个语法错误,我已经搜索了很多时间来解释为什么会这样,但我似乎无法找到原因。我收到了sytax错误:
# -- Pictures ---
image[5] = (r"E5")
和
# --- Colours ---
black = (0,0,0)
任何帮助都表示赞赏,因为我之前从未遇到过这些特定代码的问题
# --- Import ---
import sys
import random
import pygame
from pygame.locals import *
pygame.init()
# --- Constants ---
size = width, height = 720, 480
speed = [2, 2]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Broom! || BETA::00.1.0")
clock = pygame.time.Clock()
car_width = 100
largeText = pygame.font.Font('freesansbold.ttf',115)
smallText = pygame.font.Font("freesansbold.ttf",20)
# --- Pictures ---
road = pygame.image.load(r"1.png")
BackgroundPNG = pygame.image.load(r"BackgroundPNG.png")
carImg = pygame.image.load(r"Sp1.png").convert_alpha()
image[1] = pygame.image.load(r"E1.png")
image[2] = pygame.image.load(r"E2.png")
image[3] = pygame.image.load(r"E3.png")
image[4] = pygame.image.load(r"E4.png"
image[5] = pygame.image.load(r"E5.png")
# --- 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)
# --- functions ---
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def crash():
message_display("You Crashed")
def message_display():
largeText
text_, text_rect = text_objects(text, largeText)
text_rect.center = ((width/2), (height/2))
screen.blit(text_, text_rect)
pygame.display.update()
time.sleep(2)
game_running()
def game_intro():
text_vroom, text_vroom_rect = text_objects("V'Room!", largeText)
text_vroom_rect.center = ((250),(150))
text_go, text_go_rect = text_objects("GO", smallText)
text_go_rect.center = ((75+(100/2)),(400+(50/2)))
text_exit, text_exit_rect = text_objects("Exit", smallText)
text_exit_rect.center = ((550+(100/2)),(400+(50/2)))
running = True
while running:
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()
screen.fill(blue)
screen.blit(BackgroundPNG,(0,0))
screen.blit(text_vroom, text_vroom_rect)
# --- Button GO ---
if 75+100 > mouse[0] > 75 and 400+50 > mouse[1] > 400:
pygame.draw.rect(screen, green_bright,(75,400,100,50))
if click != None and click[0] == 1:
game_running()
else:
pygame.draw.rect(screen, green,(75,400,100,50))
screen.blit(text_go, text_go_rect)
# --- Button EXIT ---
if 550+100 > mouse[0] > 550 and 400+50 > mouse[1] > 400:
pygame.draw.rect(screen, red_bright,(550,400,100,50))
if click != None and click[0] == 1:
pygame.quit()
quit()
else:
pygame.draw.rect(screen, red,(550,400,100,50))
screen.blit(text_exit, text_exit_rect)
pygame.display.flip()
clock.tick(15)
def game_running():
print("gamerunning")
#Create pause here
#Create stop here
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
x = 240
y = 280
x_change = 0
car_speed = 0
crashed = False
while not crashed:
print(x)
for event in pygame.event.get():
print(event)
if event.type == pygame.QUIT:
crashed = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x_change = -50
elif event.key == pygame.K_RIGHT:
x_change = 50
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
x_change = 0
x += x_change
screen.fill(blue)
screen.blit(road, (0,0))
screen.blit(carImg, (x,y))
pygame.display.flip()
if x < -10:
x = -10
else:
if x > 490:
x = 490
else:
crashed = False
clock.tick(30)
game_intro()
答案 0 :(得分:2)
上一行。括号。就是这样。