コード例 #1
0
ファイル: ActorSprite.java プロジェクト: kevindude/clyde
    @Override
    public void update(Actor actor) {
      super.update(actor);

      // update the base animation
      Animation base = getBase((Mobile) actor);
      if (base != null && !base.isPlaying()) {
        base.start();
      }
    }
コード例 #2
0
ファイル: ActorSprite.java プロジェクト: kevindude/clyde
 /**
  * Returns a weighted random animation (unless one of the animations is already playing, in
  * which case the method will return that animation).
  */
 protected static Animation getWeightedAnimation(Animation[] anims, float[] weights) {
   if (anims.length == 0) {
     return null;
   }
   for (Animation anim : anims) {
     if (anim.isPlaying()) {
       return anim;
     }
   }
   return anims[RandomUtil.getWeightedIndex(weights)];
 }
コード例 #3
0
ファイル: ActorSprite.java プロジェクト: kevindude/clyde
    @Override
    public void update(Actor actor) {
      super.update(actor);

      // update the state animation
      EntryState estate = (EntryState) actor;
      int entered = estate.getStateEntered();
      if (entered > _lastStateEntered) {
        int state = estate.getState();
        Animation anim = (_states != null && state < _states.length) ? _states[state] : null;
        if (anim != null) {
          anim.start();
          anim.tick((_view.getDelayedTime() - entered) / 1000f);
        }
        _lastStateEntered = entered;
      }
    }
コード例 #4
0
ファイル: ActorSprite.java プロジェクト: kevindude/clyde
 /**
  * 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;
 }
コード例 #5
0
ファイル: ActorSprite.java プロジェクト: kevindude/clyde
 /**
  * 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;
 }