home · contact · privacy
Minor refactorings / re-namings.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 30 Apr 2019 18:29:21 +0000 (20:29 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 30 Apr 2019 18:29:21 +0000 (20:29 +0200)
new/plomrogue/mapping.py
new/plomrogue/things.py

index bec311b56e5064258ec4a7c3cc85869d0cfa546b..9826e6887eb9571cdd53349f9217184321000cf8 100644 (file)
@@ -90,7 +90,7 @@ class MapGeometry():
         pos_x = pos[1].x + (maps_size.x * pos[0].x) - offset.x
         return YX(pos_y, pos_x)
 
-    def absolutize_coordinate(self, map_size, big_yx, little_yx):
+    def correct_double_coordinate(self, map_size, big_yx, little_yx):
 
         def adapt_axis(axis):
             maps_crossed = little_yx[axis] // map_size[axis]
@@ -105,8 +105,9 @@ class MapGeometry():
     def move(self, start_pos, direction, map_size):
         mover = getattr(self, 'move_' + direction)
         big_yx, little_yx = start_pos
-        unadapted_target = mover(little_yx)
-        return self.absolutize_coordinate(map_size, big_yx, unadapted_target)
+        uncorrected_target = mover(little_yx)
+        return self.correct_double_coordinate(map_size, big_yx,
+                                              uncorrected_target)
 
 
 
index 2e97541a8cb2416eaa3ead7bad023c4b9d75ce3d..5d1c7bce1b72bf21b7fdd23a64a67998236019aa 100644 (file)
@@ -254,11 +254,10 @@ class ThingAnimate(Thing):
     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
+        y_long = self.position[0].y * self.game.map_size.y + self.position[1].y
+        x_long = self.position[0].x * self.game.map_size.x + self.position[1].x
+        yx_to_origin = YX(y_long, x_long)
+        self._surroundings_offset = yx_to_origin - YX(self._radius, self._radius)
         return self._surroundings_offset
 
     def get_surrounding_map(self):
@@ -267,9 +266,8 @@ class ThingAnimate(Thing):
         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)
+            correct = self.game.map_geometry.correct_double_coordinate
+            big_yx, small_yx = correct(self.game.map_size, (0,0), pos + offset)
             map_ = self.game.get_map(big_yx, False)
             if map_ is None:
                 map_ = Map(size=self.game.map_size)