Example #1
0
class SimpleAI:
    
    def __init__(self):
        """SimpleAI class.
        Need following attribs:
            image, x_vel, rect, direction,...
        Need following methods:
            move
        """
        pass
    
    def check_player_sight(self, player, mainS, myCam):
        """Check if player is in line of sight."""

        p11 = myCam.use_cam_point(self.rect.topleft)[0]
        p22 = myCam.use_cam_point(player.rect.topleft)[0]

        pos_diff2 = p11 - p22
        
        self.los = LOS(self.rect.center, self.direction)
        cond2 = self.los.check_LOS_collision(player, mainS, myCam)
        
        if pos_diff2 < 0 and self.direction == RIGHT and cond2:
            return True

        elif pos_diff2 > 0 and self.direction == LEFT and cond2:
            return True

        return False
   
    def check_player_distance(self, player):
        """Check if player is near enough for AI to kick in."""


        p1 = self.rect.x
        p2 = player.rect.x
        
        pos_diff = p1 - p2
        
        if abs(pos_diff) < AI_THRESHOLD_DIFF:
            return True 
        return False
    

    def check_ai_conditions(self, player, mainS, cam):
        
        # ORDER IS IMPORTANT DUE TO SHORT CIRCUITING
        # ORDER IS NECESSARY FOR los OBJECT TO BE CREATED
        if self.check_player_sight(player, mainS, cam) \
           and self.check_player_distance(player):
            
            return True
        
        return False
Example #2
0
    def check_player_sight(self, player, mainS, myCam):
        """Check if player is in line of sight."""

        p11 = myCam.use_cam_point(self.rect.topleft)[0]
        p22 = myCam.use_cam_point(player.rect.topleft)[0]

        pos_diff2 = p11 - p22
        
        self.los = LOS(self.rect.center, self.direction)
        cond2 = self.los.check_LOS_collision(player, mainS, myCam)
        
        if pos_diff2 < 0 and self.direction == RIGHT and cond2:
            return True

        elif pos_diff2 > 0 and self.direction == LEFT and cond2:
            return True

        return False