From b3b3370dbee77130d200d0e17bb72b247f397f4b Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Fri, 11 Jul 2014 08:36:13 -0700 Subject: [PATCH] Close #54 : AI now resume paths after colliding with each other --- moonlight/src/AISprite.js | 29 +++++++++++++++++++++++++---- moonlight/src/Constants.js | 2 ++ moonlight/src/Util.js | 2 ++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/moonlight/src/AISprite.js b/moonlight/src/AISprite.js index 5ba9854..6542257 100644 --- a/moonlight/src/AISprite.js +++ b/moonlight/src/AISprite.js @@ -76,7 +76,7 @@ var AISprite = function(game, x, y, key, frame) { this.awareness_change_enabled = true; } - this.enableAwarenessChange = function(state) { + this.enableConversation = function(state) { delState(this, STATE_CONVERSATION_DISABLED); } @@ -85,12 +85,30 @@ var AISprite = function(game, x, y, key, frame) { if ( isSet(this.conversation_timer) ) this.conversation_timer.stop(); this.conversation_timer = game.time.create(false); - this.conversation_timer.add(this.sprite_conversation_duration, - this.enableConversationChange, + this.conversation_timer.add(30000, + this.enableConversation, this); 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.awareness_change_enabled = false; if ( isSet(this.awareness_timer) ) @@ -685,7 +703,7 @@ var AISprite = function(game, x, y, key, frame) { this.collide_with_AI = function(spr) { - if ( spr == this ) + if ( spr == this || hasState(this, STATE_COLLISION_DISABLED) == true ) return; this.path_tween_stop(); @@ -708,6 +726,9 @@ var AISprite = function(game, x, y, key, frame) { spr.path_purge(); addState(spr, STATE_CONVERSING); setMovingState(spr, getFaceState(spr)); + } else { + this.startCollisionTimer(); + spr.startCollisionTimer(); } } diff --git a/moonlight/src/Constants.js b/moonlight/src/Constants.js index 80665d6..48bb7e8 100644 --- a/moonlight/src/Constants.js +++ b/moonlight/src/Constants.js @@ -41,6 +41,8 @@ STATE_CONVERSING = 1 << 14; STATE_CONVERSING_YOURTURN = 1 << 15; STATE_CONVERSATION_DISABLED = 1 << 16; +STATE_COLLISION_DISABLED = 1 << 17; + STATES_AWARENESS = (STATE_UNAWARE | STATE_CONCERNED | STATE_ALERTED | STATE_LOSTHIM); STATES_MOVEMENT = (STATE_MOVING | STATE_RUNNING); STATES_FACE = (STATE_FACE_LEFT | STATE_FACE_RIGHT | STATE_FACE_DOWN | STATE_FACE_UP); diff --git a/moonlight/src/Util.js b/moonlight/src/Util.js index 400c7b2..d499a89 100644 --- a/moonlight/src/Util.js +++ b/moonlight/src/Util.js @@ -400,6 +400,8 @@ function purgeConversation(obj1, obj2) obj2.clearWordBubble(); obj1.startConversationTimer(); obj2.startConversationTimer(); + obj1.startCollisionTimer(); + obj2.startCollisionTimer(); } function setConversation(obj1, obj2)