Пример #1
0
 @Override
 public Vector3f getValue(Vector3f result) {
   return result.set(
       FloatMath.random(minimum.x, maximum.x),
       FloatMath.random(minimum.y, maximum.y),
       FloatMath.random(minimum.z, maximum.z));
 }
Пример #2
0
 /**
  * Configures and returns the appropriate movement animation for the actor.
  *
  * @param scale the actor scale.
  * @param sets the movement set configs.
  * @param movements the resolved movement animations.
  */
 protected static Animation getMovement(
     Mobile actor, float scale, ActorSpriteConfig.MovementSet[] sets, Animation[][] movements) {
   // make sure we have movement animations
   int mlen = movements.length;
   if (mlen == 0) {
     return null;
   }
   float sspeed = actor.getSpeed() / scale;
   int idx = 0;
   if (mlen > 1) {
     float cdiff = Math.abs(sspeed - sets[0].speed);
     for (int ii = 1; ii < sets.length; ii++) {
       float diff = Math.abs(sspeed - sets[ii].speed);
       if (diff < cdiff) {
         cdiff = diff;
         idx = ii;
       }
     }
   }
   // include a bias towards the lateral directions so that we're sure to use them
   // when travelling diagonally
   float angle =
       (FloatMath.getAngularDifference(actor.getDirection(), actor.getRotation())
                   / FloatMath.HALF_PI
               + 2.5f)
           % 4f;
   Animation movement;
   if (angle <= 0.01f || angle >= 2.99f) {
     movement = movements[idx][3];
   } else if (angle < 0.99f) {
     movement = movements[idx][0];
   } else if (angle <= 2.01f) {
     movement = movements[idx][1];
   } else {
     movement = movements[idx][2];
   }
   movement.setSpeed(sspeed / sets[idx].speed);
   return movement;
 }