Пример #1
0
    def __init__(self, world, cl, res: Resources, pos, vector,
                 game_object_group, *groups):
        super().__init__(world, cl, game_object_group, *groups)

        self.draw_shadow = False
        self.ignore_ray_casting = True
        self.set_init_image(paint_images([res.image_bullet], lambda x: (120, 0, 200, x[3]))[0])
        self.vector = pygame.Vector2(vector).normalize()
        pos = pygame.Vector2(pos) + self.vector * 100
        self.rect.center = pos
        self.res = res

        self.impulse = 2.5
        radius = 12
        shape = b2CircleShape()
        shape.radius = radius / PPM
        fd = B2Factory.create_fixture(shape, 0.3, 0, 1)
        self.body = B2Factory.create_body(
            world, b2_dynamicBody, fd, b2_coords(pos) / PPM)
        self.body.userData = self
        self.body.fixedRotation = True
        self.body.ApplyLinearImpulse(b2_coords(self.vector) * self.impulse, self.body.GetWorldPoint((0, 0)), True)

        self.timer = 0
        self.timeout = 3
        self.collide = False
Пример #2
0
    def __init__(self, world, cl, res: Resources, pos, game_object_group,
                 *groups):
        super().__init__(world, cl, game_object_group, *groups)
        self.set_init_image(res.image_turret)
        self.rect.center = pos
        self.res = res
        self.force = 10**4
        self.base = TurretBase(self.world, self.cl, self.res, pos,
                               self.game_object_group)

        radius = 40
        shape = b2CircleShape()
        shape.radius = radius / PPM
        fd = B2Factory.create_fixture(shape, 1, 0.1, 0.2)
        self.body = B2Factory.create_body(world, b2_dynamicBody, fd,
                                          b2_coords(pos) / PPM)
        shape = b2PolygonShape()
        shape.SetAsBox(28 / 2 / PPM, 81 / 2 / PPM, (0, 81 / 2 / PPM), 0)
        fd = B2Factory.create_fixture(shape, 1, 0.1, 0.2)
        self.body.CreateFixture(fd)
        self.body.userData = self
        self.body.angularDamping = 3

        shape = b2PolygonShape()
        shape.SetAsBox(*b2Vec2(10, 10) / 4 / PPM)
        fd = B2Factory.create_fixture(shape)
        self.center_body = B2Factory.create_body(world, b2_staticBody, fd,
                                                 b2_coords(pos) / PPM)
        jd = b2RevoluteJointDef()
        jd.bodyA = self.body
        jd.bodyB = self.center_body
        self.world.CreateJoint(jd)

        self.shot_timer = 0
        self.shot_timeout = 1
Пример #3
0
    def get_random_point(self):
        rand_vec = pygame.Vector2(random.uniform(-1, 1),
                                  random.uniform(-1, 1))
        rand_vec *= 300

        point1: b2Vec2 = b2_coords(self.get_position()) / PPM
        point2 = point1 + b2_coords(rand_vec) / PPM
        ray = RayCastCallback(point1, point2)
        self.world.RayCast(ray, point1, point2)
        if ray.reports:
            ray_report = ray.reports[-1]
            point2 = ray_report.point
        return b2_coords(point2) * PPM
Пример #4
0
    def is_near(self, car):
        point1 = self.get_position()
        point2 = car.get_position()
        if pygame.Vector2(point1).distance_to(point2) > self.max_detect_radius:
            return False
        ray = RayCastCallback(b2_coords(point1) / PPM, b2_coords(point2) / PPM)
        self.world.RayCast(ray, b2_coords(point1) / PPM, b2_coords(point2) / PPM)
        ray_report = ray.reports[-1]
        ray_report: RayFixtureReport

        if ray_report:
            data = ray_report.fixture.body.userData
            if data == car:
                return b2_coords(ray_report.point) * PPM
        return False
