Example #1
0
 def init_body(self, position):
     body_def = b2.b2BodyDef()
     body_def.position = position
     self.body = self.game_screen.world.CreateBody(body_def)
     self.body.userData = self
     shape_def = b2.b2CircleDef()
     shape_def.radius = 0.5
     shape_def.density = 1
     self.body.CreateShape(shape_def)
     self.body.SetMassFromShapes()
Example #2
0
 def __init__(self, level_actor, body_model):
     super(BodyActor, self).__init__(body_model)
     self.z = level_actor.z
     level_actor.z += 1
     body_def = b2.b2BodyDef()
     self.body = level_actor.world.CreateBody(body_def)
     self.body.userData = self
     for shape_model in body_model.shape_models:
         if isinstance(shape_model, CircleModel):
             shape_def = b2.b2CircleDef()
             shape_def.localPosition = self.body.GetLocalPoint(tuple(shape_model.center))
             shape_def.radius = shape_model.radius
         elif isinstance(shape_model, PolygonModel):
             shape_def = b2.b2PolygonDef()
             shape_def.vertices = [self.body.GetLocalPoint(tuple(v)) for v in shape_model.vertices]
         else:
             assert False
         shape_def.density = shape_model.density
         shape_def.friction = shape_model.friction
         shape_def.restitution = shape_model.restitution
         shape_def.filter.groupIndex = shape_model.group_index
         shape = self.body.CreateShape(shape_def)
         shape.userData = shape_model.color
     self.body.SetMassFromShapes()