Пример #1
0
    def handle_unit(self, unit, other):
        flagged = set()
        adjusts = set()
        while other != None:
            proximity = collides(unit, other)
            if proximity:
                unit_collided = unit.handle_collision(other)
                other_collided = other.handle_collision(unit)
                if unit_collided and other_collided:
                    flagged.update([unit, other])
                    

                    if unit.solid and other.solid:
                        if proximity < unit.radius + other.radius:
                            dx, dy = tools.one_step_toward_destination((other.x, other.y), 
                                             (unit.x, unit.y), 
                                             (10.)) # this value should be how far
                                                      # unit overlaps into other
                                             
                            if not unit.immobile:
                                self.move(unit, -dx, -dy)
                                if other.immobile:
                                    unit.receive_command(None, command="STOP")
                                else:
                                    unit.brain.set_state("waiting")
                            if not other.immobile:
                                self.move(other, dx, dy)
                                if unit.immobile:
                                    other.receive_command(None, command="STOP")
                                else:
                                    other.brain.set_state("waiting")
                            adjusts.update([unit])#, other])

            else:
                pass
            other = other.next
        flagged.difference_update(adjusts)
        return flagged
Пример #2
0
    def handle_unit(self, unit, other):
        flagged = set()
        adjusts = set()
        while other != None:
            proximity = collides(unit, other)
            if proximity:
                unit_collided = unit.handle_collision(other)
                other_collided = other.handle_collision(unit)
                if unit_collided and other_collided:
                    flagged.update([unit, other])

                    if unit.solid and other.solid:
                        if proximity < unit.radius + other.radius:
                            dx, dy = tools.one_step_toward_destination(
                                (other.x, other.y), (unit.x, unit.y),
                                (10.))  # this value should be how far
                            # unit overlaps into other

                            if not unit.immobile:
                                self.move(unit, -dx, -dy)
                                if other.immobile:
                                    unit.receive_command(None, command="STOP")
                                else:
                                    unit.brain.set_state("waiting")
                            if not other.immobile:
                                self.move(other, dx, dy)
                                if unit.immobile:
                                    other.receive_command(None, command="STOP")
                                else:
                                    other.brain.set_state("waiting")
                            adjusts.update([unit])  #, other])

            else:
                pass
            other = other.next
        flagged.difference_update(adjusts)
        return flagged
Пример #3
0
 def do_actions(self):
     distance_traveled = self.unit.velocity
     dx, dy = tools.one_step_toward_destination(
         self.unit.current_destination, (self.unit.x, self.unit.y),
         distance_traveled)
     self.unit.move(dx, dy)
Пример #4
0
 def do_actions(self):
     distance_traveled = self.unit.velocity
     dx, dy = tools.one_step_toward_destination(self.unit.current_destination, 
                                          (self.unit.x, self.unit.y), 
                                          distance_traveled)
     self.unit.move(dx, dy)