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
  @Override
  public void reset() throws Exception {
    // if the maze exits we will change the location to the start of the maze
    if (getGame().getLabyrinth() != null && getGame().getLabyrinth().getMaze() != null) {
      // assign maze start location as our current
      super.setCol(getGame().getLabyrinth().getMaze().getStart());
      super.setRow(getGame().getLabyrinth().getMaze().getStart());
    } else {
      // we will start at (0, 0)
      super.setCol(0);
      super.setRow(0);
    }

    // the target will be the current location
    setTarget(getCol(), getRow());

    if (hasIsometric()) {
      // set a default animation
      setAnimationKey(AnimationKey.IsometricEastStand);

      // assign the dimension
      setDimensions(DEFAULT_DIMENSION_ISOMETRIC);

      // position player
      super.setX((GamePanel.WIDTH / 2) + (Labyrinth.WIDTH_ISOMETRIC / 2));
      super.setY((GamePanel.HEIGHT / 2) - (Labyrinth.HEIGHT_ISOMETRIC / 4));
    } else {
      // set a default animation
      setAnimationKey(AnimationKey.TopDownEastStand);

      // assign the dimension
      setDimensions(DEFAULT_DIMENSION_TOP_DOWN);

      // position player
      super.setX((GamePanel.WIDTH / 2));
      super.setY((GamePanel.HEIGHT / 2));
    }

    // we will not be moving
    super.setDX(VELOCITY_NONE);
    super.setDY(VELOCITY_NONE);
  }
Beispiel #3
0
  @Override
  public void render(final Canvas canvas) throws Exception {
    // if the location is not on the screen we won't need to render
    if (getX() + getWidth() < 0 || getX() > GamePanel.WIDTH) return;
    if (getY() + getHeight() < 0 || getY() > GamePanel.HEIGHT) return;

    // get location
    final double x = getX();
    final double y = getY();

    // offset location
    super.setX(x - (getWidth() / 2));
    super.setY(y - (getHeight() / 2));

    // render animation
    super.render(canvas);

    // restore location
    super.setX(x);
    super.setY(y);
  }
Beispiel #4
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));
      }
    }
  }
Beispiel #5
0
 /**
  * Set the animation of the player
  *
  * @param key The desired animation
  */
 public final void setAnimationKey(final AnimationKey key) {
   super.getSpritesheet().setKey(key);
 }
Beispiel #6
0
 /**
  * Assign the dimension of the player
  *
  * @param dimension This will be assigned the width/height
  */
 public void setDimensions(final int dimension) {
   super.setWidth(dimension);
   super.setHeight(dimension);
 }