Exemplo n.º 1
0
 def get_current_room(self):
     distant_point = (0.0, 1e10)
     player_to_distance = (tuple(self.position), distant_point)
     for room in self.game.rooms:
         # Count the times it crosses the room's boundary. Odd = inside.
         cross_count = 0
         for wall in room.walls:
             if utils.lines_intersect(player_to_distance, wall):
                 cross_count += 1
         if cross_count % 2 == 1:
             return room
     
     # Inside no room
     return None
Exemplo n.º 2
0
    def contains_point(self, point):
        """True if the room contains the given 2D or 3D point.

        """
        # Three coords? Check Z first.
        if len(point) > 2:
            if not self.floor_height <= point[3] <= self.ceiling_height:
                return False

        # Check it's inside the boundaries
        distant_point = (0.0, 1e10)
        player_to_distance = ((point[0], point[1]), distant_point)
        # Count the times it crosses the room's boundary. Odd = inside.
        cross_count = 0
        for wall in self.walls:
            if utils.lines_intersect(player_to_distance, wall):
                cross_count += 1
        if cross_count % 2 == 1:
            return True
        else:
            return False
Exemplo n.º 3
0
 def check_walls(self):
     """Make sure the vertices are valid.
     
     # >>> a = 0.0, 0.0  # c
     # >>> b = 1.0, 0.0  # 
     # >>> c = 0.0, 1.0  # a    b
     # >>> Room((a, b, c)).check_walls()
     
     Checks for self-intersection and winding.
     
     """
     # Make sure every vertex is unique
     if not len(set(self.vertices)) == len(self.vertices):
         raise InvalidRoomError("Vertices aren't unique.")
     
     # Check for intersection. Loop over every pair of walls:
     for wall_a, wall_b in itertools.combinations(self.walls, 2):
         if utils.lines_intersect(wall_a, wall_b):
             raise InvalidRoomError("Walls intersect: %s, %s" %
                                    (wall_a, wall_b))
     
     # Check winding:
     self.check_winding()