mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-23 19:32:03 -04: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'
|
Label = require './Label'
|
||||||
AudioPlayer = require 'lib/AudioPlayer'
|
AudioPlayer = require 'lib/AudioPlayer'
|
||||||
|
|
||||||
#For bobbing
|
|
||||||
ticker = 0
|
|
||||||
|
|
||||||
# We'll get rid of this once level's teams actually have colors
|
# We'll get rid of this once level's teams actually have colors
|
||||||
healthColors =
|
healthColors =
|
||||||
ogres: [64, 128, 212]
|
ogres: [64, 128, 212]
|
||||||
|
@ -55,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
|
||||||
|
@ -66,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()
|
||||||
|
@ -115,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
|
||||||
|
@ -150,16 +150,15 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
|
|
||||||
updatePosition: ->
|
updatePosition: ->
|
||||||
return unless @thang?.pos and @options.camera?
|
return unless @thang?.pos and @options.camera?
|
||||||
if 'bobs' in @thang.trackedPropertiesKeys
|
if @thang.bobHeight
|
||||||
ticker++
|
@thang.pos.z = @thang.pos.z + (Math.sin @ticker / @thang.bobTime) * 0.1 * @thang.bobHeight
|
||||||
@thang.pos.z = @thang.pos.z + (Math.sin ticker / (1 / @thang.bobSpeed) * .01 * @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
|
||||||
sup = @options.camera.worldToSurface wop
|
sup = @options.camera.worldToSurface wop
|
||||||
[@displayObject.x, @displayObject.y] = [sup.x, sup.y]
|
[@displayObject.x, @displayObject.y] = [sup.x, sup.y]
|
||||||
@lastPos = _.clone(p1)
|
@lastPos = _.clone(p1)
|
||||||
@hasMoved = true
|
@hasMoved = true
|
||||||
|
|
||||||
updateScale: ->
|
updateScale: ->
|
||||||
if @thangType.get('matchWorldDimensions') and @thang
|
if @thangType.get('matchWorldDimensions') and @thang
|
||||||
|
@ -179,7 +178,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
return unless @thang?.alpha?
|
return unless @thang?.alpha?
|
||||||
@imageObject.alpha = @thang.alpha
|
@imageObject.alpha = @thang.alpha
|
||||||
if @options.showInvisible
|
if @options.showInvisible
|
||||||
@imageObject.alpha = Math.max 0.5, @imageObject.alpha
|
@imageObject.alpha = Math.max 0.5, @imageObject.alpha
|
||||||
|
|
||||||
updateRotation: (imageObject) ->
|
updateRotation: (imageObject) ->
|
||||||
rotationType = @thangType.get('rotationType')
|
rotationType = @thangType.get('rotationType')
|
||||||
|
@ -428,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…
Add table
Reference in a new issue