Esempio n. 1
0
    def turn(self, target_facing):
        """Turn's the ability towards a specific facing, returns True
        if the facing is achieved"""

        # This allows us to cut out all the below stuff if we have a
        # 360 degree fire-arc
        if self.fire_arc == [360, 360]:
            return True

        xy_diff, z_diff = vectors.angle_diff(self.facing, target_facing)

        # If it's within a certain range then BOOM, we're there
        if abs(xy_diff) <= self.turn_speed:
            if abs(z_diff) < self.turn_speed:
                self.facing = target_facing
                return True

        # XY first
        if xy_diff >= 0:
            self.facing[0] += self.turn_speed
        else:
            self.facing[0] -= self.turn_speed

        # Now for Z
        if z_diff >= 0:
            self.facing[1] += self.turn_speed
        else:
            self.facing[1] -= self.turn_speed

        self.facing = vectors.bound_angle(self.facing)
        return False
Esempio n. 2
0
 def turn(self, target_facing):
     """Turn's the ability towards a specific facing, returns True
     if the facing is achieved"""
     
     # This allows us to cut out all the below stuff if we have a
     # 360 degree fire-arc
     if self.fire_arc == [360, 360]:
         return True
     
     xy_diff, z_diff = vectors.angle_diff(self.facing, target_facing)
     
     # If it's within a certain range then BOOM, we're there
     if abs(xy_diff) <= self.turn_speed:
         if abs(z_diff) < self.turn_speed:
             self.facing = target_facing
             return True
     
     # XY first
     if xy_diff >= 0:
         self.facing[0] += self.turn_speed
     else:
         self.facing[0] -= self.turn_speed
     
     # Now for Z
     if z_diff >= 0:
         self.facing[1] += self.turn_speed
     else:
         self.facing[1] -= self.turn_speed
     
     self.facing = vectors.bound_angle(self.facing)
     return False
Esempio n. 3
0
    def check_aim(self, target_facing):
        """Checks to see if we are pointing in the right direction to use
        the ability"""

        # This allows us to cut out all the below stuff if we have a
        # 360 degree fire-arc
        if self.fire_arc == [360, 360]:
            return True

        xy_diff, z_diff = vectors.angle_diff(self.facing, target_facing)

        if abs(xy_diff) < self.turn_speed:
            if abs(z_diff) < self.turn_speed or self.ignore_z_facing:
                return True

        return False
Esempio n. 4
0
 def check_aim(self, target_facing):
     """Checks to see if we are pointing in the right direction to use
     the ability"""
     
     # This allows us to cut out all the below stuff if we have a
     # 360 degree fire-arc
     if self.fire_arc == [360, 360]:
         return True
     
     xy_diff, z_diff = vectors.angle_diff(self.facing, target_facing)
     
     if abs(xy_diff) < self.turn_speed:
         if abs(z_diff) < self.turn_speed or self.ignore_z_facing:
             return True
     
     return False
Esempio n. 5
0
    def test_angle_diff(self):
        vals = (
            (10, 100, 90),  # Right
            (100, 10, -90),  # Left

            # Cross the 360 mark
            (350, 10, 20),
            (10, 350, -20),

            # Now in 3D
            ([10, 20], [100, 0], [90, -20]),
            ([100, 0], [10, 30], [-90, 30]),
            ([350, 10], [10, 65], [20, 55]),
            ([10, 40], [350, 0], [-20, -40]),
        )

        for a1, a2, expected in vals:
            self.assertEqual(vectors.angle_diff(a1, a2), expected)
Esempio n. 6
0
 def test_angle_diff(self):
     vals = (
         (10, 100, 90),# Right
         (100, 10, -90),# Left
         
         # Cross the 360 mark
         (350, 10, 20),
         (10, 350, -20),
         
         # Now in 3D
         ([10, 20], [100, 0], [90, -20]),
         ([100, 0], [10, 30], [-90, 30]),
         ([350, 10], [10, 65], [20, 55]),
         ([10, 40], [350, 0], [-20, -40]),
     )
     
     for a1, a2, expected in vals:
         self.assertEqual(vectors.angle_diff(a1, a2), expected)
Esempio n. 7
0
    def _turn_ai(self, target):
        self.facing = vectors.bound_angle(self.facing)

        target_angle = vectors.angle(self.pos, target)
        diff = vectors.angle_diff(self.facing, target_angle)[0]

        if abs(diff) <= self.turn_speed:
            self.facing = target_angle
            return True

        if diff < 0:
            self.facing[0] -= self.turn_speed
            for a in self.abilities:
                a.facing[0] += self.turn_speed
        else:
            self.facing[0] += self.turn_speed
            for a in self.abilities:
                a.facing[0] -= self.turn_speed

        return False
Esempio n. 8
0
    def _turn_ai(self, target):
        self.facing = vectors.bound_angle(self.facing)

        target_angle = vectors.angle(self.pos, target)
        diff = vectors.angle_diff(self.facing, target_angle)[0]

        if abs(diff) <= self.turn_speed:
            self.facing = target_angle
            return True

        if diff < 0:
            self.facing[0] -= self.turn_speed
            for a in self.abilities:
                a.facing[0] += self.turn_speed
        else:
            self.facing[0] += self.turn_speed
            for a in self.abilities:
                a.facing[0] -= self.turn_speed

        return False