Пример #1
0
  public GraphicsAnt(
      GraphicsAntWarsGUI factory,
      IAntInfo antInfo,
      IAntDrawer antDrawer,
      G2D g2d,
      ColorFactory cf) {
    this.factory = factory;
    this.textManager = new VisualManagerImpl<>(true);
    this.antInfo = antInfo;
    this.antDrawer = antDrawer;
    this.g2d = g2d;
    this.cf = cf;
    DoubleInterpolator di = new DoubleInterpolator();
    xCtrl = new LinearChaserImpl<>(di, 1.0);
    yCtrl = new LinearChaserImpl<>(di, 1.0);
    directionCtrl = new LinearChaserImpl<>(new DoubleCircularInterpolation(4), 0.25);

    xCtrl.setCurrent((double) antInfo.getLocation().getX());
    yCtrl.setCurrent((double) antInfo.getLocation().getY());
    directionCtrl.setCurrent((double) antInfo.getDirection());

    xCtrl.setGoal((double) antInfo.getLocation().getX());
    yCtrl.setGoal((double) antInfo.getLocation().getY());
    directionCtrl.setGoal((double) antInfo.getDirection());
  }
Пример #2
0
  private synchronized void shake() {
    directionCtrl.setGoal(antInfo.getDirection() + 0.1);
    directionCtrl.setDuration(turnDuration * 0.1);
    waitFor(directionCtrl);

    if (antInfo.getDirection() > 0) {
      directionCtrl.setGoal(antInfo.getDirection() - 0.1);
    } else {
      directionCtrl.setGoal(3.9);
    }
    directionCtrl.setDuration(turnDuration * 0.1);
    waitFor(directionCtrl);

    directionCtrl.setGoal((double) antInfo.getDirection());
    directionCtrl.setDuration(turnDuration * 0.1);
    waitFor(directionCtrl);
  }
Пример #3
0
  @Override
  public synchronized void playAttackAnimation(int damage) {
    switch (antInfo.getDirection()) {
      case 0:
        {
          yCtrl.setGoal((double) antInfo.getLocation().getY() + 0.5f);
          yCtrl.setDuration(attackDuration);
          waitFor(yCtrl);

          yCtrl.setGoal((double) antInfo.getLocation().getY());
          yCtrl.setDuration(attackDuration);
          waitFor(yCtrl);
          break;
        }
      case 1:
        {
          xCtrl.setGoal((double) antInfo.getLocation().getX() + 0.5f);
          xCtrl.setDuration(attackDuration);
          waitFor(xCtrl);

          xCtrl.setGoal((double) antInfo.getLocation().getX());
          xCtrl.setDuration(attackDuration);
          waitFor(xCtrl);
          break;
        }
      case 2:
        {
          yCtrl.setGoal((double) antInfo.getLocation().getY() - 0.5f);
          yCtrl.setDuration(attackDuration);
          waitFor(yCtrl);

          yCtrl.setGoal((double) antInfo.getLocation().getY());
          yCtrl.setDuration(attackDuration);
          waitFor(yCtrl);
          break;
        }
      case 3:
        xCtrl.setGoal((double) antInfo.getLocation().getX() - 0.5f);
        xCtrl.setDuration(attackDuration);
        waitFor(xCtrl);

        xCtrl.setGoal((double) antInfo.getLocation().getX());
        xCtrl.setDuration(attackDuration);
        waitFor(xCtrl);
        break;
    }
  }
Пример #4
0
 private synchronized void doMove() {
   switch (antInfo.getDirection()) {
     case 0:
     case 2:
       {
         yCtrl.setGoal((double) antInfo.getLocation().getY());
         yCtrl.setDuration(moveDuration);
         waitFor(yCtrl);
         break;
       }
     case 1:
     case 3:
       {
         xCtrl.setGoal((double) antInfo.getLocation().getX());
         xCtrl.setDuration(moveDuration);
         waitFor(xCtrl);
         break;
       }
   }
 }
Пример #5
0
 private synchronized void doTurn() {
   directionCtrl.setGoal((double) antInfo.getDirection());
   directionCtrl.setDuration(turnDuration);
   waitFor(directionCtrl);
 }
Пример #6
0
 @Override
 public synchronized boolean isFinished() {
   return antInfo.isDead();
 }