示例#1
0
 def autoattack(self, dt):
     if self.hero.attacking:
         self.hero.attack_timer -= dt / 100.
         if self.hero.attack_timer <= 0:
             self.hero.attack_timer = self.hero.attack_time
             if self.hero.tgh.target:
                 if point_distance(self.hero.coords,
                                   self.hero.tgh.coords) < 14:
                     self.client.send('attack', self.hero.tgh.id)
示例#2
0
 def attack(self):
     # Attack target if in range, otherwise move toward it
     if point_distance(self.lifeform.coords,
                       self.target.coords) < (1.7 * TILE_SIZE):
         if self.attack_timer < 0:
             logging.info('attack: Target in range, attacking')
             self.lifeform.attack(self.target.id)
             self.state = None
             return
     else:
         if self.action_timer < 0:
             logging.info(
                 'attack: Target not in range, pathing towards target')
             self.action_timer = self.lifeform.move_time
             self.lifeform.move_to_lifeform(self.target.coords)
             return
示例#3
0
 def move_to_lifeform(self, coords):
     """ Move to given coordinates and stop right in front of them """
     start = self.coords[0] / TILE_SIZE, self.coords[1] / TILE_SIZE
     end = coords[0] / TILE_SIZE, coords[1] / TILE_SIZE
     updated_grid = self.goc.rooms[self.current_room].grid
     route = astar(updated_grid, start, end)
     if point_distance(self.coords, coords) > 12:
         try:
             new_x, new_y = route[1][0] * TILE_SIZE, route[1][1] * TILE_SIZE
             # print('newx/newy {0},{1}'.format(new_x, new_y))
             self.coords = [new_x, new_y]
             return route
         except IndexError:
             return None
     # Return None if we have arrived at our destination
     return None
示例#4
0
 def farthest_ally(self):
     try:
         return max({point_distance(self.coords, lifeform.coords): lifeform
                     for key, lifeform in self.nearby_allies.items()}.values())
     except ValueError:
         return {}
示例#5
0
 def nearest_enemy(self):
     try:
         return min({point_distance(self.coords, lifeform.coords): lifeform
                     for key, lifeform in self.nearby_enemies.items()}.values())
     except ValueError:
         return {}
示例#6
0
 def nearby_lifeforms(self):
     return {lf.id: lf for id, lf in self.goc.lifeforms.items()
             if point_distance(self.coords, lf.coords) < self.sight and lf != self}
示例#7
0
 def nearby_lifeforms(self):
     return {
         rs.id: rs
         for id, rs in self.game.rsc.remotesprites.items()
         if point_distance(self.coords, rs.coords) < TARGET_RANGE
     }