Пример #5
0
    def __init__(self, world, cl, image, width,
                 density, friction, restitution, body_type, point1, point2,
                 game_object_group, *groups):
        super().__init__(world, cl, game_object_group, *groups, connects=False)

        point1, point2 = sorted([point1, point2], key=lambda x: x[1])
        size = (width, pygame.Vector2(point1).distance_to(point2))
        self.sin = (point2[0] - point1[0]) / size[1]
        angle = math.asin(self.sin)
        self.size = tuple(map(int, size))
        self.center = (pygame.Vector2(point1) + pygame.Vector2(point2)) / 2
        self.image_stick = pygame.transform.scale(image, self.size).convert_alpha()
        self.width = width
        self.start = point1
        self.end = point2

        # Скругления
        shape = b2PolygonShape()
        shape.SetAsBox(*b2Vec2(size) / 2 / PPM)
        fd1 = B2Factory.create_fixture(shape, density, friction, restitution)
        self.body = B2Factory.create_body(world, body_type, fd1, b2_coords(self.center) / PPM)
        shape = b2CircleShape()
        shape.radius = width / 2 / PPM
        shape.pos = 0, size[1] / 2 / PPM
        fd2 = B2Factory.create_fixture(shape, density, friction, restitution)
        shape = b2CircleShape()
        shape.radius = width / 2 / PPM
        shape.pos = 0, -size[1] / 2 / PPM
        fd3 = B2Factory.create_fixture(shape, density, friction, restitution)
        self.body.CreateFixture(fd2)
        self.body.CreateFixture(fd3)

        self.body.userData = self
        self.body.angle = angle
Пример #6
0
    def __init__(self, world, cl, res: Resources, point1, point2,
                 game_object_group, *groups):
        super().__init__(world, cl, game_object_group, *groups, connects=False)

        self.draw_shadow = False
        self.ignore_ray_casting = True

        width = 10
        point1, point2 = sorted([point1, point2], key=lambda x: x[1])
        size = (width, pygame.Vector2(point1).distance_to(point2) + width * 1)
        center = (pygame.Vector2(point1) + pygame.Vector2(point2)) / 2
        sin = (point2[0] - point1[0]) / (size[1] - width * 1)
        angle = math.asin(sin)
        image = pygame.transform.scale(res.image_wall, tuple(map(int, size)))

        self.start = point1
        self.end = point2
        self.set_init_image(image)
        self.rect.center = center

        shape = b2PolygonShape()
        shape.SetAsBox(*b2Vec2(size) / 2 / PPM)
        fd1 = B2Factory.create_fixture(shape, 2, 0.1, 0.5, True)

        self.body = B2Factory.create_body(world, b2_staticBody, fd1,
                                          b2_coords(center) / PPM)
        self.body.userData = self
        self.body.angle = angle

        self.set_rotated_sprite(self.body, self.get_init_image())
Пример #7
0
    def __init__(self, world, cl, res: Resources, pos, game_object_group,
                 *groups):
        super().__init__(world, cl, game_object_group, *groups, connects=False)

        self.ignore_ray_casting = True
        self.draw_shadow = False

        image = res.image_tire_particle
        self.set_init_image(image)
        self.rect.center = pos

        shape = b2CircleShape()
        shape.radius = self.image.get_size()[0] / 2 / PPM
        fd = B2Factory.create_fixture(shape, 1, 0.1, 0.5, True)
        self.body = B2Factory.create_body(world, b2_dynamicBody, fd,
                                          b2_coords(pos) / PPM)
        self.body.userData = self
        self.body.linearDamping = 3
        self.body.fixedRotation = True
        impulse = 0.5
        self.body.ApplyLinearImpulse((random.uniform(
            -impulse, impulse), random.uniform(-impulse, impulse)),
                                     self.body.GetWorldPoint((0, 0)), True)

        self.timer = 0
        self.timeout = 0.2
