Beispiel #1
0
 def __init__(self,
              pos,
              nmb_size):
     GameObject.__init__(self)
     self.pos = pos
     self.nmb_size = nmb_size #nmb_size for 32x12
     self.size = Vector2(49,4+14*nmb_size+12)
     self.init_image()
     self.body = physics_manager.add_body(pos=self.pos+Vector2(7,3)+Vector2(31, self.size.y)/2,body_type=BodyType.static)
     physics_manager.add_box(body=self.body, pos=Vector2(),size=Vector2(31, self.size.y)/2,data=12)
Beispiel #2
0
    def scale(self, x, y):

        self.size = self.size*Vector2(x*CONST.scale_speed+1,
                                      y*CONST.scale_speed+1)
        """update body"""
        if self.body:
            physics_manager.remove_body(self.body)
            self.body = physics_manager.add_body(self.not_rot_pos, BodyType.static)
            physics_manager.add_box(self.body,Vector2(),self.size/2)
        self.update_rect()
Beispiel #3
0
 def __init__(self,pos,size,userData=0,speed=Vector2(-5,0)):
     GameObject.__init__(self)
     self.pos = pos
     self.parallax_factor = 1.0
     self.size = size
     self.show = True
     self.flip = False
     self.body = physics_manager.add_body(self.pos+self.size/2,BodyType.dynamic)
     physics_manager.add_box(self.body,Vector2(),Vector2(self.size.x/2,2),data=userData,sensor=True)
     physics_manager.move(self.body,vx=-5)
     self.anim = BulletAnimation(self)
Beispiel #4
0
def load_physic_objects(physics_data,image):
    if image is None:
        return
    body_type = get_element(physics_data, "type")
    if body_type:
        pos = Vector2()
        if image.pos:
            pos = image.pos
        if image.screen_relative_pos:
            pos = pos+image.screen_relative_pos*engine.get_screen_size()
        if image.size:
            pos = pos+image.size/2
        body_mass = get_element(physics_data, "mass")
        if body_mass is None:
            body_mass = 1
        if body_type == "dynamic":
            image.body = physics_manager.add_body(pos, BodyType.dynamic, mass=body_mass)
        elif body_type == "static":
            image.body = physics_manager.add_body(pos, BodyType.static, mass=body_mass)
        elif body_type == 'kinematic':
            image.body = physics_manager.add_body(pos, BodyType.kinematic, mass=body_mass)
    pos = (0,0)
    if image.pos:
        pos = image.pos
    if image.screen_relative_pos:
        pos = pos+image.screen_relative_pos*engine.get_screen_size()+image.size/2
    angle = get_element(physics_data, "angle")
    if angle:
        image.body.angle = angle*math.pi/180
    else:
        if image.body and image.angle != 0:
            if CONST.physics == 'b2':
                image.body.angle = image.angle*math.pi/180
            elif CONST.physics == 'pookoo':
                #TODO: set angle for body
                pass
            '''Set new pos for body'''
            v = image.size/2
            v.rotate(image.angle)
            pos = image.pos+v
            pos = pixel2meter(pos)
            if CONST.physics == 'b2':
                image.body.position = pos.get_tuple()
            elif CONST.physics == 'pookoo':
                #TODO: set pos for body
                pass
            
    fixtures_data = get_element(physics_data,"fixtures")
    if fixtures_data:
        for physic_object in fixtures_data:
            sensor = get_element(physic_object, "sensor")
            if sensor is None:
                sensor = False
            user_data = get_element(physic_object,"user_data")
            if user_data is None:
                user_data = image
            obj_type = get_element(physic_object, "type")
            if obj_type == "box":
                pos = get_element(physic_object,"pos")
                if not pos:
                    pos = Vector2()

                size = get_element(physic_object,"size")
                if not size:
                    size = image.size/2

                angle = get_element(physic_object,"angle")
                if angle is None:
                    
                    angle = 0
                image.fixtures.append(physics_manager.add_box(image.body, Vector2(pos), Vector2(size), angle, user_data, sensor))
            elif obj_type == "circle":
                pos = get_element(physic_object,"pos")
                if not pos:
                    pos = (0,0)
                radius = get_element(physic_object,"radius")
                if not radius:
                    radius = 1

                image.fixtures.append(physics_manager.add_circle(image.body,pos,radius,sensor,user_data))