@Override
  public void setPosition(Pointt position) {
    super.setPosition(position);
    generatePaint();
    double startAngle = Maths.randomAngle();
    GeneralPath tempRep = new GeneralPath();

    Pointt next = new Pointt(0, 0);
    for (int i = 0; i < vertices.length; i++) {
      vertices[i] =
          next.getArcPointt(
              radius() * Geometry.DISPLAY_REAL_RATIO,
              startAngle + i * 2 * (Math.PI / NUMBER_OF_VERTICES));
    }

    tempRep.moveTo(vertices[0].getX(), vertices[0].getY());

    for (int i = 0; i < vertices.length; i++) {
      next = vertices[(i + 1) % vertices.length];
      tempRep.quadTo(
          vertices[i].midPoint(next).getX()
              + Maths.randomNegative(radius() * Geometry.DISPLAY_REAL_RATIO / 2),
          vertices[i].midPoint(next).getY()
              + Maths.randomNegative(radius() * Geometry.DISPLAY_REAL_RATIO / 2),
          next.getX(),
          next.getY());
    }

    tempRep.closePath();
    rep = new Area(tempRep);

    for (int i = 0; i < vertices.length; i++) {
      vertices[i].translate(position);
    }
  }
  @Override
  public synchronized void moveNoCollision(double time) {
    if (2 * relativeTime >= SKILL_BOUND) { // Half Period
      clearTask();
      owner().setRepel(false);
      owner().removeDive();
    } else {
      relativeTime += INCREMENT;

      Pointt currentPosition = position(relativeTime);
      Pointt veryClose = position(relativeTime + DELTA);
      owner().setMovingAngle(currentPosition.angle(veryClose));
      owner().setPosition(currentPosition);

      for (int i = 1; i < 10; i++) {
        synchronized (game().visualEffects()) {
          game()
              .visualEffects()
              .add(
                  new UniversalEffect(
                      position(relativeTime - i * INCREMENT / 5),
                      DragonFly.repInstances[0],
                      DragonFly.standardColors,
                      (2 * (10 - i) + 1) / FADE_TIME,
                      0,
                      owner().movingAngle(),
                      UniversalEffect.STAND_STILL,
                      UniversalEffect.FADING,
                      UniversalEffect.SHRINKING_SCALE));
        }
      }
    }
  }
Exemple #3
0
 // Update heading direction
 public void updateMovement(Pointt destination) {
   this.destination = destination;
   finalAngle =
       Geometry.arcTan(
           destination.getY() - position.getY(),
           destination.getX() - position.getX(),
           destination.getX() - position.getX());
 }
Exemple #4
0
 protected Shape healthBar() {
   final int UPPER_DISTANCE = 10;
   final int HEIGHT = 10;
   return new Rectangle2D.Double(
       -Pointt.realToDisplay(radius),
       -Pointt.realToDisplay(radius) - UPPER_DISTANCE - HEIGHT,
       2 * Pointt.realToDisplay(radius),
       HEIGHT);
 }
Exemple #5
0
 protected Shape realHealthBar() {
   final int UPPER_DISTANCE = 10;
   final int HEIGHT = 10;
   try {
     return new Rectangle2D.Double(
         -Pointt.realToDisplay(radius),
         -Pointt.realToDisplay(radius) - UPPER_DISTANCE - HEIGHT,
         2 * Pointt.realToDisplay(radius) * ((double) health / maxHealth),
         HEIGHT);
   } catch (ArithmeticException ex) {
     return null;
   }
 }
