Skip to content

Instantly share code, notes, and snippets.

@technoAl
Created March 1, 2021 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technoAl/459c1f8b4b8998fd43a028c549a36ec0 to your computer and use it in GitHub Desktop.
Save technoAl/459c1f8b4b8998fd43a028c549a36ec0 to your computer and use it in GitHub Desktop.
public class Platform {
int x, y, width, height;
public boolean isColliding(Player player){
int distanceX = Math.abs(player.getX() - this.x);
int distanceY = Math.abs(player.getY() - this.y);
int widthSum = this.width / 2 + player.getWidth() / 2;
int heightSum = this.height / 2 + player.getHeight() / 2;
return distanceX < widthSum && distanceY < heightSum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment