Exemple #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);
      }
    }
  }
Exemple #2
0
  public void draw(Canvas canvas) {
    canvas.drawRect(DIMENSIONS, rectPaint);

    // TODO Fixme
    if (this.currentUnitType == UnitType.ATTACKING) {
      unitPaint.setColor(Color.WHITE);
      attacker.drawChassis(canvas);
      unitPaint.setColor(Color.GRAY);
      defender.drawChassis(canvas);
    } else if (this.currentUnitType == UnitType.DEFENDING) {
      unitPaint.setColor(Color.WHITE);
      defender.drawChassis(canvas);
      unitPaint.setColor(Color.GRAY);
      attacker.drawChassis(canvas);
    }
  }
Exemple #3
0
  public UnitSelector(Team team, UnitManager mom, ParticleSystem particles) {
    currentUnitType = UnitType.ATTACKING;
    rectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    rectPaint.setARGB(127, 0, 0, 0);

    unitPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    unitPaint.setStrokeWidth(2.0f);
    unitPaint.setStrokeJoin(Join.ROUND);
    unitPaint.setStyle(Style.STROKE);
    unitPaint.setAntiAlias(true);
    unitPaint.setStrokeCap(Cap.ROUND);

    attacker = UnitType.ATTACKING.createUnit(mom, team, unitPaint, particles);
    attacker.setPosition(DIMENSIONS.centerX(), UNIT_HEIGHT / 2);
    defender = UnitType.DEFENDING.createUnit(mom, team, unitPaint, particles);
    defender.setPosition(DIMENSIONS.centerX(), UNIT_HEIGHT + UNIT_HEIGHT / 2);
  }
Exemple #4
0
  public void takeDamage(float damage, Unit inflictor) {
    if (!isDead()) {
      health -= damage;

      if (inflictor != null && inflictor.getType() == UnitType.UBER) attackedByUber = true;

      if (isDead()) {
        onDead();
        killer = inflictor;
        unitManager.notifyUnitDead(this);
      }
    }
  }
Exemple #5
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;
      }
    }
  }