aurelienribon.tweenengine.TweenCallback Java Examples

The following examples show how to use aurelienribon.tweenengine.TweenCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RangeSystem.java    From xibalba with MIT License 6 votes vote down vote up
private void doThrowAnimation(Entity entity, Entity item, Vector2 position, boolean destroy) {
  // We have to set the items position before starting the tween since who knows wtf
  // position it had before it ended up in your inventory.
  PositionComponent entityPosition = ComponentMappers.position.get(entity);

  WorldManager.entityHelpers.updatePosition(item, entityPosition.pos.x, entityPosition.pos.y);
  WorldManager.entityHelpers.updateSprite(item, entityPosition.pos.x, entityPosition.pos.y);

  VisualComponent itemVisual = ComponentMappers.visual.get(item);

  WorldManager.tweens.add(Tween.to(itemVisual.sprite, SpriteAccessor.XY, .1f).target(
      position.x * Main.SPRITE_WIDTH, position.y * Main.SPRITE_HEIGHT
  ).setCallback(
      (type, source) -> {
        if (type == TweenCallback.COMPLETE) {
          WorldManager.itemHelpers.drop(entity, item, position, destroy);
        }
      }
  ));
}
 
Example #2
Source File: Knockback.java    From xibalba with MIT License 4 votes vote down vote up
@Override
public void act(Entity caster, Entity target) {
  AttributesComponent casterAttributes = ComponentMappers.attributes.get(caster);

  if (casterAttributes.energy >= MeleeComponent.COST
      && WorldManager.entityHelpers.isNear(caster, target)) {
    PositionComponent casterPosition = ComponentMappers.position.get(caster);
    PositionComponent targetPosition = ComponentMappers.position.get(target);

    caster.add(new MeleeComponent(target, "body", false));

    int maxDistance = MathUtils.random(1, 3);

    Vector2 newPosition = getKnockbackPosition(
        casterPosition.pos, targetPosition.pos, maxDistance
    );

    VisualComponent targetVisual = ComponentMappers.visual.get(target);

    WorldManager.tweens.add(
        Tween.to(targetVisual.sprite, SpriteAccessor.XY, .25f).target(
            newPosition.x * Main.SPRITE_WIDTH, newPosition.y * Main.SPRITE_HEIGHT
        ).setCallback((type, source) -> {
          if (type == TweenCallback.COMPLETE) {
            targetPosition.pos.set(newPosition);

            Vector2 behindNewPosition = getCellBehind(casterPosition.pos, targetPosition.pos);

            if (WorldManager.mapHelpers.getCell(behindNewPosition).type == MapCell.Type.WALL
                || WorldManager.mapHelpers.getEnemyAt(behindNewPosition) != null) {
              Main.cameraShake.shake(.5f, .1f);

              WorldManager.tweens.add(
                  Tween.to(targetVisual.sprite, SpriteAccessor.ALPHA, .05f)
                      .target(.25f).repeatYoyo(1, 0f)
              );

              int damage = MathUtils.random(3, 5);
              WorldManager.entityHelpers.takeDamage(target, damage);
              WorldManager.mapHelpers.makeFloorBloody(targetPosition.pos);

              AttributesComponent targetAttributes = ComponentMappers.attributes.get(target);
              WorldManager.log.add("effects.knockback.damaged", targetAttributes.name, damage);
            }
          }
        })
    );
  }
}
 
Example #3
Source File: JumpOverEnemy.java    From xibalba with MIT License 4 votes vote down vote up
@Override
public void act(Entity caster, Entity target) {
  AttributesComponent attributes = ComponentMappers.attributes.get(caster);

  if (attributes.energy >= MovementComponent.COST
      && WorldManager.entityHelpers.isNear(caster, target)) {
    PositionComponent casterPosition = ComponentMappers.position.get(caster);
    PositionComponent targetPosition = ComponentMappers.position.get(target);

    float newPositionX = targetPosition.pos.x;
    float newPositionY = targetPosition.pos.y;

    if (casterPosition.pos.x < targetPosition.pos.x) {
      newPositionX += 1;
    } else if (casterPosition.pos.x > targetPosition.pos.x) {
      newPositionX -= 1;
    }

    if (casterPosition.pos.y < targetPosition.pos.y) {
      newPositionY += 1;
    } else if (casterPosition.pos.y > targetPosition.pos.y) {
      newPositionY -= 1;
    }

    Vector2 newPosition = new Vector2(newPositionX, newPositionY);

    if (!WorldManager.mapHelpers.isBlocked(newPosition)) {
      VisualComponent visual = ComponentMappers.visual.get(caster);

      WorldManager.tweens.add(
          Tween.to(visual.sprite, SpriteAccessor.SCALE, .25f).target(
              1.2f, 1.2f
          ).repeatYoyo(1, 0f).ease(Elastic.INOUT)
      );

      WorldManager.tweens.add(
          Tween.to(visual.sprite, SpriteAccessor.XY, .25f).target(
              newPosition.x * Main.SPRITE_WIDTH, newPosition.y * Main.SPRITE_HEIGHT
          ).setCallback((type, source) -> {
            if (type == TweenCallback.COMPLETE) {
              casterPosition.pos.set(newPosition);
            }
          })
      );
    }
  }
}