mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-25 14:04:54 -05:00
Merge pull request #73 from TomSteinbrecher/master
Completed #48: Adds bobbing to thangs with 'bobs' property.
This commit is contained in:
commit
b9531c7c02
2 changed files with 9 additions and 6 deletions
|
@ -52,9 +52,10 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
'level-sprite-dialogue': 'onDialogue'
|
'level-sprite-dialogue': 'onDialogue'
|
||||||
'level-sprite-clear-dialogue': 'onClearDialogue'
|
'level-sprite-clear-dialogue': 'onClearDialogue'
|
||||||
'level-set-letterbox': 'onSetLetterbox'
|
'level-set-letterbox': 'onSetLetterbox'
|
||||||
|
'surface:ticked': 'onSurfaceTicked'
|
||||||
|
|
||||||
constructor: (@thangType, options) ->
|
constructor: (@thangType, options) ->
|
||||||
super()
|
super()
|
||||||
@options = _.extend(_.cloneDeep(@options), options)
|
@options = _.extend(_.cloneDeep(@options), options)
|
||||||
@setThang @options.thang
|
@setThang @options.thang
|
||||||
console.error @toString(), "has no ThangType!" unless @thangType
|
console.error @toString(), "has no ThangType!" unless @thangType
|
||||||
|
@ -63,6 +64,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
@labels = {}
|
@labels = {}
|
||||||
@actions = @thangType.getActions()
|
@actions = @thangType.getActions()
|
||||||
@buildFromSpriteSheet @buildSpriteSheet()
|
@buildFromSpriteSheet @buildSpriteSheet()
|
||||||
|
@ticker = 0
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
super()
|
super()
|
||||||
|
@ -112,6 +114,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
@playNextAction()
|
@playNextAction()
|
||||||
|
|
||||||
onActionEnd: (e) => @playNextAction()
|
onActionEnd: (e) => @playNextAction()
|
||||||
|
onSurfaceTicked: -> @ticker += 1
|
||||||
|
|
||||||
playNextAction: ->
|
playNextAction: ->
|
||||||
@playAction(@actionQueue.splice(0,1)[0]) if @actionQueue.length
|
@playAction(@actionQueue.splice(0,1)[0]) if @actionQueue.length
|
||||||
|
@ -147,6 +150,8 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
|
|
||||||
updatePosition: ->
|
updatePosition: ->
|
||||||
return unless @thang?.pos and @options.camera?
|
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]
|
[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
|
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
|
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
|
name = AudioPlayer.nameForSoundReference sound
|
||||||
instance = createjs.Sound.play name, "none", delay, 0, 0, volume
|
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
|
#console.log @thang?.id, "played sound", name, "with delay", delay, "volume", volume, "and got sound instance", instance
|
||||||
instance
|
instance
|
|
@ -21,8 +21,7 @@ module.exports = class WizardSprite extends IndieSprite
|
||||||
subscriptions:
|
subscriptions:
|
||||||
'bus:player-states-changed': 'onPlayerStatesChanged'
|
'bus:player-states-changed': 'onPlayerStatesChanged'
|
||||||
'me:synced': 'onMeSynced'
|
'me:synced': 'onMeSynced'
|
||||||
'surface:sprite-selected': 'onSpriteSelected'
|
'surface:sprite-selected': 'onSpriteSelected'
|
||||||
'surface:ticked': 'onSurfaceTicked'
|
|
||||||
'echo-self-wizard-sprite': 'onEchoSelfWizardSprite'
|
'echo-self-wizard-sprite': 'onEchoSelfWizardSprite'
|
||||||
'echo-all-wizard-sprites': 'onEchoAllWizardSprites'
|
'echo-all-wizard-sprites': 'onEchoAllWizardSprites'
|
||||||
|
|
||||||
|
@ -102,8 +101,7 @@ module.exports = class WizardSprite extends IndieSprite
|
||||||
onEchoSelfWizardSprite: (e) -> e.payload = @ if @isSelf
|
onEchoSelfWizardSprite: (e) -> e.payload = @ if @isSelf
|
||||||
onEchoAllWizardSprites: (e) -> e.payload.push @
|
onEchoAllWizardSprites: (e) -> e.payload.push @
|
||||||
defaultPos: -> x: 35, y: 24, z: @thang.depth / 2 + @spriteZOffset
|
defaultPos: -> x: 35, y: 24, z: @thang.depth / 2 + @spriteZOffset
|
||||||
getZOffset: -> @thang.depth / 2 + @spriteZOffset + Math.sin @ticker / 20 # Cloud bobbing.
|
getZOffset: -> @thang.depth / 2 + @spriteZOffset + Math.sin @ticker / 20 # Cloud bobbing.
|
||||||
onSurfaceTicked: -> @ticker += 1
|
|
||||||
move: (pos, duration) -> @setTarget(pos, duration)
|
move: (pos, duration) -> @setTarget(pos, duration)
|
||||||
|
|
||||||
setTarget: (newTarget, duration) ->
|
setTarget: (newTarget, duration) ->
|
||||||
|
|
Loading…
Reference in a new issue