Example #1
0
  @Override
  public void drawEffects(Canvas canvas) {
    if (firing) {
      float radius = POWER_CIRCLE_RADIUS * powerLevel / MAX_POWER_LEVEL;
      if (radius > 0f) {
        tempPaint.set(paint);

        paint.setStyle(Style.FILL);
        paint.setColor(Color.GRAY);

        paint.setStrokeWidth(radius);
        canvas.drawLine(getX(), getY(), fireTarget.getX(), fireTarget.getY(), paint);

        canvas.drawCircle(fireTarget.getX(), fireTarget.getY(), radius * .7f, paint);

        paint.setColor(Color.WHITE);
        canvas.drawCircle(getX(), getY(), radius, paint);
        canvas.drawCircle(fireTarget.getX(), fireTarget.getY(), radius * .45f, paint);

        paint.setStrokeWidth(radius * .5f);
        canvas.drawLine(getX(), getY(), fireTarget.getX(), fireTarget.getY(), paint);

        paint.set(tempPaint);
      }
    }
  }
Example #2
0
  @Override
  public void update(float seconds) {
    super.update(seconds);

    if (isDead()) return;

    if (firing) {
      if (!getStateName().equals("attacking")
          || fireTarget.isDead()
          || powerLevel < 0) { // $NON-NLS-1$
        powerLevel = Math.max(0f, powerLevel);
        charging = true;
        firing = false;
        fireTarget = null;
      } else {
        powerLevel -= DISCHARGE_RATE;
        float damage = DAMAGE_RATE * seconds;
        for (Unit unit :
            unitManager.getUnitsIntersectingLine(
                getX(), getY(), fireTarget.getX(), fireTarget.getY())) {
          if (team.isEnemy(unit.getTeam())) {
            unit.takeDamage(damage, this);
          }
        }
      }
    } else {
      if (powerLevel > MAX_POWER_LEVEL) { // that is, if its power level is over 9000
        powerLevel = MAX_POWER_LEVEL;
        charging = false;
      } else {
        charging = true;
      }

      if (charging) {
        powerLevel += CHARGE_RATE * seconds;
      }

      if (!charging
          && target != null
          && !target.isDead()
          && getStateName().equals("attacking")) { // $NON-NLS-1$
        firing = true;
        fireTarget = target;
      }
    }
  }