Created
February 22, 2015 05:25
-
-
Save saucecode/450b271bca13ece8dbef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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