Пример #8
0
    def __init__(self, world, cl, image, car, max_forward_speed,
                 max_backward_speed, max_drive_force, max_lateral_impulse,
                 angular_friction_impulse, linear_friction_impulse, density,
                 restitution, friction, game_object_group, *groups):
        self.shadow_color = PLAYER_CAR_SHADOW_COLOR
        super().__init__(world, cl, game_object_group, *groups)

        size = 10, 24
        self.car = car
        self.set_init_image(image)
        self.rect = pygame.Rect((0, 0), size)

        shape = b2PolygonShape()
        shape.SetAsBox(*b2Vec2(*self.rect.size) / 2 / PPM)
        fd = B2Factory.create_fixture(shape, density, restitution, friction)
        self.body = B2Factory.create_body(world, b2_dynamicBody, fd,
                                          b2_coords(self.rect.center) / PPM)
        self.body.userData = self

        self.control_state = 0
        self.current_traction = 1
        self.grounds = []

        self.acceleration_time = 1
        self.min_acc = 0.3
        self.acceleration = self.min_acc

        self.set_characteristics(max_forward_speed, max_backward_speed,
                                 max_drive_force, max_lateral_impulse,
                                 angular_friction_impulse,
                                 linear_friction_impulse)
Пример #9
0
 def explode(self):
     particles = paint_images(
         self.res.explosion_particles, lambda x: (10, 90, 10, x[3]))
     Explosion.spawn_particles(self.world, self.cl, self.res,
                               b2_coords(self.body.position) * PPM, particles, 15, 5,
                               self.game_object_group, timeout=1)
     self.dispose()
Пример #10
0
    def __init__(self,
                 world,
                 cl,
                 res: Resources,
                 car,
                 vector,
                 explosion_callback,
                 game_object_group,
                 *groups,
                 damage_me=True):
        super().__init__(world, cl, game_object_group, *groups)

        self.draw_shadow = False
        self.ignore_ray_casting = True
        self.animation = Animation(res.animation_fireball, 6, 20)
        self.image = self.animation.get_frame()
        self.vector = pygame.Vector2(vector).normalize()
        pos = car.get_position() + self.vector * 10
        self.rect = pygame.Rect(0, 0, *self.image.get_size())
        self.rect.center = pos
        self.res = res
        self.car = car
        self.callback = explosion_callback
        self.damage_me = damage_me

        self.impulse = 5
        self.force = 15
        radius = 20
        shift = 40, 0

        shape = b2CircleShape()
        shape.radius = radius / PPM
        shape.pos = b2Vec2(shift) / PPM
        fd = B2Factory.create_fixture(shape, 0.3, 0.1, 0.5)
        self.body = B2Factory.create_body(world, b2_dynamicBody, fd,
                                          b2_coords(pos) / PPM)
        self.body.userData = self
        self.body.angle = math.radians(
            pygame.Vector2(self.vector).angle_to((1, 0)))
        self.body.fixedRotation = True
        self.body.linearDamping = 0.3
        self.body.ApplyLinearImpulse(
            b2_coords(self.vector) * self.impulse,
            self.body.GetWorldPoint((0, 0)), True)

        self.timer = 0
        self.collide = False
Пример #11
0
 def update(self, dt: float, events):
     self.animation.update(dt)
     self.timer += dt
     if self.timer > 1.5 or self.collide:
         self.explode()
     self.body.ApplyForce(
         b2_coords(self.vector) * self.force, self.body.GetWorldPoint(
             (0, 0)), True)
Пример #12
0
 def update(self, dt: float, events):
     self.timer += dt
     if self.timer > 3:
         BombExplosion(self.world, self.cl, self.res,
                       b2_coords(self.body.position) * PPM,
                       self.game_object_group)
         self.explosion_callback()
         self.dispose()
Пример #13
0
    def update(self, dt: float, events):
        if self.is_broken:
            self.broken_timer += dt
            if self.broken_timer > self.dispose_timeout:
                for i in self.tires:
                    particles = paint_images(self.res.explosion_particles,
                                             lambda x: (0, 0, 0, x[3]))
                    FireballExplosion.explosion.spawn_particles(
                        self.world, self.cl, self.res,
                        b2_coords(i.body.position) * PPM, particles, 3, 2,
                        self.game_object_group)
                    i.dispose()
                particles = paint_images(
                    self.res.explosion_particles, lambda x:
                    (*self.color_particles, x[3]))
                FireballExplosion.explosion.spawn_particles(
                    self.world, self.cl, self.res,
                    b2_coords(self.body.position) * PPM, particles, 7, 10,
                    self.game_object_group)
                self.dispose()
            return

        # Update turn
        curr_angle = self.joints[0].angle

        v = self.control_state & (C_LEFT | C_RIGHT)
        desired_angle = 0
        if v == C_LEFT:
            desired_angle = self.lock_angle
        elif v == C_RIGHT:
            desired_angle = -self.lock_angle
        turn = desired_angle - curr_angle
        if abs(turn) > self.speed_tire_rotate / 2 * dt:
            if turn > 0:
                turn = self.speed_tire_rotate * dt
            else:
                turn = -self.speed_tire_rotate * dt
        else:
            turn = 0

        new_angle = curr_angle + turn
        if new_angle > self.lock_angle * 2:
            new_angle = 0
        self.joints[0].SetLimits(new_angle, new_angle)
        self.joints[1].SetLimits(new_angle, new_angle)
Пример #14
0
 def on_explosion(self, obj_from, power):
     if type(obj_from) == BombExplosion:
         if power > 200:
             particles = paint_images(self.res.explosion_particles,
                                      lambda x: (0, 0, 0, x[3]))
             Explosion.spawn_particles(self.world, self.cl, self.res,
                                       b2_coords(self.body.position) * PPM,
                                       particles, 15, 10,
                                       self.game_object_group)
             self.dispose()
Пример #15
0
 def explode(self):
     FireballExplosion(
         self.world,
         self.cl,
         self.res,
         b2_coords(self.body.GetWorldPoint(
             self.body.fixtures[0].shape.pos)) * PPM,
         self.game_object_group,
         damage_me=self.damage_me)
     if self.damage_me is True:
         self.callback()
     self.dispose()
Пример #16
0
    def __init__(self, world, cl, res: Resources, pos, images, vector, timeout,
                 game_object_group, *groups):
        super().__init__(world, cl, game_object_group, *groups)

        self.ignore_ray_casting = True
        self.draw_shadow = False

        self.set_init_image(random.choice(images))
        self.rect.center = pos

        shape = b2CircleShape()
        shape.radius = self.image.get_size()[0] / 2 / PPM
        fd = B2Factory.create_fixture(shape, 0.1, 0.1, 0.5)
        self.body = B2Factory.create_body(world, b2_dynamicBody, fd,
                                          b2_coords(pos) / PPM)
        self.body.userData = self
        self.body.linearDamping = 1
        self.body.fixedRotation = True
        self.body.ApplyLinearImpulse(
            b2_coords(vector) / PPM, self.body.GetWorldPoint((0, 0)), True)

        self.timer = 0
        self.timeout = timeout
Пример #17
0
    def apply_impulses(world,
                       pos,
                       power,
                       radius,
                       count_rays,
                       obj_from,
                       damage_me=True):
        rays = []
        direction = pygame.Vector2(1, 0)
        rotate_angle = 360 / count_rays
        for i in range(count_rays):
            start_point = b2_coords(pos) / PPM
            end_point = b2_coords(direction * radius) / PPM + start_point
            ray = RayCastCallback(start_point, end_point)
            world.RayCast(ray, start_point, end_point)
            rays.append(ray)
            direction = direction.rotate(rotate_angle)

        exploded_objects = defaultdict(int)
        for i in rays:
            if not i.reports:
                continue
            last_report = i.reports[-1]
            impulse: b2Vec2 = i.end - last_report.point
            impulse.Normalize()
            impulse = impulse * power / count_rays * max(
                last_report.fraction + 0.5, 1)
            body: b2Body = last_report.fixture.body
            if damage_me is not True and isinstance(body.userData, damage_me):
                continue
            body.ApplyLinearImpulse(impulse, body.GetWorldPoint((0, 0)), True)
            if isinstance(body.userData, GameObject):
                exploded_objects[body.userData] += impulse.length
        for obj, power in exploded_objects.items():
            obj: GameObject
            obj.on_explosion(obj_from, power)
Пример #18
0
    def set_rotated_sprite(self, body: b2Body, image):
        """Rotates sprite image and shadow from b2Body"""

        # Base image
        angle = math.degrees(body.angle)
        self.rect.center = b2_coords(body.position) * PPM
        new_rect, rotated_im = self.rotate_image_center(
            self.rect, angle, image)
        self.image = rotated_im
        self.rect = new_rect

        # Shadow image
        if self.draw_shadow:
            self.shadow_rect, rotated_im = self.rotate_image_center(
                self.rect, angle, self.init_shadow)
            self.shadow = rotated_im
Пример #19
0
    def __init__(self, world: b2World, cl: ContactListener, res: Resources,
                 center, game_object_group: Group, *groups):
        super().__init__(world, cl, game_object_group, *groups)

        self.set_init_image(res.image_bank)
        self.rect.center = center

        render = res.font64.render('$  Банк  $', True, (0, 0, 0))
        self.image.blit(
            render, ((self.image.get_width() - render.get_width()) / 2, 230))

        shape = b2PolygonShape()
        shape.SetAsBox(*b2Vec2(self.rect.size) / 2 / PPM)
        fd = B2Factory.create_fixture(shape)
        self.body = B2Factory.create_body(self.world, b2_staticBody, fd,
                                          b2_coords(center) / PPM)
        self.body.userData = self
        self.set_rotated_sprite(self.body, self.image)
        LootArea(self.world, self.cl, center, self.game_object_group)
Пример #20
0
    def __init__(self, world: b2World, cl: ContactListener, center,
                 game_object_group: Group, *groups):
        super().__init__(world, cl, game_object_group, *groups)
        radius = 400
        image = pygame.Surface((radius * 2, radius * 2)).convert_alpha()
        image.fill((0, 0, 0, 0))
        pygame.draw.circle(image, (100, 100, 100, 30), (radius, radius),
                           radius)
        self.set_init_image(image)
        self.rect.center = center

        self.ignore_ray_casting = True
        self.draw_shadow = False
        shape = b2CircleShape()
        shape.radius = radius / PPM
        fd = B2Factory.create_fixture(shape, is_sensor=True)
        self.body = B2Factory.create_body(self.world, b2_staticBody, fd,
                                          b2_coords(center) / PPM)
        self.body.userData = self
Пример #21
0
    def __init__(self, world, cl, res: Resources,
                 pos, game_object_group, *groups):
        super().__init__(world, cl, game_object_group, *groups)

        self.ignore_ray_casting = True
        self.set_init_image(res.energy_item)
        self.rect.center = pos

        shape = b2CircleShape()
        shape.radius = self.image.get_width() / 2 / PPM
        fd1 = B2Factory.create_fixture(shape, 0.2, 0.2, 0.2, True)

        self.body = B2Factory.create_body(world, b2_dynamicBody, fd1, b2_coords(pos) / PPM)
        self.body.userData = self
        self.body.fixedRotation = True

        self.timer = 0
        self.timeout = 0.5
        self.is_collecting = False
