2016-11-26 59 views
0
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”。在环视自己之后,有一个“导入gameDisplay from ...”项目中的另一个文件。我认为,如果我删除了该行,它会被修复,但是它表示“未解决的导入”。我重新启动了Ecplise并多次清理了我的项目,但仍然无法正常工作。我把这个程序发送到了我的另一台电脑上,它仍然得到了同样的错误。当我删除“gameDisplay”这一行时,它告诉我“def game_intro():”中有一个无效的语法。使用Eclipse的PyGame中的不寻常的语法错误

所有帮助将不胜感激。

+1

还没跑出你的代码,但它看起来就像你的第二行到最后一行代码中有一些不匹配的括号。 – CodeSurgeon

回答

0

它看起来就像你上线74 一个不匹配的paranthese只需删除该行上最前面的一个,你的代码应该只是罚款再次工作..

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