Ejemplo n.º 1
0
    def smooth_wall_collision(wall, sprite, point):
        v = sprite.get_velocity()

        projected = v.apply_to_point(point)
        adjustment = wall.get_normal_adjustment(projected)
        adjustment = add_points(adjustment, v.get_value())
        sprite.move(*adjustment)

        normal = wall.get_normal()
        sprite.physics.scale_movement_in_direction(normal.get_angle(), 0)
Ejemplo n.º 2
0
    def get_graphics(self, offset):
        image = self.image

        mirror_x, mirror_y = self.mirror
        if mirror_x or mirror_y:
            image = image.flip(mirror_x, mirror_y)

        position = add_points(self.entity.position, offset)
        args = (image, position)

        return [args]
Ejemplo n.º 3
0
    def get_rect_args(item, offset):
        if len(item) < 3:
            rect, color = item
            width = 0
        else:
            rect, color, width = item

        x, y = add_points(offset, rect.position)
        rect = rect.pygame_rect
        rect.x = int(x)
        rect.y = int(y)

        return (con.PYGAME_RECT, color, rect, width)
Ejemplo n.º 4
0
    def get_graphics(self, offset):
        if not self.layers:
            return super(ImageSectionGraphics, self).get_graphics(offset)

        else:
            args = []

            for layer in self.layers:
                a = self.get_section_args(layer)
                position = add_points(a[1], offset)
                a = (a[0], position)
                args.append(a)

            return args
Ejemplo n.º 5
0
    def get_graphics(self, offset=None):
        if not offset:
            offset = 0, 0
        offset = add_points(self.entity.position, offset)
        offset = int(offset[0]), int(offset[1])

        args = []

        for item in self.items:
            if type(item[0]) is Rect:
                args.append(self.get_rect_args(item, offset))

            elif type(item[0]) is Vector:
                args.append(self.get_vector_args(item, offset))

            elif type(item[0]) is Wall:
                args.append(
                    self.get_vector_args(item,
                                         add_points(offset, item[0].origin)))

            elif item[0] == con.PYGAME_LINE:
                item[2] = add_points(offset, item[2])
                item[3] = add_points(offset, item[3])
                args.append(item)

            elif item[0] == con.PYGAME_RECT:
                item[2].x += offset[0]
                item[2].y += offset[1]
                args.append(item)

            elif item[0] == con.PYGAME_CIRCLE:
                item = list(item)
                item[2] = add_points(offset, item[2])
                args.append(item)

        return args
Ejemplo n.º 6
0
    def get_graphics(self, offset=None):
        """
        This method provides a list of tuples of arguments to be used in
        the Screen object's 'draw()' method where each tuple in the list is
        effectively a set of arguments for the 'render_graphics()' method.

        An optional 'position' argument can be passed as a tuple of numbers
        representing a relative offset for any position arguments added to
        the argument tuples list. If no 'position' argument is passed then the
        layer's 'position' attribute is used as the value.

        The Layer's graphics are added to the argument tuple list, then any
        Layer in the 'sub_layers' list is added, with the position passed
        to it's 'get_graphics' method added to the current position value.

        Any sprites returned by the 'get_sprites()' method will also have
        their graphics arguments added to the list.

        :param offset: None or (int or float, int or float)

        :return: list
        """
        if not offset:
            offset = 0, 0

        args = []

        if self.visible:
            args += super(Layer, self).get_graphics(offset=offset)
            offset = add_points(offset, self.position)

            for l in self.sub_layers:
                args += l.get_graphics(offset=offset)

            for sprite in self.get_sprites():
                args += sprite.get_graphics(offset=offset)

        return args