Exemplo n.º 1
0
    def _update_rotation(cls):
        '''
        Internal method.  
        Update rotation, inverse acc in the middle,
        stop rotation on target angle.
        '''
        if cls._target_angle == None:
            return
        
        ship = cls._api._ships['own']
        orien = get_deg(ship.orien)

        # check halfway through -> inv acc
        path_length = cls._path_f(orien)

        if not cls._inversed == False and path_length <= cls._path_length/2:
            # inverse acc
            ship.circular_acc = -ship.circular_acc
            cls._inversed = True

        # check target angle
        if abs(orien - cls._target_angle) <= 1:
            ship.orien = get_rad(cls._target_angle)

            # finish rotation
            ship.circular_acc = 0
            ship.circular_speed = 0
            cls._target_angle = None
Exemplo n.º 2
0
    def rotate_target(cls, angle: int):
        '''
        Rotate the ship to a target angle.
        The ship will rotate all the way until reaching the target angle.  
        For example, if the orientation of the ship is 277° and the target
        angle 233°, the ship will rotate of 44° counter-clockwise.

        Parameters
        ---
        `angle`: int  
        The target angle in degrees.
        '''

        if cls._target_angle == angle:
            # given angle is already target angle
            return
        
        cls._target_angle = angle
        cls._inversed = False

        # select the smallest path to the angle
        orien = get_deg(cls._api._ships['own'].orien)
        
        acc_circular = cls._choose_rotation_path(orien)
        
        cls._api._ships['own'].circular_acc = acc_circular
Exemplo n.º 3
0
    def __init__(self, team, pos, orien, speed=None, damage=None, _id=None):

        super().__init__(Spec.DIM_BULLET, pos, surface=img_bullet, center=True)

        self.team = team

        # each bullet has a (~)unique id
        if _id == None:
            self.id = np.random.randint(0, 1000)
        else:
            self.id = _id

        # rotate the bullet according to its orientation
        self.rotate(get_deg(orien))

        self.orien = orien
        self.mask = self.get_mask()

        if speed == None:
            self.speed = Spec.SPEED_BULLET
        else:
            self.speed = speed

        if damage == None:
            self.damage = Spec.DAMAGE_BULLET
        else:
            self.damage = damage
Exemplo n.º 4
0
    def rotate_surf(self, angle: float):
        '''
        Rotate the ship's surface to a given angle (rad).  
        '''
        # converts the angle into deg
        angle = -get_deg(angle)

        self.form.rotate(angle)
Exemplo n.º 5
0
 def get_orientation(cls):
     '''
     Return the orientation of the ship (degree).  
     The orientation is an angle, with:
     0° : East  
     90° : South  
     180° : West  
     270° : North
     '''
     return get_deg(cls._api._ship['opp'].orien)
Exemplo n.º 6
0
    def rotate_angle(cls, angle: int):
        '''
        Rotate the ship of a given angle.  
        The ship will rotate of the given angle, so if the orientation
        of the ship is 130° and the given angle -21°, the ship will rotate
        of 21° counter-clockwise to reach 119°.

        Parameters
        ---
        `angle`: int  
        The angle of rotation in degrees, positive is clockwise,
        negative is counter-clockwise.
        '''
        orien = get_deg(cls._api._ships['own'].orien)

        target_angle = (orien + angle) % 360

        if cls._target_angle == target_angle:
            # given angle is already target angle
            return
        
        cls.rotate_target(target_angle)