2014-01-30 80 views
0

我正在做一個平臺遊戲,我剛開始它,並且遇到了語法錯誤。該代碼是在這裏:令人討厭的無效語法

import pygame, sys 
from player import * 
from constants import * 

class Game(): 

    def __init__(self): 
     pygame.init() 

     self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) 
     pygame.display.set_caption('GAME') 

     self.font = pygame.font.Font('data/font/orecrusherexpanded.ttf', 50) 

     self.black = (0, 0, 0) 
     self.blue = (50, 60, 100) 

     self.player = Player(250, 250) 

    def run(self): 

     clock = pygame.time.Clock() 

     RUNNING = True 

     while RUNNING: 

      for event in pygame.event.get(): 

       if event.type == pygame.QUIT: 
        pygame.quit() 
        sys.exit() 

       if event.type == pygame.KEYDOWN: 

        if event.key == pygame.K_ESCAPE: 
         pygame.quit() 
         sys.exit() 

      fps = 60 
      self.screen.fill(self.blue) 

      self.player_move() 
      self.player.update() 
      self.player.handle_events(event) 
      self.player.render(self.screen) 
      self.screen.blit(self.font.render("FPS: " + str(clock.get_fps()), 1, (255, 0, 0), (0,0)) 

      clock.tick(fps) 

      pygame.display.flip() 

    def player_move(self): 

     self.player.rect.x += self.player.velX 
     self.player.rect.y += self.player.velY 

Game().run() 

凡說clock.tick(FPS)當我運行程序錯誤亮點時鐘和彈出說語法無效!謝謝你的幫助。

+2

你缺少在該行正上方此 – Wolf

回答

1

問題實際上是clock.tick(fps)之前的行。

self.screen.blit(self.font.render("FPS: " + str(clock.get_fps()), 1, (255, 0, 0), (0,0)) 

這條線沒有足夠的圓括號。它可能應該是:

self.screen.blit(self.font.render("FPS: " + str(clock.get_fps()), 1, (255, 0, 0), (0,0))) 
+0

啊關於那該死的遺憾年底關閉「)」。沒有注意到,感謝指出我的錯誤。 – GhostFrag1