This commit is contained in:
Ting-Kuan 2014-03-24 13:19:30 -04:00
commit 37876ee480
10 changed files with 108 additions and 90 deletions

View file

@ -27,8 +27,8 @@ Whether you're novice or pro, the CodeCombat team is ready to help you implement
![Nick Winter](http://codecombat.com/images/pages/about/nick_small.png)
![Michael Schmatz](http://codecombat.com/images/pages/about/michael_small.png)
![Jeremy Arns](http://codecombat.com/images/pages/about/jeremy_small.png)
![Glen De Cauwsemaecker](http://codecombat.com/images/pages/about/glen_small.png)
![Tom Steinbrecher](http://codecombat.com/images/pages/contribute/archmage/tom_small.png)
![Glen De Cauwsemaecker](http://codecombat.com/images/pages/contribute/archmage/glen_small.png)
![Sébastien Moratinos](http://codecombat.com/images/pages/contribute/archmage/sebastien_small.png)
![deepak1556](http://codecombat.com/images/pages/contribute/archmage/deepak_small.png)
![Ronnie Cheng](http://codecombat.com/images/pages/contribute/archmage/ronald_small.png)

View file

@ -7,7 +7,7 @@ World = require 'lib/world/world'
# Also uncomment vendor_with_box2d.js in index.html if you want Collision to run and things to move.
module.exports = class God
@ids: ['Athena', 'Baldr', 'Crom', 'Dagr', 'Eris', 'Freyja', 'Great Gish', 'Hades', 'Ishtar', 'Janus', 'Khronos', 'Loki', 'Marduk', 'Negafook', 'Odin', 'Poseidon', 'Quetzalcoatl', 'Ra', 'Shiva', 'Thor', 'Umvelinqangi', 'Týr', 'Vishnu', 'Wepwawet', 'Xipe Totec', 'Yahweh', 'Zeus', '上帝', 'Tiamat', '盘古', 'Phoebe', 'Artemis', 'Osiris', "嫦娥", 'Anhur', 'Teshub', 'Enlil', 'Perkele', 'Aether', 'Chaos', 'Hera', 'Iris', 'Theia', 'Uranus', 'Stribog', 'Sabazios', 'Izanagi', 'Ao', 'Tāwhirimātea', 'Tengri', 'Inmar', 'Torngarsuk', 'Centzonhuitznahua', 'Hunab Ku', 'Apollo', 'Helios', 'Thoth', 'Hyperion', 'Alectrona', 'Eos', 'Mitra', 'Saranyu', 'Freyr', 'Koyash', 'Atropos', 'Clotho', 'Lachesis', 'Tyche', 'Skuld', 'Urðr', 'Verðandi', 'Camaxtli', 'Huhetotl', 'Set', 'Anu', 'Allah', 'Anshar', 'Hermes', 'Lugh', 'Brigit', 'Manannan Mac Lir', 'Persephone', 'Mercury', 'Venus', 'Mars', 'Azrael', 'He-Man', 'Anansi', 'Issek', 'Mog', 'Kos', 'Amaterasu Omikami', 'Raijin', 'Susanowo', 'Blind Io', 'The Lady', 'Offler', 'Ptah', 'Anubis', 'Ereshkigal', 'Nergal', 'Thanatos', 'Macaria', 'Angelos', 'Erebus', 'Hecate', 'Hel', 'Orcus', 'Ishtar-Deela Nakh', 'Prometheus', 'Hephaestos', 'Sekhmet', 'Ares', 'Enyo', 'Otrera', 'Pele', 'Hadúr', 'Hachiman', 'Dayisun Tngri', 'Ullr', 'Lua', 'Minerva']
@ids: ['Athena', 'Baldr', 'Crom', 'Dagr', 'Eris', 'Freyja', 'Great Gish', 'Hades', 'Ishtar', 'Janus', 'Khronos', 'Loki', 'Marduk', 'Negafook', 'Odin', 'Poseidon', 'Quetzalcoatl', 'Ra', 'Shiva', 'Thor', 'Umvelinqangi', 'Týr', 'Vishnu', 'Wepwawet', 'Xipe Totec', 'Yahweh', 'Zeus', '上帝', 'Tiamat', '盘古', 'Phoebe', 'Artemis', 'Osiris', "嫦娥", 'Anhur', 'Teshub', 'Enlil', 'Perkele', 'Chaos', 'Hera', 'Iris', 'Theia', 'Uranus', 'Stribog', 'Sabazios', 'Izanagi', 'Ao', 'Tāwhirimātea', 'Tengri', 'Inmar', 'Torngarsuk', 'Centzonhuitznahua', 'Hunab Ku', 'Apollo', 'Helios', 'Thoth', 'Hyperion', 'Alectrona', 'Eos', 'Mitra', 'Saranyu', 'Freyr', 'Koyash', 'Atropos', 'Clotho', 'Lachesis', 'Tyche', 'Skuld', 'Urðr', 'Verðandi', 'Camaxtli', 'Huhetotl', 'Set', 'Anu', 'Allah', 'Anshar', 'Hermes', 'Lugh', 'Brigit', 'Manannan Mac Lir', 'Persephone', 'Mercury', 'Venus', 'Mars', 'Azrael', 'He-Man', 'Anansi', 'Issek', 'Mog', 'Kos', 'Amaterasu Omikami', 'Raijin', 'Susanowo', 'Blind Io', 'The Lady', 'Offler', 'Ptah', 'Anubis', 'Ereshkigal', 'Nergal', 'Thanatos', 'Macaria', 'Angelos', 'Erebus', 'Hecate', 'Hel', 'Orcus', 'Ishtar-Deela Nakh', 'Prometheus', 'Hephaestos', 'Sekhmet', 'Ares', 'Enyo', 'Otrera', 'Pele', 'Hadúr', 'Hachiman', 'Dayisun Tngri', 'Ullr', 'Lua', 'Minerva']
@nextID: ->
@lastID = (if @lastID? then @lastID + 1 else Math.floor(@ids.length * Math.random())) % @ids.length
@ids[@lastID]
@ -52,7 +52,7 @@ module.exports = class God
onWorkerMessage: (event) =>
worker = event.target
if event.data.type is 'worker-initialized'
#console.log "Worker initialized after", ((new Date()) - worker.creationTime), "ms (before it was needed)"
#console.log @id, "worker initialized after", ((new Date()) - worker.creationTime), "ms (before it was needed)"
worker.initialized = true
worker.removeEventListener 'message', @onWorkerMessage

View file

@ -35,6 +35,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
spriteSheetCache: null
showInvisible: false
possessed: false
flipped: false
flippedCount: 0
originalScaleX: null
@ -54,6 +55,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
'level-sprite-clear-dialogue': 'onClearDialogue'
'level-set-letterbox': 'onSetLetterbox'
'surface:ticked': 'onSurfaceTicked'
'level-sprite-move': 'onMove'
constructor: (@thangType, options) ->
super()
@ -223,7 +225,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@thang.bobHeight * (1 + Math.sin(@age * Math.PI / @thang.bobTime))
getWorldPosition: ->
p1 = @thang.pos
p1 = if @possessed then @shadow.pos else @thang.pos
if bobOffset = @getBobOffset()
p1 = p1.copy?() or _.clone(p1)
p1.z += bobOffset
@ -309,8 +311,9 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@updateIsometricRotation(rotation, imageObject)
getRotation: ->
return @rotation if not @thang?.rotation
rotation = @thang?.rotation
thang = if @possessed then @shadow else @thang
return @rotation if not thang?.rotation
rotation = thang?.rotation
rotation = (360 - (rotation * 180 / Math.PI) % 360) % 360
rotation -= 360 if rotation > 180
rotation
@ -333,13 +336,14 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
determineAction: ->
action = null
action = @thang.getActionName() if @thang?.acts
thang = if @possessed then @shadow else @thang
action = thang.action if thang?.acts
action ?= @currentRootAction.name if @currentRootAction?
action ?= 'idle'
action = null unless @actions[action]?
return null unless action
action = 'break' if @actions.break? and @thang?.erroredOut
action = 'die' if @actions.die? and @thang?.health? and @thang.health <= 0
action = 'die' if @actions.die? and thang?.health? and thang.health <= 0
@actions[action]
updateActionDirection: (@wallGrid=null) ->
@ -619,3 +623,67 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
instance = AudioPlayer.playSound name, volume, delay, @getWorldPosition()
# console.log @thang?.id, "played sound", name, "with delay", delay, "volume", volume, "and got sound instance", instance
instance
onMove: (e) ->
return unless e.spriteID is @thang?.id
pos = e.pos
if _.isArray pos
pos = new Vector pos...
else if _.isString pos
return console.warn "Couldn't find target sprite", pos, "from", @options.sprites unless pos of @options.sprites
target = @options.sprites[pos].thang
heading = Vector.subtract(target.pos, @thang.pos).normalize()
distance = @thang.pos.distance target.pos
offset = Math.max(target.width, target.height, 2) / 2 + 3
pos = Vector.add(@thang.pos, heading.multiply(distance - offset))
Backbone.Mediator.publish 'level-sprite-clear-dialogue', {}
@onClearDialogue()
args = [pos]
args.push(e.duration) if e.duration?
@move(args...)
move: (pos, duration=2000, endAnimation='idle') =>
@updateShadow()
if not duration
createjs.Tween.removeTweens(@shadow.pos) if @lastTween
@lastTween = null
z = @shadow.pos.z
@shadow.pos = pos
@shadow.pos.z = z
@imageObject.gotoAndPlay(endAnimation)
return
@shadow.action = 'move'
@shadow.actionActivated = true
@pointToward(pos)
@possessed = true
@update true
ease = createjs.Ease.getPowInOut(2.2)
if @lastTween
ease = createjs.Ease.getPowOut(1.2)
createjs.Tween.removeTweens(@shadow.pos)
endFunc = =>
@lastTween = null
@imageObject.gotoAndPlay(endAnimation)
@shadow.action = 'idle'
@update true
@possessed = false
@lastTween = createjs.Tween
.get(@shadow.pos)
.to({x:pos.x, y:pos.y}, duration, ease)
.call(endFunc)
pointToward: (pos) ->
@shadow.rotation = Math.atan2(pos.y - @shadow.pos.y, pos.x - @shadow.pos.x)
if (@shadow.rotation * 180 / Math.PI) % 90 is 0
@shadow.rotation += 0.01
updateShadow: ->
@shadow = {} if not @shadow
@shadow.pos = @thang.pos
@shadow.rotation = @thang.rotation
@shadow.action = @thang.action
@shadow.actionActivated = @thang.actionActivated

View file

@ -7,13 +7,13 @@ Camera = require './Camera'
module.exports = IndieSprite = class IndieSprite extends CocoSprite
notOfThisWorld: true
subscriptions:
'level-sprite-move': 'onMove'
'note-group-started': 'onNoteGroupStarted'
'note-group-ended': 'onNoteGroupEnded'
constructor: (thangType, options) ->
options.thang = @makeIndieThang thangType, options.thangID, options.pos
super thangType, options
@shadow = @thang
makeIndieThang: (thangType, thangID, pos) ->
@thang = thang = new Thang null, thangType.get('name'), thangID
@ -35,57 +35,3 @@ module.exports = IndieSprite = class IndieSprite extends CocoSprite
onNoteGroupEnded: => @scriptRunning = false
onMouseEvent: (e, ourEventName) -> super e, ourEventName unless @scriptRunning
defaultPos: -> x: -20, y: 20, z: @thang.depth / 2
onMove: (e) ->
return unless e.spriteID is @thang.id
pos = e.pos
if _.isArray pos
pos = new Vector pos...
else if _.isString pos
return console.warn "Couldn't find target sprite", pos, "from", @options.sprites unless pos of @options.sprites
target = @options.sprites[pos].thang
heading = Vector.subtract(target.pos, @thang.pos).normalize()
distance = @thang.pos.distance target.pos
offset = Math.max(target.width, target.height, 2) / 2 + 3
pos = Vector.add(@thang.pos, heading.multiply(distance - offset))
Backbone.Mediator.publish 'level-sprite-clear-dialogue', {}
@onClearDialogue()
args = [pos]
args.push(e.duration) if e.duration?
@move(args...)
move: (pos, duration=2000, endAnimation='idle') =>
if not duration
createjs.Tween.removeTweens(@thang.pos) if @lastTween
@lastTween = null
z = @thang.pos.z
@thang.pos = pos
@thang.pos.z = z
@imageObject.gotoAndPlay(endAnimation)
return
@thang.action = 'move'
@thang.actionActivated = true
@pointToward(pos)
@update true
ease = createjs.Ease.getPowInOut(2.2)
if @lastTween
ease = createjs.Ease.getPowOut(1.2)
createjs.Tween.removeTweens(@thang.pos)
endFunc = =>
@lastTween = null
@imageObject.gotoAndPlay(endAnimation)
@thang.action = 'idle'
@update true
@lastTween = createjs.Tween
.get(@thang.pos)
.to({x:pos.x, y:pos.y}, duration, ease)
.call(endFunc)
pointToward: (pos) ->
@thang.rotation = Math.atan2(pos.y - @thang.pos.y, pos.x - @thang.pos.x)
if (@thang.rotation * 180 / Math.PI) % 90 is 0
@thang.rotation += 0.01

View file

@ -67,9 +67,13 @@ module.exports = class Layer extends createjs.Container
# TODO: remove this z stuff
az = if a.z then a.z else 1000
bz = if b.z then b.z else 1000
aThang = a.sprite?.thang
bThang = b.sprite?.thang
az -= 1 if aThang?.health < 0
bz -= 1 if bThang?.health < 0
if az == bz
return 0 unless a.sprite?.thang?.pos and b.sprite?.thang?.pos
return (b.sprite.thang.pos.y - a.sprite.thang.pos.y) or (b.sprite.thang.pos.x - a.sprite.thang.pos.x)
return 0 unless aThang?.pos and bThang?.pos
return (bThang.pos.y - aThang.pos.y) or (bThang.pos.x - aThang.pos.x)
return az - bz
onZoomUpdated: (e) ->

View file

@ -143,9 +143,9 @@ module.exports = class ThangType extends CocoModel
@builder.buildAsync() unless buildQueue.length > 1
@builder.on 'complete', @onBuildSpriteSheetComplete, @, true, key
return true
t0 = new Date().getTime()
t0 = new Date()
spriteSheet = @builder.build()
console.warn "Built #{@get('name')} in #{new Date().getTime() - t0}ms on main thread."
console.warn "Built #{@get('name')} in #{new Date() - t0}ms on main thread."
@spriteSheets[key] = spriteSheet
delete @building[key]
spriteSheet

View file

@ -9,8 +9,6 @@
border: 1px solid transparent
cursor: pointer
@include user-select(all)
::selection
background: transparent
&:hover
border: 1px solid #000000

View file

@ -10,8 +10,12 @@ module.exports = class WizardSettingsModal extends View
template: template
closesOnClickOutside: false
constructor: (options) ->
@onNameChange = _.debounce(@checkNameExists, 500)
super options
events:
'change #wizard-settings-name': 'onNameChange'
'keyup #wizard-settings-name': 'onNameChange'
'click #wizard-settings-done': 'onWizardSettingsDone'
afterRender: ->
@ -19,16 +23,16 @@ module.exports = class WizardSettingsModal extends View
view = new WizardSettingsView()
@insertSubView view
onNameChange: ->
me.set('name', $('#wizard-settings-name').val())
@checkNameExists()
checkNameExists: ->
checkNameExists: =>
forms.clearFormAlerts(@$el)
success = (id) => forms.applyErrorsToForm(@$el, {property:'name', message:'is already taken'}) if id and id isnt me.id
$.ajax("/db/user/#{me.get('name')}/nameToID", {success: success})
onWizardSettingsDone: ->
name = $('#wizard-settings-name').val()
success = (id) =>
forms.clearFormAlerts(@$el)
forms.applyErrorsToForm(@$el, {property:'name', message:'is already taken'}) if id and id isnt me.id
$.ajax("/db/user/#{name}/nameToID", {success: success})
onWizardSettingsDone: =>
me.set('name', $('#wizard-settings-name').val())
forms.clearFormAlerts(@$el)
res = me.validate()
if res?
@ -44,8 +48,9 @@ module.exports = class WizardSettingsModal extends View
errors = JSON.parse(res.responseText)
forms.applyErrorsToForm(@$el, errors)
@disableModalInProgress(@$el)
res.success (model, response, options) =>
@hide()
@enableModalInProgress(@$el)
me.save()
me.save()

View file

@ -19,10 +19,10 @@ module.exports = class LadderTabView extends CocoView
id: 'ladder-tab-view'
template: require 'templates/play/ladder/ladder_tab'
startsLoading: true
events:
'click .connect-facebook': 'onConnectFacebook'
subscriptions:
'facebook-logged-in': 'onConnectedWithFacebook'
@ -48,13 +48,13 @@ module.exports = class LadderTabView extends CocoView
# FACEBOOK
# Connect button pressed
onConnectFacebook: ->
@connecting = true
FB.login()
onConnectedWithFacebook: -> location.reload() if @connecting
# Load friends
loadFacebookFriendSessions: ->
@ -101,7 +101,7 @@ module.exports = class LadderTabView extends CocoView
onGPlusFriendSessionsLoaded: (result) =>
@loadingGPlusFriends = false
@renderMaybe()
# LADDER LOADING
refreshLadder: ->
@ -117,7 +117,7 @@ module.exports = class LadderTabView extends CocoView
leaderboardsLoaded: =>
@loadingLeaderboards = false
@renderMaybe()
renderMaybe: ->
return if @loadingFacebookFriends or @loadingLeaderboards
@startsLoading = false

View file

@ -171,9 +171,6 @@ module.exports = class SpellPaletteEntryView extends View
Backbone.Mediator.publish 'tome:palette-pin-toggled', entry: @, pinned: @popoverPinned
onClick: (e) =>
unless @popoverPinned
$(e.target).selectText()
e.stopPropagation() # don't re-focus editor since we might want to select text
@togglePinned()
Backbone.Mediator.publish 'tome:palette-clicked', thang: @thang, prop: @doc.name, entry: @