From e1130e0c84fc989e0f429b612fecc366888001cb Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Sun, 22 Jun 2014 11:51:21 -0700 Subject: [PATCH] People keep chasing the guards even after touching the light --- moonlight/src/AISprite.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/moonlight/src/AISprite.js b/moonlight/src/AISprite.js index 60d8c29..90060e8 100644 --- a/moonlight/src/AISprite.js +++ b/moonlight/src/AISprite.js @@ -380,25 +380,24 @@ var AISprite = function(game, x, y, key, frame) { this.action_reportplayer = function() { 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; this.target = nearestInGroup(this, aiSprites, "townsfolk-guard"); - } else { - this.setAwarenessEffect(STATE_RELIEVED); - return; - } - } - if ( this.target !== null && - hasState(this, STATE_RUNNINGTOLIGHT) == false ) { - if ( (game.physics.arcade.collide(this, this.target) == true) ) { + } else if ( hasState(this, STATE_RUNNINGTOLIGHT) == false ) { this.path_tween_stop(); this.path_purge(); var staticLights = game.state.states.game.staticLights; this.target = nearestInGroup(this, staticLights); console.log("Running to the nearest light"); 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, STATE_ALERTED, STATE_MOVING | STATE_RUNNING,