PyGame中使用Eclipse

时间:2016-11-26 19:45:41

标签: eclipse python-2.7 syntax import

import pygame
import time
import random
from __builtin__ import quit

pygame.init()

display_width = 800
display_height = 600

black = (0,0,0)
white = (255,255,255)

red = (200,0,0)
green = (0,200,0)

bright_red = (255,0,0)
bright_green = (0,255,0)

ship_width = 73

gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Galaxia Remastered')
clock = pygame.time.Clock()

background = pygame.image.load('space1.png')
background = pygame.transform.scale(background, (800,600))

shipImg = pygame.image.load('ship1.png')
shipImg = pygame.transform.scale(shipImg, (73,73))

mobImg = pygame.image.load('ufo.png')
mobImg = pygame.transform.scale(mobImg, (100,100))

def mobs_dodged(count):
    font = pygame.font.SysFont(None, 25)
    text = font.render("Dodged: "+str(count), True, white)
    gameDisplay.blit(text,(0,0))

def mobs(mobx, moby, mobw, mobh):
    gameDisplay.blit(mobImg,(mobx,moby))

def ship(x,y):
    gameDisplay.blit(shipImg,(x,y))

def text_objects(text,font):
    textSurface = font.render(text, True, white)
    return textSurface, textSurface.get_rect()

def message_display(text):
    font = pygame.font.Font('freesansbold.ttf',115)
    TextSurf, TextRect = text_objects(text,font)
    TextRect.center = ((display_width/2),(display_height/2))
    gameDisplay.blit(TextSurf,TextRect)

    pygame.display.update()

    time.sleep(2)

    game_loop()

def crash():
    message_display('You Crashed!')

def button(msg,x,y,w,h,ic,ac):
    mouse = pygame.mouse.get_pos()

    if x + w > mouse[0] > x and y+h > mouse[1] > y:
        pygame.draw.rect(gameDisplay, ac, (x,y,w,h))
    else:
        pygame.draw.rect(gameDisplay,ic, (x,y,w,h))
    font = pygame.font.Font('freesansbold.ttf',20)
    textSurf, textRect = text_objects(msg, font)
    textRect.center = ((x+(w/2)),(y+(h/2))
    gameDisplay.blit(textSurf, textRect)

最后一行给出了无效的语法错误,突出显示" gameDisplay"。环顾四周后,有一个"导入游戏显示来自..."我在项目中的另一个文件。我认为如果删除该行就会修复它,但它表示"未解析的导入"。我重新启动了Ecplise并多次清理了我的项目,但它仍然无法正常工作。我将程序发送到我的其他计算机,它仍然得到相同的错误。当我删除" gameDisplay"它告诉我" def game_intro()中的语法无效:"。

非常感谢所有帮助。

1 个答案:

答案 0 :(得分:0)

看起来你在第74行有一个不匹配的paranthese 只需删除该行中的第一个,您的代码应该再次正常工作..

textRect.center = (x+(w/2)),(y+(h/2))