def __init__(self, event_manager, world, area_id): SingleListener.__init__(self, event_manager) self.area_id = area_id self.world = world # Only keep weak references to the entities because they are owned by # the World itself, not by the area. They can move between areas, or # even be in no area at all. self.entities = weakref.WeakValueDictionary() # The tile map is a data structure that describes the fixed features of # the landscape. By fix, I mean that these features cannot move. # However, one can imagine that some of these features appear, # disappear or change. For example, a door can open. self.tile_map = tile.TileMap() # The entity map is here ONLY for performance purposes. It allows a # relatively quick access to the entities in a region. This helps us # limiting the number of entities to look for during collisions, or # when a creature is looking around for nearby victims. self.entity_map = EntityMap() # Useful for collision detection: entities are colliding if the # distance between them is smaller than the sum of their radii. Keeping # track of the biggest possible radius helps you delimiting the area # containing the entities you may be colliding with. Nothing beyond # your_radius + biggest_radius can touch you. self._biggest_entity_radius = 0 LOGGER.debug("Area %i created.", area_id)