示例#1
0
    def update(self, deltat):
        self.processKeys()
        num = 0
        for wheel in self.wheels:
            rel_ground_vel = self.rigid_body.rel_point_vel(wheel.pos)
            vel_pair = []
            vel_pair.append(self.rigid_body.relative_to_world(wheel.pos))
            vel_pair.append(
                self.rigid_body.relative_to_world(wheel.pos) +
                self.rigid_body.rot_relative_to_world(rel_ground_vel))
            self.vel_line_pairs.append(vel_pair)

            rel_response_force = wheel.calculate_force(rel_ground_vel, deltat)
            response_force_offset = self.rigid_body.rot_relative_to_world(
                rel_response_force) + self.rigid_body.relative_to_world(
                    wheel.pos)
            force_pair = []
            force_pair.append(self.rigid_body.relative_to_world(wheel.pos))
            force_pair.append(
                (response_force_offset.x, response_force_offset.y))
            self.force_line_pairs.append(force_pair)
            self.rigid_body.add_rel_force(rel_response_force, wheel.pos)

        self.rigid_body.update(deltat)
        self.direction = self.rigid_body.angle
        self.delta_pos += self.rigid_body.pos - self.world_pos
        self.world_pos = self.rigid_body.pos

        self.image = pygame.transform.rotate(
            self.src_image,
            -1 * self.direction * 180 / math.pi)  # degrees counter-clockwise
        self.rect = self.image.get_rect()
        self.rect.center = self.screen_pos if self.STAY_CENTERED else self.rigid_body.pos
        self.aabb.center = self.rigid_body.pos
        self.bounding_box = BoundingBox(self.aabb, self.direction)
示例#2
0
class Sensor(Sprite):
    def __init__(self, res):
        sensor_image = res.image_dict['Sensor.png']
        center_image(sensor_image)
        super(Sensor, self).__init__(sensor_image, x = 0, y = 0)
        self.collision = BoundingBox(self)

    def collide(self, other):
        return self.collision.collide(other.collision)
示例#3
0
class Sensor(Sprite):
    def __init__(self, res):
        sensor_image = res.image_dict['Sensor.png']
        center_image(sensor_image)
        super(Sensor, self).__init__(sensor_image, x=0, y=0)
        self.collision = BoundingBox(self)

    def collide(self, other):
        return self.collision.collide(other.collision)
示例#4
0
 def collide(self):
     self.speed = 0
     self.position = self.old_position
     self.direction = self.old_direction
     self.image = pygame.transform.rotate(self.src_image, self.direction)
     self.rect = self.image.get_rect()
     self.rect.center = self.position
     self.aabb.center = self.position
     self.bounding_box = BoundingBox(self.aabb, -1 * self.direction)
示例#5
0
    def __init__(self, image, screen_pos, world_pos):
        pygame.sprite.Sprite.__init__(self)
        self.world_pos = world_pos
        self.screen_pos = screen_pos
        self.delta_pos = pygame.math.Vector2()
        self.src_image = pygame.image.load(image)
        # Correct for car being upside-down
        self.src_image = pygame.transform.rotate(self.src_image, 180)
        self.rect = self.src_image.get_rect()
        self.rect.center = screen_pos
        self.aabb = self.rect
        self.direction = 3 * math.pi / 2
        self.bounding_box = BoundingBox(self.aabb, self.direction)

        self.forward = self.reverse = self.left = self.right = False

        self.force_line_pairs = []
        self.vel_line_pairs = []

        # Our rigid body simulator
        half_size = pygame.math.Vector2(self.rect.width * 0.25,
                                        self.rect.height * 0.25)
        self.rigid_body = RigidBody(2 * half_size, self.MASS)

        wheel_pos = []
        wheel_pos.append(half_size)
        wheel_pos.append(pygame.math.Vector2(half_size.x * -1, half_size.y))
        wheel_pos.append(half_size * -1)
        wheel_pos.append(pygame.math.Vector2(half_size.x, half_size.y * -1))

        self.wheels = []
        self.wheels.append(Wheel(wheel_pos[0], 1))
        self.wheels.append(Wheel(wheel_pos[1], 1))
        self.wheels.append(Wheel(wheel_pos[2], 1))
        self.wheels.append(Wheel(wheel_pos[3], 1))

        self.rigid_body.set_position(self.world_pos, self.direction)
示例#6
0
 def __init__(self, res):
     sensor_image = res.image_dict['Sensor.png']
     center_image(sensor_image)
     super(Sensor, self).__init__(sensor_image, x = 0, y = 0)
     self.collision = BoundingBox(self)
示例#7
0
 def __init__(self, res):
     sensor_image = res.image_dict['Sensor.png']
     center_image(sensor_image)
     super(Sensor, self).__init__(sensor_image, x=0, y=0)
     self.collision = BoundingBox(self)