Close #4 : Guard will start hunting for you when they lose you instead of just spinning in place

This commit is contained in:
2014-07-06 14:11:15 -07:00
parent 914536670a
commit 9b4ec3ff92

View File

@@ -98,8 +98,9 @@ var AISprite = function(game, x, y, key, frame) {
} }
} }
this.setAwarenessEffect = function(state) { this.setAwarenessEffect = function(state, force) {
var animkey = ""; var animkey = "";
force = (typeof force == 'undefined' ? false : force);
if ( state == STATE_NONE ) if ( state == STATE_NONE )
return; return;
@@ -110,7 +111,7 @@ var AISprite = function(game, x, y, key, frame) {
return; return;
} else if ( (state == STATE_LOSTHIM) && } else if ( (state == STATE_LOSTHIM) &&
(hasState(this, STATE_ALERTED) == false) && (hasState(this, STATE_ALERTED) == false) &&
(hasState(this, STATE_CONCERNED) == false) ) { (hasState(this, STATE_CONCERNED) == false)) {
return; return;
} }
@@ -407,11 +408,17 @@ var AISprite = function(game, x, y, key, frame) {
this.path_tween_stop(); this.path_tween_stop();
if ( ((visual == true) && (this.canSeeSprite(target, false) == true )) || if ( ((visual == true) && (this.canSeeSprite(target, false) == true )) ||
(visual == false)) { (visual == false)) {
this.setAwarenessEffect(alertedState); this.setAwarenessEffect(alertedState);
this.path_set(target, true, maxsteps, useNearestWalkable); this.path_set(target, true, maxsteps, useNearestWalkable);
this.path_tween_start(movingstate); this.path_tween_start(movingstate);
} else { } else {
if ( ( hasState(this, STATE_ALERTED) == true ) &&
( this.seen_directions.length < 4 ) ) {
this.startTimedRotation(); this.startTimedRotation();
} else if ( hasState(this, STATE_ALERTED) == true ) {
this.action_huntplayer();
}
} }
} else { } else {
if ( this.path_set(target, this.blocked(true), maxsteps, useNearestWalkable) == true ) { if ( this.path_set(target, this.blocked(true), maxsteps, useNearestWalkable) == true ) {
@@ -513,6 +520,14 @@ var AISprite = function(game, x, y, key, frame) {
return new Phaser.Sprite(game, destx*32, desty*32, null); return new Phaser.Sprite(game, destx*32, desty*32, null);
} }
this.stopTimedRotation = function() {
if ( isSet(this.rotation_timer) == true ) {
this.rotation_timer.stop();
this.rotation_timer = null;
}
this.seen_directions = [];
}
this.startTimedRotation = function() { this.startTimedRotation = function() {
var rotation_times = {}; var rotation_times = {};
rotation_times["" + STATE_UNAWARE] = 5000; rotation_times["" + STATE_UNAWARE] = 5000;