Skip to content

Instantly share code, notes, and snippets.

@saucecode
Created February 22, 2015 05:25
Show Gist options
  • Save saucecode/450b271bca13ece8dbef to your computer and use it in GitHub Desktop.
Save saucecode/450b271bca13ece8dbef to your computer and use it in GitHub Desktop.
private boolean canSee(float x, float y) {
float delta = 0.1f;
float targetDistance = (float) Math.hypot(x-this.x, y-this.y);
float angle = (float) (game.calcAngle(this.x, this.y, x, y) - Math.PI/2f);
float dx = (float) Math.sin(angle) * delta;
float dy = (float) -Math.cos(angle) * delta;
float mx = this.x, my = this.y;
for(float distance=0; distance < targetDistance; distance+=delta){
mx += dx;
my += dy;
if(!game.placeFree(mx, my)){
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment