Close #54 : AI now resume paths after colliding with each other

This commit is contained in:
2014-07-11 08:36:13 -07:00
parent a8d33e956d
commit b3b3370dbe
3 changed files with 29 additions and 4 deletions

View File

@@ -76,7 +76,7 @@ var AISprite = function(game, x, y, key, frame) {
this.awareness_change_enabled = true; this.awareness_change_enabled = true;
} }
this.enableAwarenessChange = function(state) { this.enableConversation = function(state) {
delState(this, STATE_CONVERSATION_DISABLED); delState(this, STATE_CONVERSATION_DISABLED);
} }
@@ -85,12 +85,30 @@ var AISprite = function(game, x, y, key, frame) {
if ( isSet(this.conversation_timer) ) if ( isSet(this.conversation_timer) )
this.conversation_timer.stop(); this.conversation_timer.stop();
this.conversation_timer = game.time.create(false); this.conversation_timer = game.time.create(false);
this.conversation_timer.add(this.sprite_conversation_duration, this.conversation_timer.add(30000,
this.enableConversationChange, this.enableConversation,
this); this);
this.conversation_timer.start() this.conversation_timer.start()
} }
this.enableCollision = function()
{
delState(this, STATE_COLLISION_DISABLED);
}
this.startCollisionTimer = function(duration)
{
duration = (typeof duration == 'undefined' ? 5000 : duration);
addState(this, STATE_COLLISION_DISABLED);
if ( isSet(this.collision_timer) )
this.collision_timer.stop();
this.collision_timer = game.time.create(false);
this.collision_timer.add(duration,
this.enableCollision,
this);
this.collision_timer.start()
}
this.startAwarenessTimer = function() { this.startAwarenessTimer = function() {
this.awareness_change_enabled = false; this.awareness_change_enabled = false;
if ( isSet(this.awareness_timer) ) if ( isSet(this.awareness_timer) )
@@ -685,7 +703,7 @@ var AISprite = function(game, x, y, key, frame) {
this.collide_with_AI = function(spr) this.collide_with_AI = function(spr)
{ {
if ( spr == this ) if ( spr == this || hasState(this, STATE_COLLISION_DISABLED) == true )
return; return;
this.path_tween_stop(); this.path_tween_stop();
@@ -708,6 +726,9 @@ var AISprite = function(game, x, y, key, frame) {
spr.path_purge(); spr.path_purge();
addState(spr, STATE_CONVERSING); addState(spr, STATE_CONVERSING);
setMovingState(spr, getFaceState(spr)); setMovingState(spr, getFaceState(spr));
} else {
this.startCollisionTimer();
spr.startCollisionTimer();
} }
} }

View File

@@ -41,6 +41,8 @@ STATE_CONVERSING = 1 << 14;
STATE_CONVERSING_YOURTURN = 1 << 15; STATE_CONVERSING_YOURTURN = 1 << 15;
STATE_CONVERSATION_DISABLED = 1 << 16; STATE_CONVERSATION_DISABLED = 1 << 16;
STATE_COLLISION_DISABLED = 1 << 17;
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);

View File

@@ -400,6 +400,8 @@ function purgeConversation(obj1, obj2)
obj2.clearWordBubble(); obj2.clearWordBubble();
obj1.startConversationTimer(); obj1.startConversationTimer();
obj2.startConversationTimer(); obj2.startConversationTimer();
obj1.startCollisionTimer();
obj2.startCollisionTimer();
} }
function setConversation(obj1, obj2) function setConversation(obj1, obj2)