Ignore:
Timestamp:
09/07/13 15:40:59 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Better wall and bulkhead drawing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/render.py

    r474 r488  
    77
    88from nagslang.options import options
    9 from nagslang.utils import tile_surface, vec_from_angle
     9from nagslang.utils import (
     10    tile_surface, vec_from_angle, points_to_pygame, extend_line)
    1011from nagslang.widgets.text import LabelWidget, MultiLineWidget
    1112
     
    4849
    4950class BulkheadRenderer(Renderer):
    50     def _offset_point(self, vec, to_vec, length):
    51         offset = vec_from_angle((to_vec - vec).angle, abs(length))
    52         if length < 0:
    53             offset = -offset
    54         return vec + offset
    55 
    56     def _to_pygame(self, surface, *points):
    57         return [pymunk.pygame_util.to_pygame(p, surface) for p in points]
    58 
    5951    def draw_bulkhead_line(self, surface, a, b):
    60         ai = self._offset_point(a, b, 2)
    61         bi = self._offset_point(b, a, 2)
    62         a, b, ai, bi = self._to_pygame(surface, a, b, ai, bi)
     52        ai, bi = extend_line(a, b, -2)
     53        a, b, ai, bi = points_to_pygame(surface, (a, b, ai, bi))
    6354        pygame.draw.line(
    64             surface, pygame.color.THECOLORS['black'], a, b, 8)
     55            surface, pygame.color.THECOLORS['black'], a, b, 7)
    6556        pygame.draw.line(
    66             surface, pygame.color.THECOLORS['lightblue'], ai, bi, 6)
     57            surface, pygame.color.THECOLORS['lightblue'], ai, bi, 5)
    6758
    6859    def render(self, surface):
    6960        shape = self.game_object.get_shape()
    7061        if self.game_object.puzzler.get_state():
    71             ai = self._offset_point(shape.a, shape.b, 10)
    72             bi = self._offset_point(shape.b, shape.a, 10)
     62            offset = vec_from_angle((shape.b - shape.a).angle, 10)
     63            ai = shape.a + offset
     64            bi = shape.b - offset
    7365            self.draw_bulkhead_line(surface, shape.a, ai)
    7466            self.draw_bulkhead_line(surface, bi, shape.b)
Note: See TracChangeset for help on using the changeset viewer.