Beispiel #1
0
  /**
   * Set the target location for the player.<br>
   * Here we will also determine the animation for the player to be facing the target.<br>
   * We will also assign the velocity
   *
   * @param targetCol Target column
   * @param targetRow Target row
   */
  public void setTarget(final double targetCol, final double targetRow) {
    // assign the target
    this.targetCol = targetCol;
    this.targetRow = targetRow;

    // stop moving
    super.setDX(VELOCITY_NONE);
    super.setDY(VELOCITY_NONE);

    // here we will set the velocity
    if (targetCol > getCol()) {
      super.setDX(getVelocityLimit());
      super.setDY(VELOCITY_NONE);
    } else if (targetCol < getCol()) {
      super.setDX(-getVelocityLimit());
      super.setDY(VELOCITY_NONE);
    } else if (targetRow > getRow()) {
      super.setDX(VELOCITY_NONE);
      super.setDY(getVelocityLimit());
    } else if (targetRow < getRow()) {
      super.setDX(VELOCITY_NONE);
      super.setDY(-getVelocityLimit());
    }

    // here we will set the animation
    PlayerHelper.assignWalkAnimation(this);
  }
Beispiel #2
0
  public Player(final Game game, final boolean human) {
    super();

    // store our reference object
    this.game = game;

    // assign human status
    this.human = human;

    // setup the animations
    PlayerHelper.setupAnimations(this);

    // set the default
    setVelocityLimit(VELOCITY_DEFAULT);
  }
Beispiel #3
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));
      }
    }
  }