def init_body(self, position): body_def = b2.b2BodyDef() body_def.position = position self.body = self.game_screen.world.CreateBody(body_def) shape_def = b2.b2PolygonDef() shape_def.SetAsBox(3.5, 1) self.body.CreateShape(shape_def)
def init_body(self, position, linear_velocity, sensor, static): body_def = b2.b2BodyDef() body_def.position = position self.body = self.game_screen.world.CreateBody(body_def) self.body.userData = self shape_def = b2.b2PolygonDef() shape_def.SetAsBox(self.width / 2, config.cloud_height / 2) shape_def.isSensor = sensor shape_def.density = 1 self.body.CreateShape(shape_def) if static: self.mass = 0 else: self.body.SetMassFromShapes() self.mass = self.body.massData.mass self.body.linearVelocity = linear_velocity
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()