Exemple #1
0
    def __init__(self, verts, color=(1, 1, 1), draw=True, friction=None):
        self.indexes = earcut(verts)

        if draw:
            size = len(verts) // 2
            self.dl = self.batch.add_indexed(
                size,
                gl.GL_TRIANGLES,
                self.group,
                self.indexes,
                ('v2f/static', np.array(verts) / SPACE_SCALE),
                ('t2f/static', np.array(verts) / (512 * SPACE_SCALE * 2)),
                ('c3f/static', [c for _ in range(size) for c in color]),
            )
        else:
            self.dl = None

        self.shapes = []
        verts = np.array(verts)
        tris = verts.reshape(-1, 2)[self.indexes].reshape(-1, 3, 2)
        for tri in tris:
            shp = Poly(space.static_body, tri)
            shp.friction = friction or self.FRICTION
            shp.elasticity = self.ELASTICITY
            space.add(shp)
            self.shapes.append(shp)
Exemple #2
0
def __createPolyShape(info: 'Dict[str, Any]') -> 'Poly':

    points = tuple(
        (point.get('x', 0), point.get('y', 0)) for point in info['Point'])
    shape = Poly(None, points)

    shape.mass = info['mass']
    shape.elasticity = info.get('elasticity', 0.5)
    shape.friction = info.get('friction', 0.5)

    return shape
Exemple #3
0
 def create_shape(self):
     shape = Poly(self.body, self.item.geometry.verts, (0, 0))
     shape.elasticity = 1.0
     shape.friction = 0.0
     return shape
Exemple #4
0
 def get_shape(self, body):
     shape = Poly(body, self.verts, (0, 0))
     shape.elasticity = 0.5
     shape.friction = 10.0
     return shape