示例#1
0
def get_collision_direction(entity: DynamicEntity, other: Entity):
    """Get the direction where from which a collision event occurred.

    Parameters:
        entity (DynamicEntity): Colliding entity.
        other (Entity): The entity with which the colliding entity collided.

    Returns:
        (str): The direction the collision occurred in.

        "A" for Above
        "B" for Below
        "R" for Right
        "L" for Left
    """
    bb = entity.get_shape().bb
    cx, cy = bb.center()
    lx = cx - (cx - bb.left) / 2
    rx = cx + (cx - bb.left) / 2

    # direction mapping
    directions = [((cx, bb.top), ABOVE), ((lx, bb.top), ABOVE),
                  ((rx, bb.top), ABOVE), ((cx, bb.bottom), BELOW),
                  ((lx, bb.bottom), BELOW), ((rx, bb.bottom), BELOW),
                  ((bb.left, cy), RIGHT), ((bb.right, cy), LEFT)]

    for pos, result in directions:
        if other.get_shape().point_query(pos)[0] < 0:
            return result
示例#2
0
 def remove_thing(self, thing: Entity):
     """Removes a thing from the world"""
     self._space.remove(thing.get_shape())