Working on AI behaviors

This commit is contained in:
2014-06-15 22:22:17 -07:00
parent df3808351b
commit ede06c1a28

View File

@@ -923,14 +923,13 @@ var AISprite = function(game, x, y, key, frame) {
} }
} }
if ( hasState(this, STATE_ALERTED) ) { if ( hasState(this, STATE_ALERTED) ) {
if ( this.sprite_group == "townsfolk-guard" ) { if ( this.sprite_group == "townsfolk-guard" ) {
this.action_chaseplayer(); this.action_chaseplayer();
} else { } else {
this.action_reportplayer(); this.action_reportplayer();
} }
} else if ( hasState(this, (STATE_CONCERNED | STATE_LOSTHIM)) ) { } else if ( hasAnyState(this, [STATE_CONCERNED, STATE_LOSTHIM]) ) {
this.action_huntplayer(); this.action_huntplayer();
} else { } else {
this.action_wander(); this.action_wander();
@@ -1199,6 +1198,16 @@ function exchangeState(spr, state1, state2)
addState(spr, state2); addState(spr, state2);
} }
function hasAnyState(spr, states)
{
var hasstate = false;
states.forEach(function(x) {
if ( hasState(spr, x) )
hasstate = true;
}, this);
return hasstate;
}
function hasState(spr, state) function hasState(spr, state)
{ {
if ( (spr.state & state) == state ) if ( (spr.state & state) == state )