People keep chasing the guards even after touching the light

This commit is contained in:
2014-06-22 11:51:21 -07:00
parent 1e2424e427
commit e1130e0c84

View File

@@ -380,25 +380,24 @@ var AISprite = function(game, x, y, key, frame) {
this.action_reportplayer = function() this.action_reportplayer = function()
{ {
if ( (this.path.length < 1) || this.path_index >= this.path.length) { if ( (this.path.length < 1) || this.path_index >= this.path.length) {
if ( hasState(this, STATE_RUNNINGTOLIGHT) == false ) { if ( this.target == null &&
hasState(this, STATE_RUNNINGTOLIGHT) == false ) {
var aiSprites = game.state.states.game.aiSprites; var aiSprites = game.state.states.game.aiSprites;
this.target = nearestInGroup(this, aiSprites, "townsfolk-guard"); this.target = nearestInGroup(this, aiSprites, "townsfolk-guard");
} else { } else if ( hasState(this, STATE_RUNNINGTOLIGHT) == false ) {
this.setAwarenessEffect(STATE_RELIEVED);
return;
}
}
if ( this.target !== null &&
hasState(this, STATE_RUNNINGTOLIGHT) == false ) {
if ( (game.physics.arcade.collide(this, this.target) == true) ) {
this.path_tween_stop(); this.path_tween_stop();
this.path_purge(); this.path_purge();
var staticLights = game.state.states.game.staticLights; var staticLights = game.state.states.game.staticLights;
this.target = nearestInGroup(this, staticLights); this.target = nearestInGroup(this, staticLights);
console.log("Running to the nearest light"); console.log("Running to the nearest light");
console.log(this.target); console.log(this.target);
addState(this, STATE_RUNNINGTOLIGHT); addState(this, STATE_RUNNINGTOLIGHT);
} } else {
this.setAwarenessEffect(STATE_RELIEVED);
return;
}
}
if ( this.target !== null ) {
this.chasetarget(this.target, this.chasetarget(this.target,
STATE_ALERTED, STATE_ALERTED,
STATE_MOVING | STATE_RUNNING, STATE_MOVING | STATE_RUNNING,