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

    r387 r488  
    22import pygame.locals as pgl
    33
    4 from pymunk.vec2d import Vec2d
     4import pymunk
     5import pymunk.pygame_util
    56
    67
     
    1617
    1718def vec_from_angle(angle, length=1):
    18     vec = Vec2d(length, 0)
     19    vec = pymunk.Vec2d(length, 0)
    1920    vec.angle = angle
    2021    return vec
     
    2223
    2324def vec_with_length(coords, length=1):
    24     vec = Vec2d(coords)
    25     # Don't crash if we're created a zero length vector
     25    vec = pymunk.Vec2d(coords)
     26    # Don't crash if we've created a zero length vector
    2627    if vec.length != 0:
    2728        vec.length = length
    2829    return vec
     30
     31
     32def points_to_lines(points):
     33    if len(points) < 2:
     34        return
     35    last_point = points[0]
     36    for point in points[1:]:
     37        yield (last_point, point)
     38        last_point = point
     39
     40
     41def extend_line(a, b, length):
     42    offset = vec_from_angle((a - b).angle, abs(length))
     43    if length < 0:
     44        offset = -offset
     45    return (a + offset, b - offset)
     46
     47
     48def points_to_pygame(surface, points):
     49    return [pymunk.pygame_util.to_pygame(p, surface) for p in points]
    2950
    3051
Note: See TracChangeset for help on using the changeset viewer.