示例#1
0
    def update(self, timer, world, events):
        self.functionality(events, world)
        way_point = Vector(self.aim) - Vector(self.rect.center)
        bearing = way_point.normalize()
        self.image = pygame.transform.rotate(self.image_master,
                                             way_point.angle_to(Vector(1, 0)))
        self.rect = Rectangle.get_rect(self.image, self.rect.center)
        if not self.should_retract:
            self.hook_image = pygame.transform.rotate(
                self.hook_image_master, way_point.angle_to(Vector(1, 0)))
            self.hook_rect = Rectangle.get_rect(self.hook_image,
                                                self.hook_rect.center)
            self.hitmask = get_hitmask(self.hook_rect, self.hook_image, 0)

        self.x = self.rect.x
        self.y = self.rect.y

        if self.shooter:
            self.shoot(timer)
            self.should_retract = True
            self.should_aim = False

        elif not self.should_retract:
            self.hook_rect = Rectangle.get_rect(
                self.hook_image,
                (self.rect.center[0] + bearing.x * self.displacement,
                 self.rect.center[1] + bearing.y * self.displacement))
        if self.should_retract and not self.shooter:
            self.retract(timer)
        if self.should_release:
            self.release(timer)
示例#2
0
    def __init__(self, x, y, length):
        """ x and y should be the coordinates of the pivot """
        self.rope_height = length
        self.x, self.y = x, y
        self.rope_width = SAW_ROPE_WIDTH

        self.saw_image_master = image.load(
            "../ArtWork/Environment/{0}".format(SAW_IMAGE)).convert_alpha()
        self.saw_image_master = transform.scale(self.saw_image_master,
                                                SAW_DIMENSION)
        self.image = self.saw_image_master

        self.center_old = Vector(x, y + self.rope_height + 15)
        self.rect = Rectangle.get_rect(self.image, self.center_old)
        self.collision_circle = Circle(25, self.center_old)

        self.step = ROTATION_STEP
        self.rotation = 0
        self.time = 0
        self.last_time = 0
        self.current_time = 0
        self.direction = Vector((0, 0))
        self.velocity = Vector((0, 0))
        self.bob = Pendulum(SAW_ROPE_ANGLE, self.rope_height, (self.x, self.y))
        self.is_severed = False
示例#3
0
    def swing(self):
        self.current_time = pygame.time.get_ticks()
        if self.current_time - self.last_time >= 17:
            self.bob.recompute_angle()
            self.step = self.bob.d_theta
            self.rope = self.rope.rotate(self.step)
            self.rect = Rectangle.get_rect(self.image, self.bob.rect.center)
            self.x = self.rect.x
            self.y = self.rect.y

            self.last_time = self.current_time
示例#4
0
    def __init__(self, x, y):
        self.image_master = \
            pygame.image.load("../ArtWork/Environment/graple.png")\
            .convert_alpha()
        self.image_master = pygame.transform.scale(self.image_master, (80, 40))
        self.image = self.image_master

        self.hook_image_master = \
            pygame.image.load("../ArtWork/Environment/hook2.png")\
            .convert_alpha()
        self.hook_image_master = pygame.transform.scale(
            self.hook_image_master, (40, 40))
        self.hook_image = self.hook_image_master

        self.displacement = (self.hook_image_master.get_width() +
                             self.image_master.get_width()) // 2
        self.hook_rect = Rectangle.get_rect(self.hook_image, (x, y))
        self.rect = Rectangle.get_rect(self.image, (x, y))

        self.hooker = Vector((self.hook_rect.x, self.hook_rect.y))
        self.hitmask = get_hitmask(self.hook_rect, self.hook_image, 0)
        self.aim = (x, y + 20)
        self.should_aim = True
        self.should_retract = False
        self.limit = Vector(1, 0)
        self.angle = 0
        self.rotation = 0
        self.step = 0
        self.should_release = False
        self.time = 0
        self.distance_limit = 150
        self.x = self.rect.x
        self.y = self.rect.y
        self.current_time = 0
        self.last_time = 0
        self.shooter = False
        self.calculate_pivot = True
示例#5
0
 def rotate_saw(self, time):
     self.image = transform.rotate(self.saw_image_master, self.rotation)
     self.rect = Rectangle.get_rect(self.image, self.center_old)
     self.rotation += 300 * time / 1000
     if self.rotation > 360:
         self.rotation = self.step