Exemplo n.º 1
0
 public void attackEnemy() {
   if (targetGrunt != null) {
     float speed = this.getJogSpeed();
     if (this.getPosBox().getX() < (targetGrunt.getPosBox().getX() - this.getAttackDistance())) {
       this.getPosBox().setX(this.getPosBox().getX() + speed);
     } else if (this.getPosBox().getX()
         > (targetGrunt.getPosBox().getX() + this.getAttackDistance())) {
       this.getPosBox().setX(this.getPosBox().getX() - speed);
     } else {
       // Within attacking distance
       if (targetGrunt != null) {
         targetGrunt.setHp(targetGrunt.getHp() - this.getAtk());
       }
       if (targetGrunt.getHp() <= 0) {
         targetGrunt = null;
         STATE state = currentState;
         currentState = prevState;
         prevState = state;
       }
     }
   } else {
     STATE state = currentState;
     currentState = prevState;
     prevState = state;
   }
 }
Exemplo n.º 2
0
  @Override
  public void update(long currentFrame) {

    // Check for moving
    if (!_myState.moving) {
      // Check for destroy
      if (_animation.isStopped()) {
        _level.getLogicManager().detachLogic(this);
      }

      return;
    }

    super.update(currentFrame);

    // Check for squash grunts / spiders
    for (CellLogic cell : _level.getCellManager().getCollisionsWith(this, 16, currentFrame)) {

      // Check for grunt
      try {
        Grunt grunt = (Grunt) cell;
        grunt.getBehaviour().exit("Squash");
      } catch (Exception e) {
      }

      // Check for spider
      try {
        Spider spider = (Spider) cell;
        spider.squash(currentFrame);
      } catch (Exception e) {
      }
    }
  }
Exemplo n.º 3
0
 public void checkForEnemies() {
   boolean foundSomethingToAttack = false;
   for (Grunt g : Aosa.getGlobal().getGame().getWorld().getGrunts()) {
     if (this.getPosBox().getX() >= g.getPosBox().getX() - this.getSightDistance()
         && this.getPosBox().getX() <= g.getPosBox().getX() + this.getSightDistance()) {
       foundSomethingToAttack = true;
       this.setPrevState(currentState);
       this.setCurrentState(STATE.ATTACKING);
       targetGrunt = g;
       break;
     }
   }
 }