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/level.py

    r485 r488  
    33import pygame
    44import pygame.locals as pgl
     5import pymunk
    56
    67from nagslang import collectable
     
    89from nagslang import enemies
    910from nagslang import puzzle
    10 from nagslang.utils import tile_surface
     11from nagslang.utils import (
     12    tile_surface, points_to_pygame, extend_line, points_to_lines)
    1113from nagslang.resources import resources
    1214from nagslang.yamlish import load, dump
     
    184186        self._tile_image = None
    185187
    186     def point_to_pygame(self, pos):
    187         # Convert a point from pymunk (which is what we store)
    188         # to pygame for drawing
    189         return (pos[0], self.y - pos[1])
    190 
    191188    def get_walls(self):
    192189        walls = self.polygons.values()
     
    194191        return walls
    195192
     193    def _draw_wall_line(self, points, width, colour, extend):
     194        for line in points_to_lines(points):
     195            if extend:
     196                line = extend_line(
     197                    pymunk.Vec2d(line[0]), pymunk.Vec2d(line[1]), extend)
     198            line = points_to_pygame(self._surface, line)
     199            pygame.draw.line(self._surface, colour, line[0], line[1], width)
     200
     201    def _draw_walls_lines(self, width, colour, extend):
     202        for index, polygon in self.polygons.items():
     203            self._draw_wall_line(polygon, width, colour, extend)
     204        for line in self.lines:
     205            self._draw_wall_line(line, width, colour, extend)
     206
    196207    def _draw_walls(self):
    197         for index, polygon in self.polygons.items():
    198             color = POLY_COLORS.get(index, pygame.color.THECOLORS['black'])
    199             if len(polygon) > 1:
    200                 pointlist = [self.point_to_pygame(p) for p in polygon]
    201                 pygame.draw.lines(self._surface, color, False, pointlist, 2)
    202         for line in self.lines:
    203             pointlist = [self.point_to_pygame(p) for p in line]
    204             pygame.draw.lines(self._surface, LINE_COLOR, False, pointlist, 2)
     208        inner_colour = pygame.color.THECOLORS['red']
     209        mid_colour = pygame.color.THECOLORS['orange']
     210        outer_colour = pygame.color.THECOLORS['yellow']
     211        self._draw_walls_lines(5, outer_colour, 0)
     212        self._draw_walls_lines(3, outer_colour, 1)
     213        self._draw_walls_lines(3, mid_colour, 0)
     214        self._draw_walls_lines(1, inner_colour, 0)
    205215
    206216    def get_background(self):
     
    222232        for index, polygon in self.polygons.items():
    223233            if len(polygon) > 1:
    224                 pointlist = [self.point_to_pygame(p) for p in polygon]
     234                pointlist = points_to_pygame(self._surface, polygon)
    225235                # filled polygons
    226236                color = white
Note: See TracChangeset for help on using the changeset viewer.