Exemple #6
0
 protected Units(Pointt position, double movingAngle, double health) {
   moveable = true;
   this.position = position.clone();
   this.xVelocity = 10;
   this.yVelocity = 10;
   this.movingAngle = movingAngle;
   this.finalAngle = movingAngle;
   this.health = health;
   this.maxHealth = health;
   partColors = new ArrayList<>();
 }
  @Override
  public void plot(Graphics2D a, AffineTransform transform, Pointt focus) {
    if (activate()) {
      a.setTransform(transform);
      Pointt display = displayPosition(focus);
      a.translate(display.getX(), display.getY());

      if (ELAPSE_TIME - elapsedTime() < DISAPPEAR_TIME) {
        if (ELAPSE_TIME - elapsedTime() > 0) {
          a.setComposite(
              AlphaComposite.getInstance(
                  AlphaComposite.SRC_OVER, (ELAPSE_TIME - elapsedTime()) / (float) DISAPPEAR_TIME));
        } else {
          return;
        }
      } else {
        a.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
      }
      a.setPaint(paint);
      a.fill(getRep());
      a.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));

      if (Math.random() < 0.5) {
        synchronized (game().visualEffects()) {
          game()
              .visualEffects()
              .add(
                  new UniversalEffect(
                      position().randomRange(25),
                      Sarcophagidae.repInstances[0],
                      Sarcophagidae.standardColors,
                      APPEAR_TIME_VISUAL / 100,
                      APPEAR_SPEED_VISUAL,
                      Maths.randomAngle(),
                      UniversalEffect.STAND_STILL,
                      UniversalEffect.FADING,
                      UniversalEffect.FIX_SCALE));
        }
      }
    }
  }
Exemple #8
0
  private double tangentialAngle(Units testUnit) {
    double output;

    double side =
        (destination.getY() - position.getY()) * (position.getX() - testUnit.position.getX())
            - (position.getY() - testUnit.position.getY()) * (destination.getX() - position.getX());
    // Change angle to the tangential angle
    output =
        Geometry.arcTan(
                position.getY() - testUnit.position.getY(),
                position.getX() - testUnit.position.getX(),
                position.getX() - testUnit.position.getX())
            - Math.PI / 2;

    if (side >= 0) {
      output += Math.PI;
    }

    return output;
  }
  @Override
  protected void applyEffect(LivingUnit affectedUnit, boolean touched) {
    if (touched) {
      targetPreviousPosition.concur(target().position());
    } else { // Bounced back
      Pointt currentDestination = target().destination();
      double currentSpeed = target().speed();
      double currentMovingAngle = target().movingAngle();
      double currentFinalAngle = target().finalAngle();

      target().setSpeed(target().position().distance(targetPreviousPosition) / UNIT_TIME);
      target().updateMovement(position().clone());
      target().setMovingAngle(target().finalAngle());
      target().moveNoCollision(UNIT_TIME);

      target().setSpeed(currentSpeed);
      target().setDestination(currentDestination);
      target().setMovingAngle(currentMovingAngle);
      target().setFinalAngle(currentFinalAngle);
    }
  }
Exemple #10
0
  @Override
  public synchronized void moveNoCollision(double time) {
    if (2 * relativeTime >= SKILL_BOUND) { // Half Period
      clearTask();
      owner().increaseSplitFire();
      owner()
          .setAttackSpeed(
              Math.max(owner().attackSpeed() - ATTACK_SPEED_DECREMENT, ATTACK_SPEED_MINIMUM));

      synchronized (owner()) {
        owner().rescheduleAttack(0);
      }

      owner().removeDive();
    } else {
      relativeTime += INCREMENT;
      owner().setHealth(owner().health() + healthIncrement, Units.MAGICAL_DAMAGE);

      Pointt currentPosition = position(relativeTime);
      Pointt veryClose = position(relativeTime + DELTA);
      owner().setMovingAngle(currentPosition.angle(veryClose));
      owner().setPosition(currentPosition);

      for (int i = 1; i < 10; i++) {
        synchronized (game().visualEffects()) {
          game()
              .visualEffects()
              .add(
                  new UniversalEffect(
                      position(relativeTime - i * INCREMENT / 5),
                      DragonFly.repInstances[0],
                      DragonFly.standardColors,
                      (i + 1) / FADE_TIME,
                      0,
                      owner().movingAngle(),
                      UniversalEffect.STAND_STILL,
                      UniversalEffect.FADING,
                      UniversalEffect.FIX_SCALE));
        }
      }

      if (owner().pathOfVenoms().activate()) {
        Venom toBeAdd =
            new Venom(game(), owner(), owner().position(), 0, 0, PathOfVenoms.VENOM_TYPE);
        synchronized (owner().projectiles()) {
          owner().projectiles().add(toBeAdd);
        }

        synchronized (owner().venoms()) {
          owner().venoms().add(toBeAdd);
        }

        toBeAdd.schedule();
      }

      int random = Maths.RANDOM.nextInt(Petaluridae.repInstances[0].parts().size());
      ArrayList<Area> part = new ArrayList<>();
      part.add(new Area(Petaluridae.repInstances[0].parts().get(random)));

      synchronized (game().visualEffects()) {
        game()
            .visualEffects()
            .add(
                new UniversalEffect(
                    owner().position(),
                    new RepInstance(part),
                    Petaluridae.standardColors.get(random),
                    UniversalEffect.DEFAULT_COUNT_DOWN,
                    0,
                    Maths.randomAngle(),
                    UniversalEffect.STAND_STILL,
                    UniversalEffect.FADING,
                    UniversalEffect.FIX_SCALE));
      }
    }
  }
