Exemplo n.º 1
0
class Platform(object):

    def __init__(self, x, y, width=400, height=50):
        self.width = width
        self.height = height

        verts = [
            (- self.width / 2, - self.height / 2),# left top
            (- self.width / 2, + self.height / 2),# left bottom
            (+ self.width / 2, + self.height / 2),# right bottom
            (+ self.width / 2, - self.height / 2),# right top
        ]
        verts = map(Vec2d, verts)
        self.mass = self.width * self.height * 1
        self.body = Body(
            self.mass, moment_for_poly(self.mass, verts))
        self.body.position = (x, y)
        self.start_pos = Vec2d(x, y)
        self.shape = Poly(self.body, verts, (0, 0))


    @property
    def verts(self):
        return self.shape.get_points()        

    @property
    def centre(self):
        verts = self.verts
        return (verts[0] + verts[2]) / 2
Exemplo n.º 2
0
class GameRect(object):

    def __init__(self, x, y, width, height):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.mass = self.width * self.height / 10000
        self.layers = LayerType.EVERYTHING # collide with everything
        self.status = None


    def get_verts(self):
        return [
            (+ self.width / 2, - self.height / 2), # right bottom
            (- self.width / 2, - self.height / 2), # left bottom
            (- self.width / 2, + self.height / 2), # left top
            (+ self.width / 2, + self.height / 2), # right top
        ]


    def create_body(self):
        verts = map(Vec2d, self.get_verts())
        self.body = Body(self.mass, moment_for_poly(self.mass, verts))
        self.body.position = (self.x, self.y)
        self.shape = Poly(self.body, verts, (0, 0))
        self.shape.layers = self.layers
        # this is so you can get to it from collision handlers.
        #     eg. arbiter.shapes[0].parent 
        self.shape.parent = self


    def update(self):
        pass


    def add_to_space(self, space):
        space.add(self.body)
        space.add(self.shape)

    def remove_from_space(self, space):
        space.remove(self.body)
        space.remove(self.shape)

    @property
    def verts(self):
        "This is the position of the item's verts as calculated by pymunk"
        return self.shape.get_points()        
Exemplo n.º 3
0
class GameRect(object):
    def __init__(self, x, y, width, height):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.mass = self.width * self.height / 10000
        self.layers = LayerType.EVERYTHING  # collide with everything
        self.status = None

    def get_verts(self):
        return [
            (+self.width / 2, -self.height / 2),  # right bottom
            (-self.width / 2, -self.height / 2),  # left bottom
            (-self.width / 2, +self.height / 2),  # left top
            (+self.width / 2, +self.height / 2),  # right top
        ]

    def create_body(self):
        verts = map(Vec2d, self.get_verts())
        self.body = Body(self.mass, moment_for_poly(self.mass, verts))
        self.body.position = (self.x, self.y)
        self.shape = Poly(self.body, verts, (0, 0))
        self.shape.layers = self.layers
        # this is so you can get to it from collision handlers.
        #     eg. arbiter.shapes[0].parent
        self.shape.parent = self

    def update(self):
        pass

    def add_to_space(self, space):
        space.add(self.body)
        space.add(self.shape)

    def remove_from_space(self, space):
        space.remove(self.body)
        space.remove(self.shape)

    @property
    def verts(self):
        "This is the position of the item's verts as calculated by pymunk"
        return self.shape.get_points()