Merge pull request #73 from TomSteinbrecher/master

Completed #48: Adds bobbing to thangs with 'bobs' property.
This commit is contained in:
Nick Winter 2014-01-04 22:09:09 -08:00
commit b9531c7c02
2 changed files with 9 additions and 6 deletions

View file

@ -52,9 +52,10 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
'level-sprite-dialogue': 'onDialogue'
'level-sprite-clear-dialogue': 'onClearDialogue'
'level-set-letterbox': 'onSetLetterbox'
'surface:ticked': 'onSurfaceTicked'
constructor: (@thangType, options) ->
super()
super()
@options = _.extend(_.cloneDeep(@options), options)
@setThang @options.thang
console.error @toString(), "has no ThangType!" unless @thangType
@ -63,6 +64,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@labels = {}
@actions = @thangType.getActions()
@buildFromSpriteSheet @buildSpriteSheet()
@ticker = 0
destroy: ->
super()
@ -112,6 +114,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@playNextAction()
onActionEnd: (e) => @playNextAction()
onSurfaceTicked: -> @ticker += 1
playNextAction: ->
@playAction(@actionQueue.splice(0,1)[0]) if @actionQueue.length
@ -147,6 +150,8 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
updatePosition: ->
return unless @thang?.pos and @options.camera?
if @thang.bobHeight
@thang.pos.z = @thang.pos.z + (Math.sin @ticker / @thang.bobTime) * 0.1 * @thang.bobHeight
[p0, p1] = [@lastPos, @thang.pos]
return if p0 and p0.x is p1.x and p0.y is p1.y and p0.z is p1.z and not @options.camera.tweeningZoomTo
wop = x: p1.x, y: p1.y, z: if @thang.isLand then 0 else p1.z - @thang.depth / 2
@ -422,4 +427,4 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
name = AudioPlayer.nameForSoundReference sound
instance = createjs.Sound.play name, "none", delay, 0, 0, volume
#console.log @thang?.id, "played sound", name, "with delay", delay, "volume", volume, "and got sound instance", instance
instance
instance

View file

@ -21,8 +21,7 @@ module.exports = class WizardSprite extends IndieSprite
subscriptions:
'bus:player-states-changed': 'onPlayerStatesChanged'
'me:synced': 'onMeSynced'
'surface:sprite-selected': 'onSpriteSelected'
'surface:ticked': 'onSurfaceTicked'
'surface:sprite-selected': 'onSpriteSelected'
'echo-self-wizard-sprite': 'onEchoSelfWizardSprite'
'echo-all-wizard-sprites': 'onEchoAllWizardSprites'
@ -102,8 +101,7 @@ module.exports = class WizardSprite extends IndieSprite
onEchoSelfWizardSprite: (e) -> e.payload = @ if @isSelf
onEchoAllWizardSprites: (e) -> e.payload.push @
defaultPos: -> x: 35, y: 24, z: @thang.depth / 2 + @spriteZOffset
getZOffset: -> @thang.depth / 2 + @spriteZOffset + Math.sin @ticker / 20 # Cloud bobbing.
onSurfaceTicked: -> @ticker += 1
getZOffset: -> @thang.depth / 2 + @spriteZOffset + Math.sin @ticker / 20 # Cloud bobbing.
move: (pos, duration) -> @setTarget(pos, duration)
setTarget: (newTarget, duration) ->