Android Open Source - Castle-Invaders Spells






From Project

Back to project page Castle-Invaders.

License

The source code is released under:

GNU General Public License

If you think the Android project Castle-Invaders listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.noobygames.nerzal.castleinvaders.spells;
// ww  w  . j  a  v  a  2  s  .com
import com.badlogic.gdx.math.Rectangle;
import com.noobygames.castleinvaders.DynamicGameObject;
import com.noobygames.castleinvaders.GameLiving;
import com.noobygames.castleinvaders.GameLiving.DamageType;
import com.noobygames.castleinvaders.World.Species;
import com.noobygames.castleinvaders.World.States;

/** @author Tobi **/
public class Spells extends DynamicGameObject {

  protected float lifeTime;
  protected float spellDuration;
  protected boolean isDot;
  protected GameLiving caster;
  protected GameLiving target;
  private Spell spell;
  protected int attackDamage;
  protected float stateTime;
  protected int spellLevel;
  protected DamageType damageType;
  private boolean hitTarget;
  private float hitTimer;

  public enum Spell {
    fireBolt, grumblingIce//, burning
  };

  /**
   * Default constructor of Spells
   * 
   * @param x
   *            lower left corner
   * @param y
   *            lower left corner
   * @param width
   *            width
   * @param height
   *            height
   * @param caster
   *            Casting mob
   * @param target
   *            the spells target
   * @param spell
   *            e-num Inhabits the specific spell name, like fireBolt or
   *            grumblingIce
   **/
  public Spells(float x, float y, float width, float height,
      GameLiving caster, GameLiving target, Spell spell) {
    super(x, y, width, height, Species.spell);
    position.set(x, y);
    lifeTime = 0;
    this.caster = caster;
    this.setTarget(target);
    this.setSpell(spell);
    stateTime = 0;
    setHitTarget(false);
    setHitTimer(0.0f);

    switch (spell) {
    case fireBolt:
      hitRange = 0;
      attackDamage = 30;
      damageType = DamageType.fire;
      isDot = true;
      velocity.set(15, 0);
      break;
    case grumblingIce:
      hitRange = 0;
      attackDamage = 20;
      damageType = DamageType.ice;
      isDot = false;
      velocity.set(15, 0);
    default:
      break;
    }
    setCenterX(position.x + width / 2);

  }

  public Spells(Rectangle bounds) {
    super(bounds);
  }

  /**Checks if the Spell has hit its target
   * @return true if hit**/
  private boolean checkCollision() {
    if(getCenterX() >= getTarget().getCenterX())
      return true;
    else
      return false;
  }

  /**
   * updates position calls target.harm(), when in hitRange
   * 
   * @param deltaTime
   *            Time since last frame
   */
  public void update(float deltaTime) {
    if (!isHitTarget()) {
      position.x += velocity.x;
      if (checkCollision()) {
        checkForSpellEffects();
        if (getTarget().harm(attackDamage, damageType, caster) || getTarget().state == States.die) {
          setTarget(null);
        }
        setHitTarget(true);
        //Assets.fireBallHit.play((float) 0.3);
        //Assets.fireBallHit.play();
      }
    } else 
    setHitTimer(getHitTimer() + deltaTime);
    
    setCenterX(position.x + width/2);
  
    stateTime += deltaTime;
  }

  private void checkForSpellEffects() { //TODO write a prettier method!
    switch(this.spell){
    case fireBolt: 
      if(!target.condition.contains(Condition.dot, true))
        target.addSpellEffect(new Burning(this.bounds.getX(), this.bounds.getY(), this.bounds.getWidth(), this.bounds.getHeight(), caster, target, Spell.fireBolt));
      break;
    case grumblingIce:
      if(!target.condition.contains(Condition.root, true))
        target.addSpellEffect(new Freeze(this.bounds.getX(), this.bounds.getY(), this.bounds.getWidth(), this.bounds.getHeight(), caster, target, Spell.grumblingIce));
      break;
    default:
      break;
    }
  }

  public float getStateTime() {
    return stateTime;
  }

  /**
   * @return the target
   */
  public GameLiving getTarget() {
    return target;
  }

