无法创建和运行类为什么?

时间:2016-12-21 07:45:36

标签: python-3.x pygame

所以我从课程,小组和精灵开始。我的代码中的所有内容似乎都是正确的,但它不会运行。我已经尝试使用print("hello")命令检测到运行的内容但是没有得到任何回复。

class Spaceship(pygame.sprite.Sprite): ###thigs that fly arround when GUI == 4

def __init__(self, ships, GUIstatus):

    # ships is a Group for all ships 
    pygame.sprite.Sprite.__init__(self, ships)
    self.shipUp = pygame.image.load("icons/shipUP.png")
    self.shipRight = pygame.image.load("icons/shipRIGHT.png")
    self.shipLeft = pygame.image.load("icons/shipLEFT.png")
    self.shipDown = pygame.image.load("icons/shipDOWN.png")

    # the image has to be in self.image
    self.image = self.shipLeft

    # no need for shipnpc_x and shipnpc_y, since we store
    # our position in self.rect
    self.rect = self.image.get_rect()
    self.GUIstatus = GUIstatus

    self.shipType = random.randrange(0,5)

# this has to be called update instead of update
# to work with groups
def update(self):

    # to change the position, we just alter self.rect

    if self.exists == 0 and self.GUIstatus == 4:
        if dirrection == LEFT:
            #self.rect.move_ip(-self.speed, 0)
            self.shipImage = self.shipLeft
            print("Hello i'm a spacecraft")

        if dirrection == RIGHT:
            #self.rect.move_ip(self.speed, 0)
            self.shipImage = self.shipRight

        if dirrection == UP:
            #self.rect.move_ip(0, -self.speed)
            self.shipImage = self.shipUp

        if dirrection == DOWN:
            #self.rect.move_ip(0, self.speed)
            self.shipImage = self.shipDown

然后我正在使用它:

ships = pygame.sprite.Group()
for _ in range(30):
    Spaceship(ships, GUIstatus)

然后进行绘图和更新:

ships.update()
ships.draw(screen)

但似乎什么都没有运行?为什么呢?

0 个答案:

没有答案