Use key.isPressed() to get movement direction

This commit is contained in:
Muhammed Thanish 2014-03-02 03:27:06 +05:30
parent a092557973
commit d7e031fd00
2 changed files with 17 additions and 17 deletions
app
lib/surface
views/play/level

View file

@ -231,7 +231,8 @@ module.exports = class WizardSprite extends IndieSprite
super() if @displayObject.visible # not if we hid the wiz
moveWizard : (x, y) =>
interval = 250
position = {x: @targetPos.x+x, y: @targetPos.y+y}
@setTarget(position, 500, true)
@setTarget(position, interval, true)
@updatePosition()
Backbone.Mediator.publish 'camera-zoom-to', position, 500
Backbone.Mediator.publish 'camera-zoom-to', position, interval

View file

@ -36,10 +36,10 @@ module.exports = class PlaybackView extends View
'⌘+p, p, ctrl+p': 'onTogglePlay'
'⌘+[, ctrl+[': 'onScrubBack'
'⌘+], ctrl+]': 'onScrubForward'
'w, up': 'onMoveUpKey'
's, down': 'onMoveDownKey'
'a, left': 'onMoveLeftKey'
'd, right': 'onMoveRightKey'
'up': 'onMoveKey'
'down': 'onMoveKey'
'left': 'onMoveKey'
'right': 'onMoveKey'
constructor: ->
super(arguments...)
@ -220,14 +220,13 @@ module.exports = class PlaybackView extends View
@onWindowResize = null
super()
onMoveUpKey: ->
Backbone.Mediator.publish 'self-wizard:move', 0, 1
onMoveDownKey: ->
Backbone.Mediator.publish 'self-wizard:move', 0, -1
onMoveLeftKey: ->
Backbone.Mediator.publish 'self-wizard:move', -1, 0
onMoveRightKey: ->
Backbone.Mediator.publish 'self-wizard:move', 1, 0
onMoveKey: (e) ->
e?.preventDefault()
x = 0
y = 0
y = 1 if key.isPressed('up')
y = -1 if key.isPressed('down')
x = 1 if key.isPressed('right')
x = -1 if key.isPressed('left')
console.log 'onMoveKey', x, y
Backbone.Mediator.publish 'self-wizard:move', x, y