Пример #22
0
    def __init__(self, world: b2World, cl: ContactListener, res: Resources, start, end,
                 game_object_group: Group, *groups):
        super().__init__(world, cl, game_object_group, *groups)

        self.ignore_ray_casting = True
        self.draw_shadow = False
        width = 24
        point1, point2 = sorted([start, end], key=lambda x: x[1])
        size = (width, pygame.Vector2(point1).distance_to(point2))
        sin = (point2[0] - point1[0]) / size[1]
        angle = math.asin(sin)
        size = tuple(map(int, size))
        center = (pygame.Vector2(point1) + pygame.Vector2(point2)) / 2

        shape = b2PolygonShape()
        shape.SetAsBox(*b2Vec2(size) / 2 / PPM, (0, 0), angle)
        fd = B2Factory.create_fixture(shape, is_sensor=True)
        self.body = B2Factory.create_body(self.world, b2_staticBody, fd, b2_coords(center) / PPM)
        self.body.userData = self

        self.collided = False
Пример #23
0
    def __init__(self, world, cl, res: Resources, rect: pygame.Rect,
                 friction_modifier, game_object_group, *groups):
        super().__init__(world, cl, game_object_group, *groups)

        self.friction_modifier = friction_modifier
        self.ignore_ray_casting = True
        self.draw_shadow = False

        rect = pygame.Rect(rect)
        image = pygame.transform.scale(res.image_ground, rect.size)
        self.set_init_image(image)
        self.rect = pygame.Rect(rect.topleft, image.get_size())

        shape = b2PolygonShape()
        shape.SetAsBox(*b2Vec2(*rect.size) / 2 / PPM)
        fd1 = B2Factory.create_fixture(shape, 0, is_sensor=True)

        self.body = B2Factory.create_body(world, b2_staticBody, fd1,
                                          b2_coords(rect.center) / PPM)
        self.body.userData = self

        self.set_rotated_sprite(self.body, self.get_init_image())
Пример #24
0
    def __init__(self, world, cl, res: Resources, car, explosion_callback,
                 game_object_group, *groups):
        super().__init__(world, cl, game_object_group, *groups, connects=False)

        self.ignore_ray_casting = True
        radius = 26
        pos = car.get_position() + car.get_vector() * -50
        self.res = res
        image = res.image_bomb
        self.set_init_image(image)
        self.rect.center = pos
        self.explosion_callback = explosion_callback

        shape = b2CircleShape()
        shape.radius = radius / PPM
        fd = B2Factory.create_fixture(shape, 0.3, 0.1, 0.5)
        self.body = B2Factory.create_body(world, b2_dynamicBody, fd,
                                          b2_coords(pos) / PPM)
        self.body.userData = self
        self.body.linearDamping = 3
        impulse = 90
        self.body.ApplyTorque(random.randint(-impulse, impulse), True)
        self.timer = 0
Пример #25
0
    def __init__(self, world, cl, res: Resources, center, radius, angle, speed,
                 game_object_group, *groups):
        super().__init__(world, cl, res.image_revolving_wall, 28, 10, 0.1, 0.5,
                         b2_dynamicBody, (center[0] - radius, center[1]),
                         (center[0] + radius, center[1]), game_object_group,
                         *groups)

        self.torque = speed
        self.body.angle = math.radians(angle)
        self.body.linearDamping = 1
        self.body.angularDamping = 1

        shape = b2PolygonShape()
        shape.SetAsBox(*b2Vec2(24, 24) / 4 / PPM)
        fd = B2Factory.create_fixture(shape)
        self.center_body = B2Factory.create_body(world, b2_staticBody, fd,
                                                 b2_coords(center) / PPM)
        jd = b2RevoluteJointDef()
        jd.bodyA = self.body
        jd.bodyB = self.center_body
        self.world.CreateJoint(jd)

        self.create_image()
