0

pygameでパックマンゲームを作成しようとしていますが、いくつか問題が発生しました。「食べ物」にはイメージがないと言っているのです。

これは私のパックマンゲーム[コード編集済み]です。

問題は、このエリアに何か問題があり、食べ物に属性画像がないことを教えてくれることです

class Food(pygame.sprite.Sprite):
    def __init__(self,x,y,color):
        pygame.sprite.Sprite.__init__(self)

        pygame.image = pygame.Surface([7,7])
        self.image.fill(color)

        self.rect = self.image.get_rect()
        self.rect.top = y
        self.rect.left = x
    def update (self,player):
        collidePlayer = pygame.sprite.spritecollide(self,player,False)
        if collidePlayer:
            food.remove
4

1 に答える 1

1

__init__無関係なビットをすべて削除すると、次のSpriteサブクラスのメソッドの違いがわかりますか?

class Wall(pygame.sprite.Sprite): 

    def __init__(self,x,y,width,height, color):#For when the walls are set up later
        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.Surface([width, height]) # <-------------
        self.image.fill(color)

class player(pygame.sprite.Sprite):

    def __init__ (self,x,y):

        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.Surface([13,13])  # <-------------
        self.image.fill(white) 

class Food(pygame.sprite.Sprite)
    def __init__(self,x,y,color):
        pygame.sprite.Sprite.__init__(self)

        pygame.image = pygame.Surface([7,7])  # <----- this one is different!
        self.image.fill(color)

属性がselfないというエラーが表示される理由は、設定していないため、画像をモジュール自体に保存したためです。imageself.imagepygame

PS:次のような線

        food.remove

私には疑わしいようです。removeがメソッドの場合、はによって呼び出されfood.remove()food.remove何もしません。

于 2012-08-22T02:24:23.480 に答える