From 93bb2d0893eb243970b8865fcd960037006d585b Mon Sep 17 00:00:00 2001 From: Jayant Jain Date: Sat, 15 Mar 2014 20:28:26 +0530 Subject: [PATCH] Restricts wizard to level bounds when moving around --- app/lib/surface/WizardSprite.coffee | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/lib/surface/WizardSprite.coffee b/app/lib/surface/WizardSprite.coffee index 58eec1dc7..cf07adc68 100644 --- a/app/lib/surface/WizardSprite.coffee +++ b/app/lib/surface/WizardSprite.coffee @@ -120,11 +120,20 @@ module.exports = class WizardSprite extends IndieSprite @shoveOtherWizards(true) if @targetSprite @targetSprite = if isSprite then newTarget else null - @targetPos = targetPos + @targetPos = @boundWizard targetPos @beginMoveTween(duration, isLinear) @shoveOtherWizards() Backbone.Mediator.publish('self-wizard:target-changed', {sender:@}) if @isSelf + boundWizard: (target) -> + # Passed an {x, y} in world coordinates, returns {x, y} within world bounds + return target unless @options.camera.bounds + @bounds = @options.camera.bounds + surfaceTarget = @options.camera.worldToSurface target + x = Math.min(Math.max(surfaceTarget.x, @bounds.x), @bounds.x + @bounds.width) + y = Math.min(Math.max(surfaceTarget.y, @bounds.y), @bounds.y + @bounds.height) + return @options.camera.surfaceToWorld {x: x, y: y} + getPosFromTarget: (target) -> """ Could be null, a vector, or sprite object. Get the position from any of these.