  /**
   * @param target the target to set
   */
  public void setTarget(GameLiving target) {
    this.target = target;
  }

  /**
   * @return the hitTimer
   */
  public float getHitTimer() {
    return hitTimer;
  }

  /**
   * @param hitTimer the hitTimer to set
   */
  public void setHitTimer(float hitTimer) {
    this.hitTimer = hitTimer;
  }

  /**
   * @return the hitTarget
   */
  public boolean isHitTarget() {
    return hitTarget;
  }

  /**
   * @param hitTarget the hitTarget to set
   */
  public void setHitTarget(boolean hitTarget) {
    this.hitTarget = hitTarget;
  }

  /**
   * @return the spell
   */
  public Spell getSpell() {
    return spell;
  }

  /**
   * @param spell the spell to set
   */
  public void setSpell(Spell spell) {
    this.spell = spell;
  }

}




Java Source Code List

com.noobgygames.castleinvaders.ui.DragonUltiButton.java
com.noobgygames.castleinvaders.ui.ElementSwitcherButton.java
com.noobgygames.castleinvaders.ui.StoreElement.java
com.noobgygames.castleinvaders.ui.TextureElement.java
com.noobygames.castleinvaders.Assets.java
com.noobygames.castleinvaders.CastleInvaders.java
com.noobygames.castleinvaders.DynamicGameObject.java
com.noobygames.castleinvaders.GameLiving.java
com.noobygames.castleinvaders.GameObject.java
com.noobygames.castleinvaders.MainActivity.java
com.noobygames.castleinvaders.Main.java
com.noobygames.castleinvaders.Player.java
com.noobygames.castleinvaders.Projectile.java
com.noobygames.castleinvaders.Settings.java
com.noobygames.castleinvaders.WorldRenderer.java
com.noobygames.castleinvaders.World.java
com.noobygames.castleinvaders.mobs.Croco.java
com.noobygames.castleinvaders.mobs.EarthDragon.java
com.noobygames.castleinvaders.mobs.FireDragon.java
com.noobygames.castleinvaders.mobs.FireTroll.java
com.noobygames.castleinvaders.mobs.GameScreen.java
com.noobygames.castleinvaders.mobs.GreyTroll.java
com.noobygames.castleinvaders.mobs.IceDragon.java
com.noobygames.castleinvaders.mobs.IceTroll.java
com.noobygames.castleinvaders.mobs.Murloc.java
com.noobygames.castleinvaders.mobs.Orc.java
com.noobygames.castleinvaders.mobs.Skeleton.java
com.noobygames.castleinvaders.screens.GameScreen.java
com.noobygames.castleinvaders.screens.MainMenuScreen.java
com.noobygames.castleinvaders.screens.ScoreScreen.java
com.noobygames.castleinvaders.screens.SplashScreen.java
com.noobygames.castleinvaders.screens.StoreScreen.java
com.noobygames.castleinvaders.store.StoreObject.java
com.noobygames.castleinvaders.store.Store.java
com.noobygames.nerzal.castleinvaders.spells.Burning.java
com.noobygames.nerzal.castleinvaders.spells.Freeze.java
com.noobygames.nerzal.castleinvaders.spells.SpellEffect.java
com.noobygames.nerzal.castleinvaders.spells.Spells.java
com.noobygames.utils.ArrayListUtils.java
com.noobygames.utils.ObjectSelectionContainer.java
com.noobygames.utils.OverlapTester.java
com.noobygames.utils.exceptions.OutOfBoundingException.java
com.noobygames.utils.exceptions.SliderOutOfBoundingsException.java
com.noobygames.utils.ui.Button.java
com.noobygames.utils.ui.ClickableElement.java
com.noobygames.utils.ui.DropDownMenu.java
com.noobygames.utils.ui.Element.java
com.noobygames.utils.ui.RadioButton.java
com.noobygames.utils.ui.RadioGroupButton.java
com.noobygames.utils.ui.ScrollableElement.java
com.noobygames.utils.ui.SimpleElement.java
com.noobygames.utils.ui.Slider.java
com.noobygames.utils.ui.Table.java
com.noobygames.utils.ui.TextBox.java
com.noobygames.utils.ui.Text.java
com.noobygames.utils.ui.Window.java