@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); }
@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)); } } }