Restricts wizard to level bounds when moving around

This commit is contained in:
Jayant Jain 2014-03-15 20:28:26 +05:30
parent 91515b1cea
commit 93bb2d0893

View file

@ -120,11 +120,20 @@ module.exports = class WizardSprite extends IndieSprite
@shoveOtherWizards(true) if @targetSprite @shoveOtherWizards(true) if @targetSprite
@targetSprite = if isSprite then newTarget else null @targetSprite = if isSprite then newTarget else null
@targetPos = targetPos @targetPos = @boundWizard targetPos
@beginMoveTween(duration, isLinear) @beginMoveTween(duration, isLinear)
@shoveOtherWizards() @shoveOtherWizards()
Backbone.Mediator.publish('self-wizard:target-changed', {sender:@}) if @isSelf 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) -> getPosFromTarget: (target) ->
""" """
Could be null, a vector, or sprite object. Get the position from any of these. Could be null, a vector, or sprite object. Get the position from any of these.