Exemplo n.º 1
0
  @Override
  public void act() {
    alien.normalAnimation.stop();
    if (ripley == null) {
      for (Actor actor : alien.getWorld()) {
        if (actor instanceof Ripley) {
          ripley = (Ripley) actor;
        }
      }
    }
    if (moveUp == null) {
      moveUp = new Move(alien, 1, 0, -1);
    }
    if (moveDown == null) {
      moveDown = new Move(alien, 1, 0, 1);
    }
    if (moveRight == null) {
      moveRight = new Move(alien, 1, 1, 0);
    }
    if (moveLeft == null) {
      moveLeft = new Move(alien, 1, -1, 0);
    }
    if (moveDownRight == null) {
      moveDownRight = new Move(alien, 1, 1, 1);
    }
    if (moveDownLeft == null) {
      moveDownLeft = new Move(alien, 1, -1, 1);
    }
    if (moveUpRight == null) {
      moveUpRight = new Move(alien, 1, 1, -1);
    }
    if (moveUpLeft == null) {
      moveUpLeft = new Move(alien, 1, -1, -1);
    }

    if (movementInterval == 0) {
      i = Math.random();
      movementInterval = 30;
    }
    if (i > 0 && i <= 0.06) {
      moveUp.Execute();
    }

    if (i > 0.06 && i <= 0.12) {
      moveDown.Execute();
    }

    if (i > 0.12 && i <= 0.18) {
      moveRight.Execute();
    }

    if (i > 0.18 && i <= 0.24) {
      moveLeft.Execute();
    }

    if (i > 0.24 && i <= 0.3) {
      moveDownRight.Execute();
    }
    if (i > 0.3 && i <= 0.36) {
      moveDownLeft.Execute();
    }
    if (i > 0.36 && i <= 0.42) {
      moveUpRight.Execute();
    }
    if (i > 0.42 && i <= 0.48) {
      moveUpLeft.Execute();
    }
    if (i > 0.48 && i <= 1) {}

    movementInterval -= 1;

    if (alien.intersects(ripley)) {
      ripley.setHealth(ripley.getHealth() - 1);
    }

    alien.die();
  }
Exemplo n.º 2
0
  public void act() {
    List<Actor> toRemove = new ArrayList<>();
    List<Actor> toAdd = new ArrayList<>();
    // inicializacia
    if (moveUp == null) {
      moveUp = new Move(this, 5, 0, -1);
    }
    if (moveDown == null) {
      moveDown = new Move(this, 5, 0, 1);
    }
    if (moveRight == null) {
      moveRight = new Move(this, 5, 1, 0);
    }
    if (moveLeft == null) {
      moveLeft = new Move(this, 5, -1, 0);
    }
    if (moveDownRight == null) {
      moveDownRight = new Move(this, 5, 1, 1);
    }
    if (moveDownLeft == null) {
      moveDownLeft = new Move(this, 5, -1, 1);
    }
    if (moveUpRight == null) {
      moveUpRight = new Move(this, 5, 1, -1);
    }
    if (moveUpLeft == null) {
      moveUpLeft = new Move(this, 5, -1, -1);
    }

    switch (normalAnimation.getRotation()) {
      case 135:
        moveDownRight.Execute();
        break;
      case 225:
        moveDownLeft.Execute();
        break;
      case 45:
        moveUpRight.Execute();
        break;
      case 315:
        moveUpLeft.Execute();
        break;
      case 0:
        moveUp.Execute();
        break;
      case 180:
        moveDown.Execute();
        break;
      case 90:
        moveRight.Execute();
        break;
      case 270:
        moveLeft.Execute();
        break;
      default:
        break;
    }

    if (getWorld().intersectWithWall(this)) {
      getWorld().removeActor(this);
      SmallExplosion impact = new SmallExplosion();
      impact.setPosition(getX(), getY());
      impact.getAnimation().setDuration(5);
      impact.setTimer(5);
      getWorld().addActor(impact);
      impact.explode();
    }

    for (Actor actor : getWorld()) {
      if (actor instanceof Enemy && this.intersects(actor)) {
        toRemove.add(this);
        SmallExplosion impact = new SmallExplosion();
        impact.setPosition(getX(), getY());
        impact.getAnimation().setDuration(5);
        impact.setTimer(5);
        toAdd.add(impact);
        impact.explode();
        ((AbstractCharacter) actor)
            .setHealth(((AbstractCharacter) actor).getHealth() - getDamage());
      }
    }

    for (Actor actor : toRemove) {
      getWorld().removeActor(actor);
    }

    for (Actor actor : toAdd) {
      getWorld().addActor(actor);
    }
  }