Python Pygame语法错误,以前从未发生过
我得到了一个语法错误,我已经搜索了很多小时为什么会发生这种情况,但我似乎找不到一个原因。我在以下方面收到sytax错误:Python Pygame语法错误,以前从未发生过,python,pygame,Python,Pygame,我得到了一个语法错误,我已经搜索了很多小时为什么会发生这种情况,但我似乎找不到一个原因。我在以下方面收到sytax错误: # -- Pictures --- image[5] = (r"E5") 等等 # --- Colours --- black = (0,0,0) 非常感谢您的帮助,因为我以前从未遇到过这些特定代码片段的问题 # --- Import --- import sys import random import pygame from pygame.locals import
# -- 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()
导入---
导入系统
随机输入
导入pygame
从pygame.locals导入*
pygame.init()
#---常数---
尺寸=宽度,高度=720480
速度=[2,2]
screen=pygame.display.set_模式(大小)
pygame.display.set_标题(“扫帚!| | BETA::00.1.0”)
clock=pygame.time.clock()
轿厢宽度=100
largeText=pygame.font.font('freesansbold.ttf',115)
smallText=pygame.font.font(“freesansbold.ttf”,20)
#---图片---
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”)
#---颜色---
黑色=(0,0,0)
蓝色=(0,0255)
绿色=(0200,0)
红色=(200,0,0)
绿色明亮=(0255,0)
红亮=(255,0,0)
#---功能--
def text_对象(文本、字体):
textSurface=font.render(文本,真,黑色)
返回textSurface,textSurface.get_rect()
def crash():
信息显示(“您崩溃了”)
def消息_显示()
大文本
text\u,text\u rect=text\u对象(text,largeText)
text_rect.center=((宽度/2),(高度/2))
screen.blit(text,text-rect)
pygame.display.update()
时间。睡眠(2)
游戏(跑步)
def game_intro():
text\u vroom,text\u vroom\u rect=text\u对象(“V'Room!”,largeText)
text_vroom_rect.center=(250)、(150))
text\u go,text\u go\u rect=文本对象(“go”,smallText)
text_go_rect.center=((75+(100/2)),(400+(50/2)))
text\u exit,text\u exit\u rect=text\u对象(“exit”,smallText)
text_exit_rect.center=((550+(100/2)),(400+(50/2)))
运行=真
运行时:
对于pygame.event.get()中的事件:
打印(事件)
如果event.type==pygame.QUIT:
pygame.quit()
退出
mouse=pygame.mouse.get_pos()
click=pygame.mouse.get_pressed()
屏幕填充(蓝色)
屏幕blit(背景PNG,(0,0))
screen.blit(text\u vroom,text\u vroom\u rect)
#---按钮开始---
如果75+100>鼠标[0]>75和400+50>鼠标[1]>400:
pygame.draw.rect(屏幕,绿色明亮,(75400100,50))
如果单击!=无并单击[0]==1:
游戏(跑步)
其他:
pygame.draw.rect(屏幕,绿色,(75400100,50))
screen.blit(text\u go,text\u go\u rect)
#---按钮出口---
如果550+100>鼠标[0]>550和400+50>鼠标[1]>400:
pygame.draw.rect(屏幕,红光,(550400100,50))
如果单击!=无并单击[0]==1:
pygame.quit()
退出
其他:
pygame.draw.rect(屏幕,红色,(550400100,50))
blit(文本退出,文本退出)
pygame.display.flip()
时钟滴答(15)
def game_running():
打印(“游戏运行”)
#在此处创建暂停
#创建停止在这里
mouse=pygame.mouse.get_pos()
click=pygame.mouse.get_pressed()
x=240
y=280
x_变化=0
车速=0
崩溃=错误
虽然没有崩溃:
打印(x)
对于pygame.event.get()中的事件:
打印(事件)
如果event.type==pygame.QUIT:
崩溃=真
如果event.type==pygame.KEYDOWN:
如果event.key==pygame.K_左:
x_变化=-50
elif event.key==pygame.K_RIGHT:
x_变化=50
如果event.type==pygame.KEYUP:
如果event.key==pygame.K_左或event.key==pygame.K_右:
x_变化=0
x+=x_变化
屏幕填充(蓝色)
屏幕布利特(道路,(0,0))
屏幕光点(carImg,(x,y))
pygame.display.flip()
如果x<-10:
x=-10
其他:
如果x>490:
x=490
其他:
崩溃=错误
时钟滴答(30)
游戏介绍()
上一行。Parens。仅此而已。请包括跟踪,它对于找出问题所在非常重要。