示例#1
0
def _bounce_one(a1, a2):
    # Bounces a1
    dir_angle = vectors.angle(a2.pos, a1.pos)

    vel_angle = vectors.angle(a1.velocity)

    # If they are head on then we want to swivel them a little
    if vectors.bound_angle(dir_angle[0] + 180) == vel_angle[0]:
        dir_angle[0] = vectors.bound_angle(dir_angle[0] + 40)

    # Keep trying distances further and further apart until they're
    # not going to be overlapping any more
    overlapping = True
    dist = vectors.total_velocity(a1.velocity)

    a2_rect = (a2.pos[0], a2.pos[1], a2.size[0], a2.size[1])

    while overlapping:
        new_pos = vectors.add_vectors(a1.pos,
                                      vectors.move_to_vector(dir_angle, dist))

        new_rect = (new_pos[0], new_pos[1], a1.size[0], a1.size[1])

        if not geometry.rect_collision(new_rect, a2_rect, True):
            overlapping = False

        dist += 1

    # Add a bit to be safe
    new_pos = vectors.add_vectors(
        a1.pos,
        vectors.move_to_vector(dir_angle,
                               dist + vectors.total_velocity(a1.velocity)))

    a1.pos = new_pos
示例#2
0
def _bounce_one(a1, a2):
    # Bounces a1
    dir_angle = vectors.angle(a2.pos, a1.pos)
    
    vel_angle = vectors.angle(a1.velocity)
    
    # If they are head on then we want to swivel them a little
    if vectors.bound_angle(dir_angle[0]+180) == vel_angle[0]:
        dir_angle[0] = vectors.bound_angle(dir_angle[0] + 40)
    
    # Keep trying distances further and further apart until they're
    # not going to be overlapping any more
    overlapping = True
    dist = vectors.total_velocity(a1.velocity)
    
    a2_rect = (a2.pos[0], a2.pos[1], a2.size[0], a2.size[1])
    
    while overlapping:
        new_pos = vectors.add_vectors(a1.pos, vectors.move_to_vector(
            dir_angle, dist
        ))
        
        new_rect = (new_pos[0], new_pos[1], a1.size[0], a1.size[1])
        
        if not geometry.rect_collision(new_rect, a2_rect, True):
            overlapping = False
        
        dist += 1
    
    # Add a bit to be safe
    new_pos = vectors.add_vectors(a1.pos, vectors.move_to_vector(
        dir_angle, dist + vectors.total_velocity(a1.velocity)
    ))
    
    a1.pos = new_pos
示例#3
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
示例#4
0
 def generate_bullet(self, target):
     # Set correct origin
     offset_angle = vectors.bound_angle(
         vectors.add_vectors(self._effect_offset_angle, self.facing)
     )
     
     origin_pos = vectors.add_vectors(self.get_offset_pos(use_effect_offset=True), self.actor.pos)
     
     # Get actual velocity we'll be using
     if type(target) == list or type(target) == tuple:
         direction = vectors.angle(origin_pos, target)
         target_pos = target
     else:
         direction = vectors.angle(origin_pos, target.pos)
         target_pos = target.pos
     
     velocity = vectors.move_to_vector(direction, self.bullet['velocity'])
     velocity[2] = math_lib.calc_trajectory(0.1, vectors.distance(origin_pos, target_pos), self.bullet['velocity'])
     
     the_bullet = bullets.Shell(
         pos=origin_pos,
         velocity=velocity,
         image = self.bullet['image'],
         size = self.bullet['size'],
         blast_radius = self.bullet['blast_radius'],
         damage = self.bullet['damage'],
         dissipation_func = self.bullet.get('dissipation_func', "linear"),
     )
     self.actor.bullets.append(the_bullet)
示例#5
0
def _bounce_both(a1, a2):
    # These are the angles directly away from each other
    angle1 = vectors.angle(a2.pos, a1.pos)
    angle2 = vectors.angle(a1.pos, a2.pos)

    vel_angle1 = vectors.angle(a1.velocity)
    vel_angle2 = vectors.angle(a2.velocity)

    # If they are head on then we want to swivel them a little
    if vel_angle1[0] == angle2[0] and vel_angle2[0] == angle1[0]:
        angle1[0] = vectors.bound_angle(angle1[0] + 20)
        angle2[0] = vectors.bound_angle(angle2[0] + 20)

    # Keep trying distances further and further apart until they're
    # not going to be overlapping any more
    overlapping = True
    dist_multiplier = 0.1

    while overlapping:
        dist_multiplier += 0.1

        new_pos1 = vectors.add_vectors(
            a1.pos,
            vectors.move_to_vector(angle1,
                                   max(a1.size) * dist_multiplier))

        new_pos2 = vectors.add_vectors(
            a2.pos,
            vectors.move_to_vector(angle2,
                                   max(a2.size) * dist_multiplier))

        new_rect1 = (new_pos1[0], new_pos1[1], a1.size[0], a1.size[1])
        new_rect2 = (new_pos2[0], new_pos2[1], a2.size[0], a2.size[1])

        if not geometry.rect_collision(new_rect1, new_rect2):
            overlapping = False

    a1.pos = new_pos1
    a2.pos = new_pos2
示例#6
0
def _bounce_both(a1, a2):
    # These are the angles directly away from each other
    angle1 = vectors.angle(a2.pos, a1.pos)
    angle2 = vectors.angle(a1.pos, a2.pos)
    
    vel_angle1 = vectors.angle(a1.velocity)
    vel_angle2 = vectors.angle(a2.velocity)
    
    # If they are head on then we want to swivel them a little
    if vel_angle1[0] == angle2[0] and vel_angle2[0] == angle1[0]:
        angle1[0] = vectors.bound_angle(angle1[0] + 20)
        angle2[0] = vectors.bound_angle(angle2[0] + 20)
    
    # Keep trying distances further and further apart until they're
    # not going to be overlapping any more
    overlapping = True
    dist_multiplier = 0.1
    
    while overlapping:
        dist_multiplier += 0.1
        
        new_pos1 = vectors.add_vectors(a1.pos, vectors.move_to_vector(
            angle1, max(a1.size) * dist_multiplier
        ))
        
        new_pos2 = vectors.add_vectors(a2.pos, vectors.move_to_vector(
            angle2, max(a2.size) * dist_multiplier
        ))
        
        new_rect1 = (new_pos1[0], new_pos1[1], a1.size[0], a1.size[1])
        new_rect2 = (new_pos2[0], new_pos2[1], a2.size[0], a2.size[1])
        
        if not geometry.rect_collision(new_rect1, new_rect2):
            overlapping = False
    
    a1.pos = new_pos1
    a2.pos = new_pos2
示例#7
0
 def generate_effect(self, target):
     offset_angle = vectors.bound_angle(
         vectors.add_vectors(self._effect_offset_angle, self.facing)
     )
     
     origin_pos = vectors.add_vectors(self.get_offset_pos(use_effect_offset=True), self.actor.pos)
     
     the_effect = effects.Beam(
         origin=origin_pos,
         target=target.pos,
         colour=self.effect['colour'],
         duration=self.effect['duration'],
         degrade=self.effect.get("degrade", (0,0,0)),
     )
     self.actor.effects.append(the_effect)
示例#8
0
 def test_bound_angle(self):
     vals = (
         # 2D
         (360, 0),
         (0, 0),
         (-360, 0),
         (359, 359),
         (360 + 359, 359),
         
         # 3D
         ([50, 50], [50, 50]),
         ([360, 0], [0, 0]),
         ([-360, 360], [0, 0]),
     )
     
     for a, expected in vals:
         self.assertEqual(expected, vectors.bound_angle(a))
示例#9
0
    def _turn_ai(self, target):
        self.facing = vectors.bound_angle(self.facing)

        target_angle = self.pos.angle(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