Android Open Source - Castle-Invaders Spell Effect






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;
//from  ww  w  .java 2 s  . co m

import com.badlogic.gdx.Gdx;
import com.noobygames.castleinvaders.GameLiving;
import com.noobygames.castleinvaders.World.States;
/**
 *
 * @author Nerzal
 *
 */
public class SpellEffect extends Spells {

  protected float effectDuration;
  protected float effectDmg;
  protected float tickDamage;
  protected float tickDuration;
  protected float tickTimer;
  protected Condition condition;
  protected float conditionTimer;
  protected float conditionDuration;
  private boolean init = false;
  
  
  public SpellEffect(float x, float y, float width, float height,
      GameLiving caster, GameLiving target, Spell spell) {
    super(x, y, width, height, caster, target, spell);
    //target.addSpellEffect(this);
  }

  public void init(){ // Is called, when the object is created/the spelleffect applies
    init = true;
    if(condition != Condition.root)
      target.condition.add(condition); 
    else if(target.rootResistTimer <= 0){ // To avoid perma root
      target.condition.add(condition); 
    }
    conditionTimer = conditionDuration;
    tickTimer = tickDuration;
    
  }
  
  public void updateAll(){
    if(!init) 
      init();
    updateTickTimer();
    updateConditionTimer();
  }
  
  /**
   * Updates ands resets the tickTimer
   */
  protected void updateTickTimer(){
    tickTimer -= Gdx.graphics.getDeltaTime();
    effectDuration -= Gdx.graphics.getDeltaTime();
    //Gdx.app.log("TickTimer", ""+tickTimer);
    if(tickTimer <= 0){
      tickTimer = tickDuration;
      this.harmTarget(tickDamage);  
      if(effectDuration <= 0 || target.state == States.die && target != null ){
        if(target.condition.contains(Condition.root, true))
          target.rootResistTimer = 2.5f;
        target.removeSpellEffect(this);
        target.condition.removeValue(this.condition, true);  
      }
    }
      
  }
  
  /**
   * Updates ands resets the tickTimer
   */
  protected void updateConditionTimer(){
    conditionTimer -= Gdx.graphics.getDeltaTime();
    if(conditionTimer <= 0)
      target.condition.removeValue(this.condition, true);
        //Gdx.app.log("Condition", "Removed!");
    /*else
      if(this.condition == Condition.root)
        target.velocity.x = 0;*/
  }
  
  /**Calls the targets harm method to deal damage
   * @param dmg dmg to deal
   * @see GameLiving**/
  protected void harmTarget(float dmg){
  //  Gdx.app.log("BURNING", "Harmed target - SpellEffect.Burning! "+dmg+" damage done!"+" Effect/Burndmg: "+effectDmg+"/"+tickDamage);
    if(dmg>0)
      this.target.harm(dmg, this.damageType, this.caster);
  //  Gdx.app.log("BURNING", "Target has now: "+target.hp+" hp!");
  }
  

  /**
   * @return the effectDuration
   */
  public float getEffectDuration() {
    return effectDuration;
  }

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

  /**
   * @return the effectDmg
   */
  public float getEffectDmg() {
    return effectDmg;
  }

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

  /**
   * @return the tickDamage
   */
  public float getTickDamage() {
    return tickDamage;
  }

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

  /**
   * @return the tickDuration
   */
  public float getTickDuration() {
    return tickDuration;
  }

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

  /**
   * @return the condition
   */
  public Condition getCondition() {
    return condition;
  }

  /**
   * @param condition the condition to set
   */
  public void setCondition(Condition condition) {
    this.condition = condition;
  }
  
  
  /**
   * 
   * @param conditionDuration the duration to set
   */
  public void setConditionDuration(float conditionDuration){
    this.conditionDuration = conditionDuration;
  }

}




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