Exemplo n.º 1
0
    def __is_dirty(self, entity, viewport, others=set()):

        on_screen = collide(
            entity.present().r_box(),
            viewport)

        was_on_screen = collide(
            entity.past().r_box(),
            viewport)

        # Thing that are and were on screen have quite a couple of rules...
        if on_screen and was_on_screen:

            # Is the stretegy being suppresed?
            if self.__force_all:

                return True

            # Force the drawing of new Entities first time they apppear on
            # screen
            if not self.__was_drawn(entity):

                self.__mark_drawn(entity)

                return True

            # See if a redraw is necessary due to changes in the entity itentity
            moved = entity.present().r_box() != entity.past().r_box()

            sprite_changed = \
                entity.present().state_name() != entity.past().state_name()

            if moved or sprite_changed:
                return True

            # See if a redraw is necessary due to changes around the entity
            for other in others:

                collided = collide(
                    entity.past().r_box(),
                    other.past().r_box())

                collide_now = collide(
                    entity.present().r_box(),
                    other.present().r_box())

                if collided or collide_now:
                    return True

        # Entities that change their onscreen status are dirty
        elif on_screen != was_on_screen:

            return True

        return False
Exemplo n.º 2
0
    def render(self, stage, engine, viewport):

        for entity in stage:

            if collide(entity.present().r_box(), viewport):

                entity.draw(engine, viewport)