Package jpotter.spells

Source Code of jpotter.spells.Spell

package jpotter.spells;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Point;

import jpotter.Game;
import jpotter.IHM;
import jpotter.Player;

import org.jdesktop.animation.timing.Animator;
import org.jdesktop.animation.timing.TimingTarget;
import org.jdesktop.animation.timing.interpolation.PropertySetter;

/**
* Date: 19 Mar 2011 Time: 10:23:58
*
* @author Thomas Michel
*/
public abstract class Spell {

  private final String incantation;
  private final String gestureName;
  private final int    damage;

  public Spell(String incantation, String gestureName, int damage) {
    this.incantation = incantation;
    this.gestureName = gestureName;
    this.damage = damage;
  }

  public String getIncantation() {
    return incantation;
  }

  public String getGesture() {
    return gestureName;
  }

  public abstract Component getComponent();

  public final void cast(final Component component, Point from, Point to,
      final Container container, final boolean toEnemy) {
    Animator anim = PropertySetter.createAnimator(2000, component, "location",
        from, to);
    anim.addTarget(new TimingTarget() {

      @Override
      public void timingEvent(float fraction) {
        // not needed
      }

      @Override
      public void repeat() {
        // not needed
      }

      @Override
      public void end() {
        container.remove(component);
        component.setVisible(false);
        if(toEnemy)
          IHM.getInstance().updateEnemyPV(getDamage());
        else
          IHM.getInstance().updateHarryPV(getDamage());
        container.validate();
        container.repaint();
        Game.getInstance().casting = false;
      }

      @Override
      public void begin() {
        component.setVisible(true);
      }
    });
    anim.setDeceleration(0.25f);
    anim.start();
  }

  public abstract Dimension getDimension();

  public final void cast(Point from, Point to, Container container, boolean toEnemy) {
    cast(getComponent(), from, to, container, toEnemy);
  }

  @Override
  public String toString() {
    return incantation + " ->" + gestureName;
  }

public int getDamage() {
  return damage;
}

}
TOP

Related Classes of jpotter.spells.Spell

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.