示例#1
0
文件: entity.py 项目: Fiona/Myrmidon
 def collision_point_calculate_point(self):
     """Returns the coordinates of the collision point to use, taking into account
     any offset assigned to collision_point_offset.
     """
     point = (self.x, self.y)
     if not self.collision_offset is None:
         rot = Game.rotate_point(self.collision_offset[0], self.collision_offset[1], self.rotation)
         point = (point[0] + rot[0], point[1] + rot[1])
     return point
示例#2
0
文件: entity.py 项目: Fiona/Myrmidon
    def collision_rectangle_calculate_corners(self):
        """This method is used as an optimisation for recangle collisions.
        We store the location of corners and only do it either once per frame
        or if a relevant value has changed. (x/y/rotation/scale/centre_point)

        Returns a dictionary containing four tuples, 'ul', 'ur', 'll', 'lr'.
        The tuples are coordinates pointing to the four corners of the rotated and
        scaled rectangle (upper left, upper right, lower left and lower right)"""
        if not self._collision_rectangle_recalculate_corners:
            return self._collision_rectangle_calculated_corners

        # Determine the size of the rectangle to use
        width, height = self.collision_rectangle_size()

        # Get the real x/y
        centre = self.get_centre_point()
        x = self.x - centre[0]
        y = self.y - centre[1]

        if not self.collision_offset is None:
            x += self.collision_offset[0]
            y += self.collision_offset[1]

        # Rotate each point of the rectangle as the Entitiy is to calculate
        # it's true position.
        rot = Game.rotate_point(0, 0, self.rotation)
        self._collision_rectangle_calculated_corners['ul'] = float(x + rot[0]), float(y + rot[1])
        rot = Game.rotate_point(width, 0, self.rotation)
        self._collision_rectangle_calculated_corners['ur'] = float(x + rot[0]), float(y + rot[1])
        rot = Game.rotate_point(0, height, self.rotation)
        self._collision_rectangle_calculated_corners['ll'] = float(x + rot[0]), float(y + rot[1])
        rot = Game.rotate_point(width, height, self.rotation)
        self._collision_rectangle_calculated_corners['lr'] = float(x + rot[0]), float(y + rot[1])

        # Flag so we don't do this more than we need to.
        self._collision_rectangle_recalculate_corners = False

        return self._collision_rectangle_calculated_corners