Ejemplo n.º 1
0
  /**
   * Permet au boss de se déplacer
   *
   * @param delta La durée d'une ittération
   */
  @Override
  public void update(int delta) {
    if (player.getX() < this.x + aggroRange
        && player.getX() > this.x - aggroRange
        && player.getY() < this.y + aggroRange
        && player.getY() > this.y - aggroRange) {
      moving = true;
      aggro = true;
    }
    if (moving && knockbackTimer <= 0 && !attaquing) {
      int relativeX = Math.abs((int) this.x - (int) player.getX()),
          relativeY = Math.abs((int) this.y - (int) player.getY());
      if (this.x < player.getX() && relativeX > relativeY) {
        this.direction = 3;
      } else if (this.x > player.getX() && relativeX > relativeY) {
        this.direction = 1;
      } else if (this.y < player.getY() && relativeY > relativeX) {
        this.direction = 2;
      } else if (this.y > player.getY() && relativeY > relativeX) {
        this.direction = 0;
      }
      if (!map.isCollision(futurX(delta), futurY(delta))) {
        this.x = futurX(delta);
        this.y = futurY(delta);
      }
      this.attack();
    } else if (knockbackTimer > 0) {
      moving = true;
      float tempSpeed = speed;
      speed = 0.5f;
      if (!map.isCollision(futurX(-delta), futurY(-delta))) {
        this.x = futurX(-delta);
        this.y = futurY(-delta);
      }
      speed = tempSpeed;
      knockbackTimer -= delta;

    } else if (attCounter > 0 && attaquing) {
      attCounter -= delta;
      if (attCounter <= 0) {
        attaquing = false;
        xOff = -16;
        yOff = -60;
        hitBox = new Box(x + xOff, y + yOff, 32, 60);
      }
    }
    if (attCooldown > 0) {
      attCooldown -= delta;
    }
    hitBox.setPos(x + xOff, y + yOff);
  }
Ejemplo n.º 2
0
 /** L'animation d'attaque du boss */
 public void attack() {
   boolean isInRange = false;
   switch (direction) {
     case 0:
       if (player.getX() > this.x - 32
           && player.getX() < this.x + 32
           && player.getY() > this.y - 128
           && player.getY() < this.y - 64) {
         isInRange = true;
       }
       break;
     case 1:
       if (player.getX() > this.x - 96
           && player.getX() < this.x - 32
           && player.getY() > this.y - 64
           && player.getY() < this.y) {
         isInRange = true;
       }
       break;
     case 2:
       if (player.getX() > this.x - 32
           && player.getX() < this.x + 32
           && player.getY() > this.y
           && player.getY() < this.y + 64) {
         isInRange = true;
       }
       break;
     case 3:
       if (player.getX() < this.x + 96
           && player.getX() > this.x + 32
           && player.getY() > this.y - 64
           && player.getY() < this.y) {
         isInRange = true;
       }
       break;
   }
   if (isInRange && attCooldown <= 0) {
     attaquing = true;
     attCooldown = 1000;
     attCounter = 500;
     for (int i = 0; i < attackAnimation.length; i++) {
       attackAnimation[i].restart();
     }
     switch (direction) {
       case 0:
         yOff = -124;
         hitBox = new Box(x + xOff, y + yOff, 32, 128);
         break;
       case 1:
         xOff = -76;
         hitBox = new Box(x + xOff, y + yOff, 96, 60);
         break;
       case 2:
         hitBox = new Box(+xOff, y + yOff, 32, 128);
         break;
       case 3:
         hitBox = new Box(+xOff, y + yOff, 96, 60);
         break;
     }
   }
 }