我正在制作一款平台游戏,我刚刚启动它,我遇到了语法错误。代码在这里:
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)当我运行程序时,错误突出显示时钟并弹出说无效语法!谢谢你的帮助。
答案 0 :(得分: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)))