无效的语法?不使用主程序的类

时间:2014-12-17 02:20:17

标签: python pygame syntax-error

我的程序在一秒钟之前工作正常,然后我略微改变了播放器类中的“更新”,然后我突然得到了错误。我解开了“更新”编辑,但仍然遇到了这个问题。我关闭了程序并重新打开它,我仍然得到同样的问题。 这是错误

Traceback (most recent call last):
  File "G:\New Folder\Final_Game.py", line 8, in <module>
    import playerSprite
  File "G:\New Folder\playerSprite.py", line 56
    `

^
SyntaxError: invalid syntax

主程序

import pygame

import random

import playerSprite

pygame.init()

pygame.mixer.init()

screen = pygame.display.set_mode((500, 500))

def main():
pygame.display.set_caption("MusicPuz")

#making the background to a floor
background = pygame.image.load("floor.jpg")
background = background.convert()
screen.blit(background, (0,0))



#making sprite
allSprites = pygame.sprite.Group()

#loop to spawn puzzle box
for i in range(1):
    puzzle = playerSprite.door(250, 250)
    allSprites.add(puzzle)



puzzle = playerSprite.door(250,250)
puzSprite = pygame.sprite.Group(puzzle)
player = playerSprite.Player(100,100,15)
pSprite = pygame.sprite.Group(player)


#making a list for the sprites
List = []

clock = pygame.time.Clock()
keepGoing = True

#main loop
while keepGoing:
    clock.tick(30)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keepGoing = False

        #moving
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                player.up=True
                player.playC()

            elif event.key == pygame.K_DOWN:
                player.down=True
                player.playF()

            elif event.key==pygame.K_LEFT:
                player.left=True
                player.playG()

            elif event.key==pygame.K_RIGHT:
                player.right=True
                player.playC2()


        #not moving        
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_UP:
                player.up = False
            elif event.key == pygame.K_DOWN:
                player.down = False
            elif event.key==pygame.K_LEFT:
                player.left=False
            elif event.key==pygame.K_RIGHT:
                player.right=False


        #collision detection to play the note puzzle
        for puzzle in allSprites:
            spriteCollide = pygame.sprite.groupcollide(pSprite, allSprites, False, False)

            for i in spriteCollide:
                pygame.mixer.stop()
                puzzle.playNotes()
                if puzzle.playNotes() == True:
                    pygame.mixer.stop()



    #update sprites        
    allSprites.clear(screen, background)
    pSprite.clear(screen, background)
    puzSprite.clear(screen, background)
    allSprites.update()
    pSprite.update()
    puzSprite.update()
    allSprites.draw(screen)
    pSprite.draw(screen)
    puzSprite.draw(screen)

    #refresh screen
    pygame.display.flip()

pygame.quit()

if __name__ == "__main__":
main()

这是playerSprites模块

import pygame
import random

pygame.init()
pygame.mixer.init()

#class to make the player controlled sprite
class Player(pygame.sprite.Sprite):

    #making the sprite
    def __init__ (self, initialX, initialY, dx):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("fez.png")
        self.image = self.image.convert()
        self.image.set_colorkey((63, 72, 204))
        w,h=self.image.get_size()
        self.image=pygame.transform.scale(self.image,(int(w*.5),int(h*.5)))
        self.rect = self.image.get_rect()
        self.rect.left = initialX
        self.rect.top = initialY
        self.dx = dx
        self.dy = 0
        self.up = False
        self.down = False
        self.left = False
        self.right = False
        self.CNote = pygame.mixer.Sound("CNote.wav")
        self.FNote = pygame.mixer.Sound("FNote.wav")
        self.GNote = pygame.mixer.Sound("GNote.wav")
        self.HighCNote = pygame.mixer.Sound("HighCNote.wav")

    #to make the sprite move
    def update(self):

        if self.up:
            self.rect.top-=5
        if self.down:
            self.rect.top+=5
        if self.left:
            self.rect.left-=5
        if self.right:
            self.rect.right+=5

#This is what I put before the program would not work`
##        if self.rect.centerx >= screen.get_width:
##            self.rect.centerx = screen.get_width - 5
##
##        if self.rect.centerx <= 0:
##            self.rect.centerx = +5

    #making all the notes
    def playC(self):
        self.CNote.play()
    def playF(self):
        self.FNote.play()
    def playG(self):
        self.GNote.play()
    def playC2(self):
        self.HighCNote.play()





#sprite for box that will start the puzzle notes 
class door(pygame.sprite.Sprite):

    def __init__ (self, initialX, initialY):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("door.png")
        self.image = self.image.convert()
        self.rect = self.image.get_rect()
        self.rect.centery = initialX
        self.rect.centerx = initialY
        self.puzzle1 = pygame.mixer.Sound("Puzzle1.wav")

    def playNotes(self):
        self.puzzle1.play()

    def update (self):
        self.rect.centerx += 0

0 个答案:

没有答案