Example #1
0
 public void sell() {
   destroy();
   int ret = 0;
   for (TowerType t = getTowerType(); t != null; t = t.getBase()) {
     ret += t.getCost();
   }
   m.getGame().setMoney(m.getGame().getMoney() + ret);
 }
Example #2
0
 public boolean isNpcInRange() {
   for (NPC npc : m.getGame().getNpcs()) {
     if (isInRange(
         npc.getX(), npc.getY(), getX(), getY(), getRange() * m.getGame().getTileWidth())) {
       return true;
     }
   }
   return false;
 }
Example #3
0
  public void damageGround(Projectile p) {
    NPC target = getClosestNPC(p.getX(), p.getY());

    if (target != null)
      if (getDistance(target.getX(), target.getY(), p.getX(), p.getY())
          < m.getGame().getTileWidth()) if (canAttack(this, target)) target.damage(getDamage());
  }
Example #4
0
  public Tower upgradeTo(TowerType t) {
    if (m.getGame().getMoney() >= t.getCost()) {
      m.getGame().setMoney(m.getGame().getMoney() - t.getCost());
      Tower t2 = m.getGame().createTower(t);
      t2.setX(getX());
      t2.setY(getY());
      destroy();
      return t2;
    } else {
      m.getGame().setStatus("Not enough money!");
      m.setNewEvent(
          new Event(m, 2000, 1) {
            public void run(int delta) {
              m.getGame().setStatus("", "Not enough money!");
            }
          });
    }

    return null;
  }
Example #5
0
  public NPC getClosestNPC(double x, double y) {
    double minDistance = Double.MAX_VALUE;
    NPC closest = null;

    for (NPC npc : m.getGame().getNpcs()) {
      if (!canAttack(this, npc)) {
        continue;
      }
      if (getDistance(npc.getX(), npc.getY(), x, y) < minDistance) {
        minDistance = getDistance(npc.getX(), npc.getY(), x, y);
        closest = npc;
      }
    }
    return closest;
  }
Example #6
0
  public void attack() {
    NPC target = getClosestNPC();

    if (target != null) {
      setAAcd(getAAcd() + 1.0D / getAttackSpeed());
      setAnimation(ANIMATION_POST_ATTACK);

      Projectile p = new Projectile(m, getX(), getY(), target, this);
      p.setAnimationDeath(getProjectileAnimationDeath());
      p.setAnimationStand(getProjectileAnimationStand());
      p.setAnimationDeathDuration(getProjectileAnimationDeathDuration());
      p.setAnimationStandDuration(getProjectileAnimationStandDuration());
      m.getGame().setNewProjectile(p);
    }
  }
Example #7
0
 public void destroy() {
   m.getGame().destroySprite(getSprite());
   m.getGame().destroyTower(this);
 }
Example #8
0
  public void drawLogic(int delta) {
    int duration = getAnimationStandDuration();
    BufferedImage animation = getAnimationStand();

    if (getAnimation() == ANIMATION_PRE_ATTACK) {
      duration = getAnimationPreAttackDuration();
      animation = getAnimationPreAttack();
    }
    if (getAnimation() == ANIMATION_POST_ATTACK) {
      duration = getAnimationPostAttackDuration();
      animation = getAnimationPostAttack();
    }

    if (getAnimationTime() + delta >= duration && getAnimation() == ANIMATION_POST_ATTACK) {
      setAnimation(ANIMATION_STAND);
      duration = getAnimationStandDuration();
      animation = getAnimationStand();
    } else if (getAnimationTime() + delta >= duration && getAnimation() == ANIMATION_PRE_ATTACK) {
      setAnimationTime(getAnimationTime() - delta);
    } else if (getAAcd() * 1000D <= getAnimationPreAttackDuration()
        && getAnimation() == ANIMATION_STAND) {
      setAnimation(ANIMATION_PRE_ATTACK);
      duration = getAnimationPreAttackDuration();
      animation = getAnimationPreAttack();
    }
    setAnimationTime((getAnimationTime() + delta) % duration);
    int phase =
        (int)
            ((double) getAnimationTime()
                / (double) duration
                * (double) Animation.getImagePhases(animation));
    if (getSprite() == null) {
      Sprite s =
          new Sprite(
              m,
              (int) getX(),
              (int) getY(),
              Animation.getImagePhase(animation, phase, m),
              this,
              false);
      m.getGame().setNewSprite(s);
      setSprite(s);
    } else {
      if ((getSprite().getX() == getX()
          && getSprite().getY() == getY()
          && getSprite().getImage() == Animation.getImagePhase(animation, phase, m))) {
      } else {
        m.getGame().destroySprite(getSprite());
        Sprite s =
            new Sprite(
                m,
                (int) getX(),
                (int) getY(),
                Animation.getImagePhase(animation, phase, m),
                this,
                false);
        m.getGame().setNewSprite(s);
        setSprite(s);
      }
    }
  }