Вы можете использовать метод, который вы можете переопределить, чтобы определить группы:
class Block(pygame.sprite.Sprite):
def __init__(self, game, x, y, collidable=True):
pygame.sprite.Sprite.__init__(self, self.get_groups(game))
self.game = game
...
def get_groups(self, game):
return game.all_sprites, game.blocks
class Ground(Block):
def __init__(self, game, x, y, collidable=False):
Block.__init__(self, game, x, y, collidable)
def get_groups(self, game):
return game.all_sprites, game.grounds
или сохранить имена атрибутов групп спрайтов в качестве атрибута класса и динамически искать их, например:
class Block(pygame.sprite.Sprite):
groups = ['all_sprites', 'blocks']
def __init__(self, game, x, y, collidable=True):
pygame.sprite.Sprite.__init__(self, (getattr(game, g) for g in self.groups))
self.game = game
...
class Ground(Block):
groups = ['all_sprites', 'grounds']
def __init__(self, game, x, y, collidable=False):
Block.__init__(self, game, x, y, collidable)
или передать группы в качестве параметра из подкласса в родительский класс:
class Block(pygame.sprite.Sprite):
def __init__(self, game, x, y, collidable=True, groups=None):
pygame.sprite.Sprite.__init__(self, groups or (game.all_sprites, game.blocks))
self.game = game
...
class Ground(Block):
def __init__(self, game, x, y, collidable=False, groups=None):
Block.__init__(self, game, x, y, collidable, groups or (game.all_sprites, game.grounds))
На самом деле возможности безграничны:
class Block(pygame.sprite.Sprite):
def __init__(self, game, x, y, collidable=True):
groups = game.all_sprites, getattr(game, self.__class__.__name__.lower() + 's')
pygame.sprite.Sprite.__init__(self, groups)
self.game = game
...
Я бы, наверное, используйте вариант 3, потому что он явный и в нем нет причудливых умных частей.