import pygame
import sys
from pygame.locals import *
pygame.init()
white = (255,255,255)
black = (0,0,0)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
yellow = (255,255,0)
cyan = (0,255,255)
purple = (255,0,255)
bg = black
fps = 30
dispWidth = 800
dispHeight = 600
pixMove = 10
UP = 'up'
DOWN = 'down'
LEFT = 'left'
RIGHT = 'right'
def runGame():
imgx = 3
imgy = 3
direction = RIGHT
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key == (K_LEFT or K_a):
direction = LEFT
elif event.key == (K_RIGHT or K_d):
direction = RIGHT
elif event.key == (K_DOWN or K_s):
direction = DOWN
elif event.key == (K_UP or K_w):
direction = UP
if direction == UP:
imgy -= pixMove
elif direction == DOWN:
imgy += pixMove
elif direction == LEFT:
imgx -=pixMove
elif direction == RIGHT:
imgx += pixMove
setDisplay.fill(bg)
img = pygame.image.load('kirby.png')
img = pygame.transform.scale(img, (20,20)
setDisplay.blit(img,(imgx,imgy))
pygame.display.update()
while True:
global fpsTime
global setDisplay
fpsTime = pygame.time.Clock()
setDisplay = pygame.display.set_mode((dispWidth,dispHeight))
pygame.display.set_caption('kirby\'s controlled adventure')
runGame()
好的,soo当我运行这段代码时,我在“setDisplay.blit(img,(imgx,imgy))”(更具体地说是在setDisplay之后)出现语法错误。
我不知道这段代码到底有什么问题,任何人都可以帮助我吗?
(我正在使用python 3.4顺便说一句)
答案 0 :(得分:1)
您在前一行缺少右括号:
img = pygame.transform.scale(img, (20,20)
# ^ ^ ^?