Exemple #1
0
 def collision_at(self, pos):
     """Return True if collision at given position, and False otherwise."""
     rad = constants.TANKRADIUS
     for obs in self.team.map.obstacles:
         if collisiontest.circle_to_poly(((pos),rad), obs.shape):
             return True
     for tank in self.team.map.tanks():
         if tank is self:
             continue
         if collisiontest.circle_to_circle((tank.pos, rad), (pos, rad)):
             self.collide_tank(tank)
             return True
     at_left_wall = pos[0]-rad < -self.config.world.size[0]/2
     at_bottem_wall = pos[1]-rad < -self.config.world.size[1]/2
     at_right_wall = pos[0]+rad > self.config.world.size[0]/2
     at_top_wall = pos[1]+rad > self.config.world.size[1]/2
     if at_left_wall or at_bottem_wall or at_right_wall or at_top_wall:
         return True
     return False
Exemple #2
0
 def collision_at(self, pos):
     """Return True if collision at given position, and False otherwise."""
     rad = constants.TANKRADIUS
     for obs in self.team.map.obstacles:
         if collisiontest.circle_to_poly(((pos), rad), obs.shape):
             return True
     for tank in self.team.map.tanks():
         if tank is self:
             continue
         if collisiontest.circle_to_circle((tank.pos, rad), (pos, rad)):
             self.collide_tank(tank)
             return True
     at_left_wall = pos[0] - rad < -self.config.world.size[0] / 2
     at_bottem_wall = pos[1] - rad < -self.config.world.size[1] / 2
     at_right_wall = pos[0] + rad > self.config.world.size[0] / 2
     at_top_wall = pos[1] + rad > self.config.world.size[1] / 2
     if at_left_wall or at_bottem_wall or at_right_wall or at_top_wall:
         return True
     return False
Exemple #3
0
 def check_position(self, pos, rad):
     """Check a position to see if it is safe to spawn a tank there."""
     for o in self._obstacles:
         if collisiontest.circle_to_poly((pos,rad), o.shape):
             return False
     for s in self.map.shots():
         shot = (s.pos, constants.SHOTRADIUS)
         if collisiontest.circle_to_circle((pos,rad), shot):
             return False
     for t in self.map.tanks():
         tank = (t.pos, constants.TANKRADIUS)
         if collisiontest.circle_to_circle((pos,rad), tank):
             return False
     off_map_left = pos[0]-rad < -self.config.world.size[0]/2
     off_map_bottom = pos[1]-rad < -self.config.world.size[1]/2
     off_map_right = pos[0]+rad > self.config.world.size[0]/2
     off_map_top = pos[1]+rad > self.config.world.size[1]/2
     if off_map_left or off_map_bottom or off_map_right or off_map_top:
         return False
     return True
Exemple #4
0
 def check_position(self, pos, rad):
     """Check a position to see if it is safe to spawn a tank there."""
     for o in self._obstacles:
         if collisiontest.circle_to_poly((pos, rad), o.shape):
             return False
     for s in self.map.shots():
         shot = (s.pos, constants.SHOTRADIUS)
         if collisiontest.circle_to_circle((pos, rad), shot):
             return False
     for t in self.map.tanks():
         tank = (t.pos, constants.TANKRADIUS)
         if collisiontest.circle_to_circle((pos, rad), tank):
             return False
     off_map_left = pos[0] - rad < -self.config.world.size[0] / 2
     off_map_bottom = pos[1] - rad < -self.config.world.size[1] / 2
     off_map_right = pos[0] + rad > self.config.world.size[0] / 2
     off_map_top = pos[1] + rad > self.config.world.size[1] / 2
     if off_map_left or off_map_bottom or off_map_right or off_map_top:
         return False
     return True
Exemple #5
0
 def check_collisions(self):
     """Check for collisions."""
     s_rad = constants.SHOTRADIUS
     t_rad = constants.TANKRADIUS
     for obs in self.team.map.obstacles:
         if collisiontest.circle_to_poly(((self.pos),s_rad), obs.shape):
             return self.kill()
     for tank in self.team.map.tanks():
         if self in tank.shots:
             continue
         if collisiontest.circle_to_circle((tank.pos, t_rad),
                                           (self.pos, s_rad)):
             if tank.team == self.team and not self.config['friendly_fire']:
                 continue
             tank.kill()
             return self.kill()
     at_left_wall = self.pos[0]-s_rad < -self.config.world.size[0]/2
     at_bottem_wall = self.pos[1]-s_rad < -self.config.world.size[1]/2
     at_right_wall = self.pos[0]+s_rad > self.config.world.size[0]/2
     at_top_wall = self.pos[1]+s_rad > self.config.world.size[1]/2
     if at_left_wall or at_bottem_wall or at_right_wall or at_top_wall:
         return self.kill()
Exemple #6
0
 def check_collisions(self):
     """Check for collisions."""
     s_rad = constants.SHOTRADIUS
     t_rad = constants.TANKRADIUS
     for obs in self.team.map.obstacles:
         if collisiontest.circle_to_poly(((self.pos), s_rad), obs.shape):
             return self.kill()
     for tank in self.team.map.tanks():
         if self in tank.shots:
             continue
         if collisiontest.circle_to_circle((tank.pos, t_rad),
                                           (self.pos, s_rad)):
             if tank.team == self.team and not self.config['friendly_fire']:
                 continue
             tank.kill()
             return self.kill()
     at_left_wall = self.pos[0] - s_rad < -self.config.world.size[0] / 2
     at_bottem_wall = self.pos[1] - s_rad < -self.config.world.size[1] / 2
     at_right_wall = self.pos[0] + s_rad > self.config.world.size[0] / 2
     at_top_wall = self.pos[1] + s_rad > self.config.world.size[1] / 2
     if at_left_wall or at_bottem_wall or at_right_wall or at_top_wall:
         return self.kill()