Ejemplo n.º 1
0
 /** Returns the base animation for the actor. */
 protected Animation getBase(Mobile actor) {
   if (actor.isSet(Mobile.MOVING)) {
     Animation anim = getMovement(actor);
     if (anim != null) {
       return anim;
     }
   }
   if (actor.getTurnDirection() != 0) {
     Animation anim = getRotation(actor);
     if (anim != null) {
       return anim;
     }
   }
   return getIdle();
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
 /**
  * Configures and returns the appropriate rotation animation for the actor.
  *
  * @param sets the rotation set configs.
  * @param rotations the resolved rotation animations.
  */
 protected static Animation getRotation(
     Mobile actor, ActorSpriteConfig.RotationSet[] sets, Animation[][] rotations) {
   // make sure we have rotation animations
   int rlen = rotations.length;
   if (rlen == 0) {
     return null;
   }
   float rate = actor.getTurnRate();
   int idx = 0;
   if (rlen > 1) {
     float cdiff = Math.abs(rate - sets[0].rate);
     for (int ii = 1; ii < sets.length; ii++) {
       float diff = Math.abs(rate - sets[ii].rate);
       if (diff < cdiff) {
         cdiff = diff;
         idx = ii;
       }
     }
   }
   Animation rotation = rotations[idx][actor.getTurnDirection() > 0 ? 0 : 1];
   rotation.setSpeed(rate / sets[idx].rate);
   return rotation;
 }