Stop chasing me if you can't see me at the end of your path

This commit is contained in:
2014-06-17 22:43:10 -07:00
parent 9f9b986f9a
commit 73c91367c3

View File

@@ -721,16 +721,20 @@ var AISprite = function(game, x, y, key, frame) {
var hyp = Math.sqrt(Number(xd * xd) + Number(yd * yd));
if ( hyp > this.view_distance ) {
console.log("Player is outside my view distance");
return false;
}
var viewrect = this.viewRectangle();
if ( viewrect == null )
if ( viewrect == null ) {
console.log("I don't have a view rectangle");
return false;
}
var sprrect = new Phaser.Rectangle(spr.x, spr.y, 32, 32);
if ( viewrect.intersects(sprrect) || viewrect.containsRect(sprrect) ) {
return true;
}
console.log("I have a view rectangle but it does not intersect or contain the player");
return false;
}