X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=tabakrolletjie%2Frays.py;h=8b532784a46a80e97f354cb9686b6161fe2bbe8b;hb=ed21b64839c0b4f7f3309756e30ff34b2ff97571;hp=8a79c34c57b4c3ff89a7d31681c1c5ec0915f385;hpb=ee4a089ad17cc17ff85d2d86d5412eab3fd9038c;p=tabakrolletjie.git diff --git a/tabakrolletjie/rays.py b/tabakrolletjie/rays.py index 8a79c34..8b53278 100644 --- a/tabakrolletjie/rays.py +++ b/tabakrolletjie/rays.py @@ -12,7 +12,7 @@ from .constants import SCREEN_SIZE from .utils import debug_timer -def screen_rays(pos): +def screen_rays(): """ An iterable that returns ordered rays from pos to the edge of the screen, starting with the edge point (0, 0) and continuing clockwise in pymunk coordinates. @@ -40,7 +40,7 @@ def calculate_ray_polys(space, position, light_filter): vertices = [position] start, end = None, None ray_polys = [] - for ray in screen_rays(position): + for ray in screen_rays(): info = space.segment_query_first(position, ray, 1, light_filter) point = ray if info is None else info.point vertices.append(point) @@ -129,6 +129,20 @@ class RayPolyManager(object): def min_radius(self, value): self._min_radius = value or 0.0 + def serialize(self): + """ Return the required information from the ray_manager """ + if self._direction is None: + direction = None + spread = None + else: + direction = self._direction.angle_degrees + spread = math.degrees(self.spread) + return { + "radius_limits": (self._min_radius, self._max_radius), + "direction": direction, + "spread": spread, + } + def reaches(self, position): distance = self.position.get_distance(position) return (self._min_radius <= distance <= self._max_radius)