Making townsfolk report you to a guard

This commit is contained in:
2014-06-19 20:47:28 -07:00
parent 4f82b0f673
commit eea3dfd07a

View File

@@ -20,6 +20,8 @@ STATE_FACE_UP = 1 << 8;
STATE_FACE_DOWN = 1 << 9; STATE_FACE_DOWN = 1 << 9;
STATE_MOVING = 1 << 10; STATE_MOVING = 1 << 10;
STATE_RUNNINGTOLIGHT = 1 << 11;
STATES_AWARENESS = (STATE_UNAWARE | STATE_CONCERNED | STATE_ALERTED | STATE_LOSTHIM); STATES_AWARENESS = (STATE_UNAWARE | STATE_CONCERNED | STATE_ALERTED | STATE_LOSTHIM);
STATES_MOVEMENT = (STATE_MOVING | STATE_RUNNING); STATES_MOVEMENT = (STATE_MOVING | STATE_RUNNING);
STATES_FACE = (STATE_FACE_LEFT | STATE_FACE_RIGHT | STATE_FACE_DOWN | STATE_FACE_UP); STATES_FACE = (STATE_FACE_LEFT | STATE_FACE_RIGHT | STATE_FACE_DOWN | STATE_FACE_UP);
@@ -1059,15 +1061,20 @@ var AISprite = function(game, x, y, key, frame) {
this.target = nearestInGroup(this, aiSprites, "townsfolk-guard"); this.target = nearestInGroup(this, aiSprites, "townsfolk-guard");
} }
if ( this.target !== null ) { if ( this.target !== null ) {
if ( this.target.canSeeSprite(this) == true || if ( (this.target.canSeeSprite(this) == true) ||
game.physics.arcade.collide(this, this.target) == true ) { (game.physics.arcade.collide(this, this.target) == true) ) {
console.log("My target can see me!"); if ( hasState(this, STATE_RUNNINGTOLIGHT) == true ) {
this.path_tween_stop(); return;
this.path_purge(); } else {
var staticLights = game.state.states.game.staticLights; console.log("My target can see me!");
this.target = nearestInGroup(this, staticLights); this.path_tween_stop();
console.log("Running to the nearest light"); this.path_purge();
console.log(this.target); 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);
}
} }
this.chasetarget(this.target, this.chasetarget(this.target,
STATE_ALERTED, STATE_ALERTED,