Group

Bases: pygame.sprite.Group

Container for multiple Entities.

Source code in robingame/objects/group.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Group(pygame.sprite.Group):
    """Container for multiple Entities."""

    def add(self, *entities: "Entity") -> None:
        """
        Does the same thing as pygame's `Group.add()`.
        Only overriding this because pygame's typing was making the linter complain.
        """
        super().add(*entities)

    def update(self, *args):
        """
        Call `.update()` on all member Entities.
        """
        super().update(*args)

    def draw(self, surface: pygame.Surface, debug: bool = False):
        """
        Call `.draw(surface, debug)` on all member Entities.

        This is different from pygame's `Group.draw()` in that it calls the `Entity.draw()` method
        (thus allowing the Entity to decide how to draw itself) instead of just blitting the
        Entity's `.image` onto the surface.
        """
        entities = self.sprites()
        for entity in entities:
            entity.draw(surface, debug)
        self.lostsprites = []

    def kill(self):
        """
        Call `.kill()` on all the entities in this group.
        This is different from `Group.empty()`.
        """
        for entity in self:
            entity.kill()

add(*entities)

Does the same thing as pygame's Group.add(). Only overriding this because pygame's typing was making the linter complain.

robingame/objects/group.py
11
12
13
14
15
16
def add(self, *entities: "Entity") -> None:
    """
    Does the same thing as pygame's `Group.add()`.
    Only overriding this because pygame's typing was making the linter complain.
    """
    super().add(*entities)

draw(surface, debug=False)

Call .draw(surface, debug) on all member Entities.

This is different from pygame's Group.draw() in that it calls the Entity.draw() method (thus allowing the Entity to decide how to draw itself) instead of just blitting the Entity's .image onto the surface.

robingame/objects/group.py
24
25
26
27
28
29
30
31
32
33
34
35
def draw(self, surface: pygame.Surface, debug: bool = False):
    """
    Call `.draw(surface, debug)` on all member Entities.

    This is different from pygame's `Group.draw()` in that it calls the `Entity.draw()` method
    (thus allowing the Entity to decide how to draw itself) instead of just blitting the
    Entity's `.image` onto the surface.
    """
    entities = self.sprites()
    for entity in entities:
        entity.draw(surface, debug)
    self.lostsprites = []

kill()

Call .kill() on all the entities in this group. This is different from Group.empty().

robingame/objects/group.py
37
38
39
40
41
42
43
def kill(self):
    """
    Call `.kill()` on all the entities in this group.
    This is different from `Group.empty()`.
    """
    for entity in self:
        entity.kill()

update(*args)

Call .update() on all member Entities.

robingame/objects/group.py
18
19
20
21
22
def update(self, *args):
    """
    Call `.update()` on all member Entities.
    """
    super().update(*args)