Esempio n. 1
0
  def resolve_tanks(self):
    for tank in self.level.all_tanks():
      if cd.tank_collides_with_tile(tank, self.level.solid):
        tank.revert()

    # check for tank to tank collisions
    conflicts = True
    loops = 0
    while conflicts:
      loops += 1
      # break out if we've obviously hit an infinite loop
      if loops > 20:
        if self.level.game.settings['debug']:
          print "tank collision resolution hit an infinite loop"
        break
      conflicts = False
      for tank1 in self.level.all_tanks():
        for tank2 in self.level.all_tanks():
          if tank1 is not tank2 and not tank1.dead and not tank2.dead and cd.tank_collides_with_tank(tank1, tank2):
            conflicts = True

            def revert(t1, t2):
              t1.revert()
              if cd.tank_collides_with_tank(t1, t2):
                t2.revert()

            # revert the enemy first, if there is one
            if tank2 in self.level.enemies:
              revert(tank2, tank1)
            else:
              revert(tank1, tank2)
Esempio n. 2
0
 def revert(t1, t2):
   t1.revert()
   if cd.tank_collides_with_tank(t1, t2):
     t2.revert()