Use WizardSprite

This commit is contained in:
Muhammed Thanish 2014-03-02 01:45:49 +05:30
parent 8cc8103288
commit 7ea9260322
4 changed files with 18 additions and 22 deletions

View file

@ -22,7 +22,6 @@ module.exports = class LevelBus extends Bus
'level-show-victory': 'onVictory' 'level-show-victory': 'onVictory'
'tome:spell-changed': 'onSpellChanged' 'tome:spell-changed': 'onSpellChanged'
'tome:spell-created': 'onSpellCreated' 'tome:spell-created': 'onSpellCreated'
'self-wizard:move': 'moveWizard'
constructor: -> constructor: ->
super(arguments...) super(arguments...)
@ -241,12 +240,3 @@ module.exports = class LevelBus extends Bus
destroy: -> destroy: ->
@session.off 'change:multiplayer', @onMultiplayerChanged, @ @session.off 'change:multiplayer', @onMultiplayerChanged, @
super() super()
moveWizard : (x, y) =>
wizardSprite = @getSelfWizard()
position = wizardSprite.getCurrentPosition()
position.x += x
position.y += y
wizardSprite.setTarget(position,1000)
wizardSprite.updatePosition()
Backbone.Mediator.publish 'camera-zoom-to', position

View file

@ -42,7 +42,6 @@ module.exports = class Camera extends CocoClass
'level:restarted': 'onLevelRestarted' 'level:restarted': 'onLevelRestarted'
'sprite:mouse-down': 'onMouseDown' 'sprite:mouse-down': 'onMouseDown'
'sprite:dragged': 'onMouseDragged' 'sprite:dragged': 'onMouseDragged'
'camera-zoom-to': 'onZoomTo'
# TODO: Fix tests to not use mainLayer # TODO: Fix tests to not use mainLayer
constructor: (@canvasWidth, @canvasHeight, angle=Math.asin(0.75), hFOV=d2r(30)) -> constructor: (@canvasWidth, @canvasHeight, angle=Math.asin(0.75), hFOV=d2r(30)) ->
@ -309,6 +308,3 @@ module.exports = class Camera extends CocoClass
createjs.Tween.removeTweens @ createjs.Tween.removeTweens @
@finishTween = null @finishTween = null
super() super()
onZoomTo: (pos) ->
@zoomTo(@worldToSurface(pos), @zoom)

View file

@ -21,6 +21,7 @@ module.exports = class WizardSprite extends IndieSprite
'surface:sprite-selected': 'onSpriteSelected' 'surface:sprite-selected': 'onSpriteSelected'
'echo-self-wizard-sprite': 'onEchoSelfWizardSprite' 'echo-self-wizard-sprite': 'onEchoSelfWizardSprite'
'echo-all-wizard-sprites': 'onEchoAllWizardSprites' 'echo-all-wizard-sprites': 'onEchoAllWizardSprites'
'self-wizard:move': 'moveWizard'
constructor: (thangType, options) -> constructor: (thangType, options) ->
if options?.isSelf if options?.isSelf
@ -102,7 +103,7 @@ module.exports = class WizardSprite extends IndieSprite
defaultPos: -> x: 35, y: 24, z: @thang.depth / 2 + @thang.bobHeight defaultPos: -> x: 35, y: 24, z: @thang.depth / 2 + @thang.bobHeight
move: (pos, duration) -> @setTarget(pos, duration) move: (pos, duration) -> @setTarget(pos, duration)
setTarget: (newTarget, duration) -> setTarget: (newTarget, duration, isLinear=false) ->
# ignore targets you're already heading for # ignore targets you're already heading for
targetPos = @getPosFromTarget(newTarget) targetPos = @getPosFromTarget(newTarget)
return if @targetPos and @targetPos.x is targetPos.x and @targetPos.y is targetPos.y return if @targetPos and @targetPos.x is targetPos.x and @targetPos.y is targetPos.y
@ -115,7 +116,7 @@ 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 = targetPos
@beginMoveTween(duration) @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
@ -127,7 +128,7 @@ module.exports = class WizardSprite extends IndieSprite
return target if target.x? return target if target.x?
return target.thang.pos return target.thang.pos
beginMoveTween: (duration=1000) -> beginMoveTween: (duration=1000, isLinear=false) ->
# clear the old tween # clear the old tween
createjs.Tween.removeTweens(@) createjs.Tween.removeTweens(@)
@ -140,8 +141,11 @@ module.exports = class WizardSprite extends IndieSprite
@updatePosition() @updatePosition()
@endMoveTween() @endMoveTween()
return return
if isLinear
ease = createjs.Ease.linear
else
ease = createjs.Ease.getPowInOut(3.0) ease = createjs.Ease.getPowInOut(3.0)
createjs.Tween createjs.Tween
.get(@) .get(@)
.to({tweenPercentage:0.0}, duration, ease) .to({tweenPercentage:0.0}, duration, ease)
@ -225,3 +229,9 @@ module.exports = class WizardSprite extends IndieSprite
updateMarks: -> updateMarks: ->
super() if @displayObject.visible # not if we hid the wiz super() if @displayObject.visible # not if we hid the wiz
moveWizard : (x, y) =>
console.log x, y
position = {x: @targetPos.x+x, y: @targetPos.y+y}
@setTarget(position, 500, true)
@updatePosition()

View file

@ -221,13 +221,13 @@ module.exports = class PlaybackView extends View
super() super()
onMoveUpKey: -> onMoveUpKey: ->
Backbone.Mediator.publish 'self-wizard:move', 0, 10 Backbone.Mediator.publish 'self-wizard:move', 0, 1
onMoveDownKey: -> onMoveDownKey: ->
Backbone.Mediator.publish 'self-wizard:move', 0, -10 Backbone.Mediator.publish 'self-wizard:move', 0, -1
onMoveLeftKey: -> onMoveLeftKey: ->
Backbone.Mediator.publish 'self-wizard:move', -10, 0 Backbone.Mediator.publish 'self-wizard:move', -1, 0
onMoveRightKey: -> onMoveRightKey: ->
Backbone.Mediator.publish 'self-wizard:move', 10, 0 Backbone.Mediator.publish 'self-wizard:move', 1, 0