mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 10:06:08 -05:00
Restricts wizard to level bounds when moving around
This commit is contained in:
parent
91515b1cea
commit
93bb2d0893
1 changed files with 10 additions and 1 deletions
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue