0

I am getting a syntax error, I have searched for many hours on why this is happening but I cannot seem to find a reason. I am getting sytax errors on:

# -- Pictures ---
image[5] = (r"E5")

and on

# --- Colours ---
black = (0,0,0)

Any help is appreciated as I have never had this problem before with those specific pieces of code

# --- 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()
1
  • Please include the trace, it is invaluable for finding out what went wrong. Commented Dec 25, 2015 at 23:38

1 Answer 1

2

Previous line. Parens. That is all.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.