Exemple #11
0
 public Pointt miniPosition() {
   return position.realToMini();
 }
Exemple #12
0
 public Pointt displayPosition(Pointt focus) {
   return position.realToDisplay(focus);
 }
Exemple #13
0
 public double distance(Units otherUnit) {
   return position.distance(otherUnit.position);
 }
Exemple #14
0
  /** Movement given no collision */
  public synchronized void moveNoCollision(double time) {
    if (time <= 0) {
      throw new InvalidParameterException("Cannot move the unit, time <= 0!");
    }

    if (Double.isNaN(time)) {
      throw new RuntimeException(
          "time is NaN. speed is " + speed + "  moving angle is " + movingAngle);
    }

    // Check if the unit is facing the required direction
    if (movingAngle == finalAngle) { // Already facing that direction
      if (this.destination != null) {
        if (speed * time >= position.distance(destination)) {
          xVelocity = 0;
          yVelocity = 0;
          position = destination;
          return;
        }
      }

      xVelocity = speed * Math.cos(movingAngle);
      yVelocity = speed * Math.sin(movingAngle);

      position.setX(Geometry.fixX(position.getX() + xVelocity * time));
      position.setY(Geometry.fixY(position.getY() + yVelocity * time));

    } else { // Need to turn to that direction
      double distance = finalAngle - movingAngle;
      double alternative = -(2 * Math.PI - finalAngle + movingAngle);

      if (distance < 0) {
        while (alternative <= -Math.PI) {
          alternative += 2 * Math.PI;
        }
      } else {
        while (alternative >= Math.PI) {
          alternative -= 2 * Math.PI;
        }
      }

      double angularDisplacement;
      if (Math.abs(distance) < Math.abs(alternative)) {
        angularDisplacement = distance;
      } else {
        angularDisplacement = alternative;
      }

      if (angularSpeed * time < Math.abs(angularDisplacement)) { // Does not finish turning
        movingAngle +=
            ((angularDisplacement) / Math.abs(angularDisplacement)) * angularSpeed * time;
        xVelocity = 0;
        yVelocity = 0;
      } else { // Finish turning with extra or no time left
        movingAngle = finalAngle;

        if (Double.isNaN(angularSpeed)) {
          throw new RuntimeException(
              "Angular speed is NaN. angulardisplacement is " + angularDisplacement);
        }

        if (Double.isInfinite(angularSpeed)) {
          throw new RuntimeException(
              "Angular speed is isInfinite. angulardisplacement is " + angularDisplacement);
        }

        if (Double.isNaN(angularDisplacement)) {
          throw new RuntimeException("angularDisplacement is NaN. angularSpeed is " + angularSpeed);
        }

        if (Double.isNaN(time - Math.abs(angularDisplacement) / angularSpeed)) {
          throw new RuntimeException(
              "Next input is NaN. angularSpeed is "
                  + angularSpeed
                  + " angularDisplacement is "
                  + angularDisplacement
                  + "time is "
                  + time);
        }

        moveNoCollision(time - Math.abs(angularDisplacement) / angularSpeed);
      }
    }
  }