Changeset 474:9775055ba2f0 for nagslang


Ignore:
Timestamp:
Sep 7, 2013, 2:43:44 PM (7 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
rebase_source:
b731a2e817ec986ddf825a04dfe14f8767004bb1
Message:

Prettier bulkheads.

Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r444 r474  
    455455        super(Bulkhead, self).__init__(
    456456            SingleShapePhysicser(space, self.shape),
    457             render.ShapeStateRenderer(),
     457            render.BulkheadRenderer(),
    458458            puzzler,
    459459        )
  • nagslang/render.py

    r454 r474  
    77
    88from nagslang.options import options
    9 from nagslang.utils import tile_surface
     9from nagslang.utils import tile_surface, vec_from_angle
    1010from nagslang.widgets.text import LabelWidget, MultiLineWidget
    1111
     
    4545    def render(self, surface):
    4646        pass
     47
     48
     49class 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
     59    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)
     63        pygame.draw.line(
     64            surface, pygame.color.THECOLORS['black'], a, b, 8)
     65        pygame.draw.line(
     66            surface, pygame.color.THECOLORS['lightblue'], ai, bi, 6)
     67
     68    def render(self, surface):
     69        shape = self.game_object.get_shape()
     70        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)
     73            self.draw_bulkhead_line(surface, shape.a, ai)
     74            self.draw_bulkhead_line(surface, bi, shape.b)
     75        else:
     76            mid = shape.a + (shape.b - shape.a) / 2
     77            self.draw_bulkhead_line(surface, shape.a, mid)
     78            self.draw_bulkhead_line(surface, mid, shape.b)
    4779
    4880
Note: See TracChangeset for help on using the changeset viewer.