Add keyboard shortcuts to move the wizard
This commit is contained in:
parent
7855ca02d8
commit
8cc8103288
3 changed files with 35 additions and 5 deletions
app
|
@ -22,6 +22,7 @@ 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...)
|
||||||
|
@ -240,3 +241,12 @@ 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
|
||||||
|
|
|
@ -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) ->
|
||||||
|
@zoomTo(@worldToSurface(pos), @zoom)
|
||||||
|
|
|
@ -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'
|
||||||
|
'w, up': 'onMoveUpKey'
|
||||||
|
's, down': 'onMoveDownKey'
|
||||||
|
'a, left': 'onMoveLeftKey'
|
||||||
|
'd, right': 'onMoveRightKey'
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super(arguments...)
|
super(arguments...)
|
||||||
|
@ -215,3 +219,15 @@ module.exports = class PlaybackView extends View
|
||||||
$(window).off('resize', @onWindowResize)
|
$(window).off('resize', @onWindowResize)
|
||||||
@onWindowResize = null
|
@onWindowResize = null
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
onMoveUpKey: ->
|
||||||
|
Backbone.Mediator.publish 'self-wizard:move', 0, 10
|
||||||
|
|
||||||
|
onMoveDownKey: ->
|
||||||
|
Backbone.Mediator.publish 'self-wizard:move', 0, -10
|
||||||
|
|
||||||
|
onMoveLeftKey: ->
|
||||||
|
Backbone.Mediator.publish 'self-wizard:move', -10, 0
|
||||||
|
|
||||||
|
onMoveRightKey: ->
|
||||||
|
Backbone.Mediator.publish 'self-wizard:move', 10, 0
|
||||||
|
|
Reference in a new issue