public boolean isCollidingVerticallySmallHB(Player player, LandEnemy landEnemy, int amount) { /** * Checks horizontal collision between the player object and any other object the 'Target' with * a smaller hit box * * <p>Params: * * <p>player is the Player object. landEnemy is any of the landEnemy's amount is how much you * want to shrink the hit box by. * * <p>Returns True if it is colliding Returns False if it is not colliding. */ if (player.isAlive()) { if (player.coordinates.getIndentTop(amount) >= landEnemy.coordinates.getIndentTop(amount) && player.coordinates.getIndentTop(amount) <= landEnemy.coordinates.getIndentBottom(amount)) return true; else if (player.coordinates.getIndentBottom(amount) >= landEnemy.coordinates.getIndentTop(amount) && player.coordinates.getIndentBottom(amount) <= landEnemy.coordinates.getIndentBottom(amount)) return true; else if (landEnemy.coordinates.getIndentTop(amount) >= player.coordinates.getIndentTop(amount) && landEnemy.coordinates.getIndentTop(amount) <= player.coordinates.getIndentBottom(amount)) return true; else if (landEnemy.coordinates.getIndentBottom(amount) >= player.coordinates.getIndentTop(amount) && landEnemy.coordinates.getIndentBottom(amount) <= player.coordinates.getIndentBottom(amount)) return true; } return false; }
public boolean isCollidingVertically(Player player, GameObject target) { /** * Checks vertical collision between the player object and any other object the 'Target' * * <p>Params: * * <p>player is the Player object. target is any other object (coin, land enemy) * * <p>Returns True if it is colliding Returns False if it is not colliding. */ if (player.isAlive()) { if (player.coordinates.getTop() >= target.coordinates.getTop() && player.coordinates.getTop() <= target.coordinates.getBottom()) return true; else if (player.coordinates.getBottom() >= target.coordinates.getTop() && player.coordinates.getBottom() <= target.coordinates.getBottom()) return true; else if (target.coordinates.getTop() >= player.coordinates.getTop() && target.coordinates.getTop() <= player.coordinates.getBottom()) return true; else if (target.coordinates.getBottom() >= player.coordinates.getTop() && target.coordinates.getBottom() <= player.coordinates.getBottom()) return true; } return false; }
public void collided(Sprite player, Sprite enemy) { ((Player) player).reduceHealth(damage); enemy.setActive(false); }