如何创建现有 class 的子 class?

How can I create a subclass of an existing class?

我正在用 PyGame 创建一个 Space Invaders,我想创建一个 class Alien 的子 class,以简化我的代码少量。我该怎么做?这是我到目前为止的代码:

class Alien(pygame.sprite.Sprite):
    def __init__(self, width, height):
        super().__init__()
        self.image = pygame.Surface([width, height])
        self.image.fill(RED)
        self.image = pygame.image.load("alien1.png").convert_alpha()
        self.rect = self.image.get_rect()

事实上,您刚刚创建了 Sprite 的子类。外星人也一样。

class Reptilian(Alien):
    def __init__(self, width, height, human_form):  # you can pass some other properties
        super().__init__(width, height)  # you must pass required args to Alien's __init__
        # your custom stuff:
        self.human_form = human_form