- self._surrounding_map = None
- self._surroundings_offset = None
-
- def get_surroundings_offset(self):
- if self._surroundings_offset is not None:
- return self._surroundings_offset
- offset = YX(self.position[0].y * self.game.map_size.y +
- self.position[1].y - self._radius,
- self.position[0].x * self.game.map_size.x +
- self.position[1].x - self._radius)
- self._surroundings_offset = offset
- return self._surroundings_offset
-
- def get_surrounding_map(self):
- if self._surrounding_map is not None:
- return self._surrounding_map
- self._surrounding_map = Map(size=YX(self._radius*2+1, self._radius*2+1))
- offset = self.get_surroundings_offset()
- for pos in self._surrounding_map:
- offset_pos = pos + offset
- absolutize = self.game.map_geometry.absolutize_coordinate
- big_yx, small_yx = absolutize(self.game.map_size, (0,0), offset_pos)
- map_ = self.game.get_map(big_yx, False)
- if map_ is None:
- map_ = Map(size=self.game.map_size)
- self._surrounding_map[pos] = map_[small_yx]
- return self._surrounding_map
+ self._surroundings = None
+
+ @property
+ def view_offset(self):
+ return self.game.map_geometry.get_view_offset(self.game.map_size,
+ self.position,
+ self._radius)
+
+ @property
+ def surroundings(self):
+ if self._surroundings is not None:
+ return self._surroundings
+ s = self.game.map_geometry.get_view(self.game.map_size,
+ self.game.get_map,
+ self._radius, self.view_offset)
+ self._surroundings = s
+ return self._surroundings