From 7eaa027162313f276cd72c3482be95c2d4539895 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Sat, 5 Jul 2014 12:20:33 -0700 Subject: [PATCH] Close #35 : This was resolved by switching from arcade.physics.collide() to arcade.physics.overlap() which provides more reliable results --- moonlight/src/AISprite.js | 19 +++++++++++++++++++ moonlight/src/Dialogue.js | 2 +- moonlight/src/GameStates.js | 8 ++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/moonlight/src/AISprite.js b/moonlight/src/AISprite.js index 34648b6..34ef629 100644 --- a/moonlight/src/AISprite.js +++ b/moonlight/src/AISprite.js @@ -327,6 +327,8 @@ var AISprite = function(game, x, y, key, frame) { this._object.animations.play(getMovingAnimationName(this._object)); }, tween); tween.onComplete.add(function() { + if ( this._object.resetPathOnCollision() == true ) + return; this._object.path_index += 1; setMovingState(this._object, getFaceState(this._object)); this._object.animations.play(getMovingAnimationName(this._object)); @@ -341,6 +343,21 @@ var AISprite = function(game, x, y, key, frame) { this.path_tweens[0].start(); } + this.resetPathOnCollision = function() { + var aiSprites = game.state.states.game.aiSprites; + var hasBeenReset = false; + aiSprites.forEach(function(spr) { + if ( hasBeenReset == true ) + return; + if ( game.physics.arcade.collide(spr, this) ) { + var last = this.path[this.path.length() - 1]; + this.path_tween_stop(); + hasBeenReset = true; + } + }, this); + return hasBeenReset; + } + this.path_tween_stop = function() { this.path_tweens.forEach(function(x) { @@ -570,6 +587,7 @@ var AISprite = function(game, x, y, key, frame) { { if ( this.ready_to_update == false ) return; + if ( isSet(this.awareness_effect) ) { if ( this.awareness_effect.alive == false ) { this.awareness_effect.destroy(); @@ -617,6 +635,7 @@ var AISprite = function(game, x, y, key, frame) { this.animations.destroy(); this.clearWordBubble(); this.state = STATE_UNAWARE; + this.view_distance = parseInt(this.view_distance); this.state_changed_at = new Phaser.Point(this.x, this.y); this.hunt_radius = parseInt(this.hunt_radius); this.sprite_can_see_lightmeter = Number(this.sprite_can_see_lightmeter); diff --git a/moonlight/src/Dialogue.js b/moonlight/src/Dialogue.js index 5401c51..d8d913d 100644 --- a/moonlight/src/Dialogue.js +++ b/moonlight/src/Dialogue.js @@ -269,7 +269,7 @@ var moonlightDialog = { "", "*spit* *cough* *hack* *choke* *gag*", "", - "Wha whats in this pie?! Its awful!", + "Wha... whats in this\npie?! Its awful!", "Oh, its turnip pie. Someone\nstole all my apples." ] }, diff --git a/moonlight/src/GameStates.js b/moonlight/src/GameStates.js index b377cf6..cc624f0 100644 --- a/moonlight/src/GameStates.js +++ b/moonlight/src/GameStates.js @@ -319,7 +319,7 @@ GameState.prototype.update = function() } return; } else { - if ( this.physics.arcade.collide(x, player) ) { + if ( this.physics.arcade.overlap(x, player) ) { x.setAwarenessEffect(STATE_CONCERNED); } else if ( hasState(x, STATE_LOSTHIM) == false ) { x.setAwarenessEffect(STATE_LOSTHIM); @@ -327,7 +327,7 @@ GameState.prototype.update = function() x.setAwarenessEffect(STATE_UNAWARE); } } - if ( this.physics.arcade.collide(x, player) == true ) + if ( this.physics.arcade.overlap(x, player) == true ) x.setAwarenessEffect(STATE_ALERTED); if ( hasState(player, STATE_STEALING) == true && x.sprite_has_treasure == true ) { @@ -353,7 +353,7 @@ GameState.prototype.update = function() break; } } - if ( this.physics.arcade.collide(x, player) == true ) { + if ( this.physics.arcade.overlap(x, player) == true ) { delState(player, STATE_STEALING); x.sprite_has_treasure = false; var stolen = moonlightTreasures[x.sprite_treasure]; @@ -388,7 +388,7 @@ GameState.prototype.update = function() } } - this.effectSprites.forEach(_inner_collide, this); + // this.effectSprites.forEach(_inner_collide, this); this.aiSprites.forEach(_inner_collide, this); this.updateShadowTexture();