mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Refactored ticker, fixed from all instances were using same ticker.
This commit is contained in:
parent
b5bb1b13a1
commit
d50c362286
2 changed files with 11 additions and 14 deletions
|
@ -6,9 +6,6 @@ Mark = require './Mark'
|
|||
Label = require './Label'
|
||||
AudioPlayer = require 'lib/AudioPlayer'
|
||||
|
||||
#For bobbing
|
||||
ticker = 0
|
||||
|
||||
# We'll get rid of this once level's teams actually have colors
|
||||
healthColors =
|
||||
ogres: [64, 128, 212]
|
||||
|
@ -55,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
|
||||
|
@ -66,6 +64,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
@labels = {}
|
||||
@actions = @thangType.getActions()
|
||||
@buildFromSpriteSheet @buildSpriteSheet()
|
||||
@ticker = 0
|
||||
|
||||
destroy: ->
|
||||
super()
|
||||
|
@ -115,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
|
||||
|
@ -150,16 +150,15 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
|
||||
updatePosition: ->
|
||||
return unless @thang?.pos and @options.camera?
|
||||
if 'bobs' in @thang.trackedPropertiesKeys
|
||||
ticker++
|
||||
@thang.pos.z = @thang.pos.z + (Math.sin ticker / (1 / @thang.bobSpeed) * .01 * @thang.bobHeight
|
||||
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
|
||||
sup = @options.camera.worldToSurface wop
|
||||
[@displayObject.x, @displayObject.y] = [sup.x, sup.y]
|
||||
@lastPos = _.clone(p1)
|
||||
@hasMoved = true
|
||||
@hasMoved = true
|
||||
|
||||
updateScale: ->
|
||||
if @thangType.get('matchWorldDimensions') and @thang
|
||||
|
@ -179,7 +178,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
return unless @thang?.alpha?
|
||||
@imageObject.alpha = @thang.alpha
|
||||
if @options.showInvisible
|
||||
@imageObject.alpha = Math.max 0.5, @imageObject.alpha
|
||||
@imageObject.alpha = Math.max 0.5, @imageObject.alpha
|
||||
|
||||
updateRotation: (imageObject) ->
|
||||
rotationType = @thangType.get('rotationType')
|
||||
|
@ -428,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
|
|
@ -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) ->
|
||||
|
|
Loading…
Reference in a new issue