Ejemplo n.º 1
0
  private void headFor(Vector2 target) {
    assert Rectangle.contains(movementRect, target);

    Vector2 delta = Vector2.subtract(target, body.getMin());
    Vector2 direction = delta.normalize();
    Vector2 velocity = Vector2.multiply(direction, speed);
    movement.setVelocity(velocity);
  }
Ejemplo n.º 2
0
 @Override
 public void update(GameTime time) {
   if (targetsLeft > 0) {
     Vector2 a = Vector2.subtract(body.getMin(), currentTarget);
     if (Vector2.dot(a, movement.getVelocity()) >= 0) {
       --targetsLeft;
       // Target passed
       if (targetsLeft > 0) {
         currentTarget =
             newRandomTarget(
                 Locator.getRandom(),
                 (int) movementRect.getX1(),
                 (int) movementRect.getY1(),
                 (int) movementRect.getX2(),
                 (int) movementRect.getY2(),
                 (int) body.getX1(),
                 (int) body.getY1(),
                 MIN_WALK_SQUARED);
         headFor(currentTarget);
       }
     }
   }
 }