mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-05-02 00:43:34 -04:00
Merge branch 'thanish-move-wizard' of git://github.com/mnmtanish/codecombat
This commit is contained in:
commit
f2f0a993af
3 changed files with 39 additions and 9 deletions
app
|
@ -42,6 +42,7 @@ 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)) ->
|
||||||
|
@ -169,7 +170,7 @@ module.exports = class Camera extends CocoClass
|
||||||
onMouseDown: (e) ->
|
onMouseDown: (e) ->
|
||||||
return if @dragDisabled
|
return if @dragDisabled
|
||||||
@lastPos = {x: e.originalEvent.rawX, y: e.originalEvent.rawY}
|
@lastPos = {x: e.originalEvent.rawX, y: e.originalEvent.rawY}
|
||||||
|
|
||||||
onMouseDragged: (e) ->
|
onMouseDragged: (e) ->
|
||||||
return if @dragDisabled
|
return if @dragDisabled
|
||||||
target = @boundTarget(@target, @zoom)
|
target = @boundTarget(@target, @zoom)
|
||||||
|
@ -180,7 +181,7 @@ module.exports = class Camera extends CocoClass
|
||||||
@zoomTo newPos, @zoom, 0
|
@zoomTo newPos, @zoom, 0
|
||||||
@lastPos = {x: e.originalEvent.rawX, y: e.originalEvent.rawY}
|
@lastPos = {x: e.originalEvent.rawX, y: e.originalEvent.rawY}
|
||||||
Backbone.Mediator.publish 'camera:dragged'
|
Backbone.Mediator.publish 'camera:dragged'
|
||||||
|
|
||||||
onLevelRestarted: ->
|
onLevelRestarted: ->
|
||||||
@setBounds(@firstBounds, false)
|
@setBounds(@firstBounds, false)
|
||||||
|
|
||||||
|
@ -220,7 +221,7 @@ module.exports = class Camera extends CocoClass
|
||||||
newTarget ?= {x:0, y:0}
|
newTarget ?= {x:0, y:0}
|
||||||
newTarget = (@newTarget or @target) if @locked
|
newTarget = (@newTarget or @target) if @locked
|
||||||
newZoom = Math.min((Math.max @minZoom, newZoom), MAX_ZOOM)
|
newZoom = Math.min((Math.max @minZoom, newZoom), MAX_ZOOM)
|
||||||
|
|
||||||
thangType = @target?.sprite?.thangType
|
thangType = @target?.sprite?.thangType
|
||||||
if thangType
|
if thangType
|
||||||
@offset = _.clone(thangType.get('positions')?.torso or {x: 0, y:0})
|
@offset = _.clone(thangType.get('positions')?.torso or {x: 0, y:0})
|
||||||
|
@ -229,7 +230,7 @@ module.exports = class Camera extends CocoClass
|
||||||
@offset.y *= scale
|
@offset.y *= scale
|
||||||
else
|
else
|
||||||
@offset = {x: 0, y:0}
|
@offset = {x: 0, y:0}
|
||||||
|
|
||||||
return if @zoom is newZoom and newTarget is newTarget.x and newTarget.y is newTarget.y
|
return if @zoom is newZoom and newTarget is newTarget.x and newTarget.y is newTarget.y
|
||||||
|
|
||||||
@finishTween(true)
|
@finishTween(true)
|
||||||
|
@ -247,7 +248,7 @@ module.exports = class Camera extends CocoClass
|
||||||
@target = newTarget
|
@target = newTarget
|
||||||
@zoom = newZoom
|
@zoom = newZoom
|
||||||
@updateZoom true
|
@updateZoom true
|
||||||
|
|
||||||
focusedOnSprite: ->
|
focusedOnSprite: ->
|
||||||
return @target?.name
|
return @target?.name
|
||||||
|
|
||||||
|
@ -308,3 +309,6 @@ module.exports = class Camera extends CocoClass
|
||||||
createjs.Tween.removeTweens @
|
createjs.Tween.removeTweens @
|
||||||
@finishTween = null
|
@finishTween = null
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
onZoomTo: (pos, time) ->
|
||||||
|
@zoomTo(@worldToSurface(pos), @zoom, time)
|
||||||
|
|
|
@ -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,10 @@ 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) =>
|
||||||
|
interval = 500
|
||||||
|
position = {x: @targetPos.x+x, y: @targetPos.y+y}
|
||||||
|
@setTarget(position, interval, true)
|
||||||
|
@updatePosition()
|
||||||
|
Backbone.Mediator.publish 'camera-zoom-to', position, interval
|
|
@ -36,6 +36,10 @@ module.exports = class PlaybackView extends View
|
||||||
'⌘+p, p, ctrl+p': 'onTogglePlay'
|
'⌘+p, p, ctrl+p': 'onTogglePlay'
|
||||||
'⌘+[, ctrl+[': 'onScrubBack'
|
'⌘+[, ctrl+[': 'onScrubBack'
|
||||||
'⌘+], ctrl+]': 'onScrubForward'
|
'⌘+], ctrl+]': 'onScrubForward'
|
||||||
|
'up': 'onMoveKey'
|
||||||
|
'down': 'onMoveKey'
|
||||||
|
'left': 'onMoveKey'
|
||||||
|
'right': 'onMoveKey'
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super(arguments...)
|
super(arguments...)
|
||||||
|
@ -215,3 +219,14 @@ module.exports = class PlaybackView extends View
|
||||||
$(window).off('resize', @onWindowResize)
|
$(window).off('resize', @onWindowResize)
|
||||||
@onWindowResize = null
|
@onWindowResize = null
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
onMoveKey: (e) ->
|
||||||
|
e?.preventDefault()
|
||||||
|
yMovement = 0
|
||||||
|
xMovement = 0
|
||||||
|
yMovement += 2 if key.isPressed('up')
|
||||||
|
yMovement -= 2 if key.isPressed('down')
|
||||||
|
xMovement += 2 if key.isPressed('right')
|
||||||
|
xMovement -= 2 if key.isPressed('left')
|
||||||
|
console.log 'onMoveKey', xMovement, yMovement
|
||||||
|
Backbone.Mediator.publish 'self-wizard:move', xMovement, yMovement
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue