Ejemplo n.º 1
0
    def hide(self, hunter):

        DistToClosest = float('inf')
        BestHidingSpot = Vector2D()

        to_target = hunter.pos - self.pos
        panic_range = 60
        dist = to_target.length()
        if dist < panic_range:
            self.visible = False

        for obst in self.world.obstacle:
            hidingSpot = self.GetHidingPosition(hunter.pos, obst)
            hidingDist = Vector2D.distance_sq(
                hidingSpot, self.pos
            )  #change to self.pos for closest obst search, and change vector to positive
            egi.cross(hidingSpot, 4)
            if hidingDist < DistToClosest:
                DistToClosest = hidingDist
                BestHidingSpot = hidingSpot

        if BestHidingSpot:
            egi.line_by_pos(hunter.pos, BestHidingSpot)
            return self.arrive(BestHidingSpot, 'fast')
        return self.flee(hunter.pos)
Ejemplo n.º 2
0
 def find_neighbours(self, bots, radius):
     for bot in bots:
         bot.tagged = False
         # get distance between self.pos and bot.pos
         dis = Vector2D.distance_sq(self.pos, bot.pos)
         if dis < (radius + bot.bRadius)**2:
             bot.tagged = True
Ejemplo n.º 3
0
    def hide(self,hunter,objs, delta):
        DistToClosest = 1000000
        
        self.BestHidingSpot = None
        hun = hunter
        # check for possible hiding spots
        for obj in objs:
            HidingSpot = self.getHidingPosition(hun,obj)
            HidingDist = Vector2D.distance_sq(HidingSpot,self.pos)
            # render the hiding spots immediatly
            egi.aqua_pen()
            egi.cross(HidingSpot, 5)

            if HidingDist < DistToClosest and (Vector2D.length(hun.pos - obj.pos) - hun.radius) > 0:
                DistToClosest = HidingDist
                self.BestHidingSpot = HidingSpot
        # if we have a best hiding spot, use it

        if self.BestHidingSpot is not None:
            return self.arrive(self.BestHidingSpot, 'fast') # speed = fast?
        # default - run away!
        return self.runAway(hunter, delta) 
Ejemplo n.º 4
0
 def get_neighbours(self, bots, radius):
     for bot in bots:
         bot.tagged = False
         dist = Vector2D.distance_sq(self.pos, bot.pos)
         if dist < (radius + bot.bRadius) ** 2:
             bot.tagged = True