Esempio n. 1
0
    def create_2body(self, pos):
        e1 = self.create_body(pos, 100, 'greencircle', mass=10)
        posx, posy = pos
        pos2 = posx, posy - 125
        e2 = self.create_body(pos2, 20, 'redcircle', mass=30, collision_type=0)

        body1 = self.gameworld.entities[e1].cymunk_physics.body
        body2 = self.gameworld.entities[e2].cymunk_physics.body

        pivot = PivotJoint(body1, body2, pos2)
        self.gameworld.physics.space.add(pivot)
Esempio n. 2
0
    def pivot_joint(self):
        entities = self.gameworld.entities
        physics = self.gameworld.system_manager['cymunk_physics']

        objs = [('batholder', 'bat')]
        for x in range(len(objs)):
            entity = entities[ent[objs[x][0]]]
            batholder = entity.cymunk_physics.body
            entity = entities[ent[objs[x][1]]]
            bat = entity.cymunk_physics.body

            anchr1 = (0, 40)
            anchr2 = (0, 0)

            bat_joint = PivotJoint(batholder, bat, anchr1, anchr2)
            physics.space.add_constraint(bat_joint)
Esempio n. 3
0
    def create_roundrect2body(self, pos):
        w = 100
        mass = 50
        col_shapes = []
        for x in (-w / 4, w / 4):
            for y in (-w / 4, w / 4):
                col_shapes.append({
                    'shape_type': 'circle',
                    'elasticity': .0,
                    'collision_type': 1,
                    'shape_info': {
                        'inner_radius': 0,
                        'outer_radius': w / 4,
                        'mass': mass / 4,
                        'offset': (x, y)
                    },
                    'friction': 1.0
                })
        physics_component = {
            'main_shape': 'circle',
            'velocity': (0, 0),
            'position': pos,
            'angle': 0,
            'angular_velocity': 0,
            'vel_limit': 250,
            'ang_vel_limit': radians(200),
            'mass': mass,
            'col_shapes': col_shapes
        }
        create_component_dict = {
            'cymunk_physics': physics_component,
            'rotate_renderer': {
                'texture': 'roundrect',
                'size': (w, w),
                'render': True
            },
            'position': pos,
            'rotate': 0,
        }
        component_order = [
            'position',
            'rotate',
            'rotate_renderer',
            'cymunk_physics',
        ]
        eid = self.gameworld.init_entity(create_component_dict,
                                         component_order)

        posx, posy = pos
        pos2 = posx, posy - w

        e2 = self.create_body(pos2,
                              20,
                              'redcircle',
                              mass=100,
                              collision_type=0)

        body1 = self.gameworld.entities[eid].cymunk_physics.body
        body2 = self.gameworld.entities[e2].cymunk_physics.body

        pivot = PivotJoint(body1, body2, pos2)
        self.gameworld.physics.space.add(pivot)
Esempio n. 4
0
 def joint(self, with_who, point):
     self.unjoint()
     self.joint_in_use = PivotJoint(self.body, with_who.body, point)
     self.space.add(self.joint_in_use)