Пример #26
0
 def get_rays(self):
     pos = self.player_car.get_position()
     rays = []
     direction = pygame.Vector2(1, 0)
     rotate_angle = 360 / self.count_rays
     for i in range(self.count_rays):
         start_point = b2_coords(pos) / PPM
         end_point = b2_coords(
             direction * self.ray_cast_radius) / PPM + start_point
         ray = RayCastCallback(start_point, end_point)
         self.world.RayCast(ray, start_point, end_point)
         rays.append(ray)
         direction = direction.rotate(rotate_angle)
     k = 0
     for i in rays:
         if not i.reports:
             self.rays[k] = b2_coords(i.start) * PPM, b2_coords(i.end) * PPM
         else:
             last_report: RayFixtureReport = i.reports[-1]
             self.rays[k] = b2_coords(i.start) * PPM, b2_coords(
                 last_report.point) * PPM
         k += 1
Пример #27
0
    def __init__(self, world, cl, res, skin: CarSkin, pos, angle,
                 game_object_group, *groups):
        super().__init__(world, cl, game_object_group, *groups)

        self.res = res
        self.set_init_image(skin.image_car)
        self.rect = pygame.Rect(pos, self.size)

        self.control_state = 0
        self.color_particles = 50, 50, 50

        # Default characteristics
        # Power characteristics
        self.max_forward_speed = 30
        self.max_backward_speed = -12
        self.max_drive_force = 30
        # Control characteristics
        self.max_lateral_impulse = 0.5
        self.angular_friction_impulse = 0.2
        self.linear_friction_impulse = 0.3

        self.lock_angle = math.radians(35)
        self.speed_tire_rotate = math.radians(180)

        # Body characteristics
        self.density = 1
        self.restitution = 0.02
        self.friction = 0.2

        self.tire_density = 3
        self.tire_restitution = 0.1
        self.tire_friction = 1

        s = b2Vec2(self.rect.size) / 2 / PPM
        box_vert = [(-s[0], -s[1]), (-s[0] / 2, s[1]), (s[0] / 2, s[1]),
                    (s[0], -s[1])]

        shape = b2PolygonShape()
        shape.vertices = box_vert
        fd = B2Factory.create_fixture(shape, self.density, self.restitution,
                                      self.friction)
        self.body = B2Factory.create_body(world, b2_dynamicBody, fd,
                                          b2_coords(pos) / PPM)
        self.body.userData = self
        self.body.angle = math.radians(angle)
        self.body.angularDamping = 0.3

        # Add tires
        def _create_tire(delta, jd):
            tire = Tire(world, self.cl, skin.image_tire, self,
                        self.max_forward_speed, self.max_backward_speed,
                        self.max_drive_force, self.max_lateral_impulse,
                        self.angular_friction_impulse,
                        self.linear_friction_impulse, self.tire_density,
                        self.tire_restitution, self.tire_friction,
                        self.game_object_group)
            tire.body.position = self.body.GetWorldPoint(delta)
            tire.body.angle = self.body.angle
            jd.bodyB = tire.body
            jd.localAnchorA = delta
            return tire, jd

        jd = b2RevoluteJointDef()
        jd.bodyA = self.body
        jd.enableLimit = True
        jd.lowerAngle = 0
        jd.upperAngle = 0
        jd.localAnchorA.SetZero()
        shift = b2Vec2(self.tire_shift) / PPM

        # ForwardLeft, ForwardRight, BackwardLeft, BackwardRight
        self.tires = []
        self.joints = []

        for i in [(-shift.x, shift.y), (shift.x, shift.y),
                  (-shift.x, -shift.y), (shift.x, -shift.y)]:
            tire, jd = _create_tire(b2Vec2(i), jd)
            self.tires.append(tire)
            self.joints.append(world.CreateJoint(jd))

        self.is_broken = False
        self.broken_timer = 0
        self.dispose_timeout = 5
Пример #28
0
 def set_position(self, position):
     self.body.position = b2_coords(position) / PPM
     for i in self.tires:
         i.body.position = b2_coords(position) / PPM
Пример #29
0
 def get_velocity(self):
     return b2_coords(self.body.linearVelocity) * PPM
Пример #30
0
 def get_position(self):
     return b2_coords(self.body.position) * PPM