Exemplo n.º 1
0
  @Override
  public void update() throws Exception {
    // update animation
    super.getSpritesheet().get().update();

    // if there is velocity or we are not at our target column
    if (getDX() != 0 || getDY() != 0 || getCol() != targetCol || getRow() != targetRow) {
      // if we are close enough
      if (super.getDistance(getCol(), getRow(), targetCol, targetRow) <= getVelocityLimit()) {
        // stop moving
        super.setDX(VELOCITY_NONE);
        super.setDY(VELOCITY_NONE);

        // place on the target
        super.setCol(targetCol);
        super.setRow(targetRow);

        // stop animation
        PlayerHelper.stopWalkAnimation(this);
      } else {
        // update (column, row) location based on velocity
        super.setCol(getCol() + getDX());
        super.setRow(getRow() + getDY());
      }
    }

    // if this player does not have focus, we need to update the (x, y)
    if (!hasFocus()) {
      // update the coordinates accordingly
      if (hasIsometric()) {
        // update opponents coordinates, we offset here a little in reference to the human player
        setX(getGame().getLabyrinth().getCoordinateX(getCol() - .75, getRow() - 1.75));
        setY(getGame().getLabyrinth().getCoordinateY(getCol() - .75, getRow() + .5));
      } else {
        // update opponents coordinates
        setX(getGame().getLabyrinth().getCoordinateX(getCol() + .5, getRow() + .5));
        setY(getGame().getLabyrinth().getCoordinateY(getCol() + .5, getRow() + .5));
      }
    }
  }