Exemplo n.º 1
0
class Player:
    def __init__(self, name, space):
        self.name = name
        self.animation = AnimationController()
        self.body = pymunk.Body(1, 1)  # Create a Body with mass and moment
        self.body.position = 0, 0  # Set the position of the body
        self.velocity_scale = 10.0

        shape = pymunk.Circle(self.body, 10, (0, 0))
        shape.friction = 0.5
        shape.collision_type = 2

        space.add(self.body,
                  shape)  # Add both body and shape to the simulation

    def update_velocity(self, vx, vy):
        scale = self.velocity_scale

        self.body.velocity = (vx, vy)

    def to_json(self):
        obj = {}

        obj['name'] = self.name
        obj['position'] = {
            'x': self.body.position.x,
            'y': self.body.position.y
        }
        obj['animation'] = self.animation.to_json()
        obj['velocity'] = {
            'vx': self.body.velocity.x,
            'vy': self.body.velocity.y
        }

        return obj
Exemplo n.º 2
0
class Objects:

    def __init__(self, name, space):
        self.name = name
        self.animation = AnimationController()
        self.body = pymunk.Body(1,1)  # Create a Body with mass and moment
        self.body.position = 0, 0      # Set the position of the body

        self.poly = pymunk.Poly.create_box(self.body) # Create a box shape and attach to body
        space.add(self.body, self.poly)       # Add both body and shape to the simulation

    def to_json(self):
        obj = {}

        obj['name'] = self.name
        obj['position'] = {'x': self.body.position.x, 'y': self.body.position.y }
        obj['animation'] = self.animation.to_json()
    
        return obj