mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Added some explanations for the SpriteBoss test setup.
This commit is contained in:
parent
0b948d4a1e
commit
f2765e05b0
1 changed files with 38 additions and 13 deletions
|
@ -21,21 +21,31 @@ describe 'SpriteBoss', ->
|
||||||
canvas = $('<canvas width="800" height="600"></canvas>')
|
canvas = $('<canvas width="800" height="600"></canvas>')
|
||||||
camera = new Camera(canvas)
|
camera = new Camera(canvas)
|
||||||
|
|
||||||
|
# Create an initial, simple world with just trees
|
||||||
world = new World()
|
world = new World()
|
||||||
world.thangs = [
|
world.thangs = [
|
||||||
{id: 'Tree 1', spriteName: 'Tree 1', exists: true, pos: {x:4, y:0}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
# Set trees side by side with different render strategies
|
||||||
{id: 'Tree Will Disappear', spriteName: 'Tree 1', exists: true, pos: {x:2, y:0}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
{id: 'Tree 1', spriteName: 'Tree 1', exists: true, pos: {x:10, y:-8}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
||||||
|
{id: 'Tree 2', spriteName: 'Full Render Tree', exists: true, pos: {x:8, y:-8}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
||||||
|
|
||||||
|
# Include a tree whose existence will change so we can test removing sprites
|
||||||
|
{id: 'Tree Will Disappear', spriteName: 'Tree 1', exists: true, pos: {x:0, y:0}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
||||||
]
|
]
|
||||||
world.thangMap = {}
|
world.thangMap = {}
|
||||||
world.thangMap[thang.id] = thang for thang in world.thangs
|
world.thangMap[thang.id] = thang for thang in world.thangs
|
||||||
|
|
||||||
thangTypes = [treeThangType, ogreMunchkinThangType, ogreFangriderThangType]
|
# Set up thang types. Mix renderStrategies.
|
||||||
|
fullRenderOgreMunchkinThangType = ogreMunchkinThangType.clone()
|
||||||
|
fullRenderOgreMunchkinThangType.set({name:'Full Render Ogre', slug:'full-render-ogre'})
|
||||||
|
fullRenderTreeThangType = treeThangType.clone()
|
||||||
|
fullRenderTreeThangType.set({name:'Full Render Tree', slug:'full-render-tree'})
|
||||||
ogreMunchkinThangType.set('renderStrategy', 'container')
|
ogreMunchkinThangType.set('renderStrategy', 'container')
|
||||||
ogreFangriderThangType.set('renderStrategy', 'container')
|
ogreFangriderThangType.set('renderStrategy', 'container')
|
||||||
treeThangType.set('renderStrategy', 'container')
|
treeThangType.set('renderStrategy', 'container')
|
||||||
|
thangTypes = [treeThangType, ogreMunchkinThangType, ogreFangriderThangType, fullRenderOgreMunchkinThangType, fullRenderTreeThangType]
|
||||||
|
|
||||||
|
# Build the Stage and SpriteBoss.
|
||||||
window.stage = stage = new createjs.Stage(canvas[0])
|
window.stage = stage = new createjs.Stage(canvas[0])
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
camera: camera
|
camera: camera
|
||||||
surfaceLayer: stage
|
surfaceLayer: stage
|
||||||
|
@ -45,32 +55,47 @@ describe 'SpriteBoss', ->
|
||||||
}
|
}
|
||||||
|
|
||||||
window.spriteBoss = spriteBoss = new SpriteBoss(options)
|
window.spriteBoss = spriteBoss = new SpriteBoss(options)
|
||||||
|
|
||||||
defaultLayer = spriteBoss.spriteLayers.Default
|
defaultLayer = spriteBoss.spriteLayers.Default
|
||||||
defaultLayer.buildAsync = false # cause faster
|
defaultLayer.buildAsync = false # cause faster
|
||||||
|
|
||||||
|
# Don't have the layer automatically draw for move_fore, instead have it notified from WebGLSprites that
|
||||||
|
# this animation or its containers are needed.
|
||||||
|
# defaultLayer.setDefaultActions(_.without defaultLayer.defaultActions, 'move_fore')
|
||||||
|
|
||||||
|
# Render the simple world with just trees
|
||||||
spriteBoss.update(true)
|
spriteBoss.update(true)
|
||||||
|
|
||||||
defaultLayer.once 'new-spritesheet', ->
|
defaultLayer.once 'new-spritesheet', ->
|
||||||
|
|
||||||
|
# Now make the world a little more complicated.
|
||||||
world.thangs = world.thangs.concat [
|
world.thangs = world.thangs.concat [
|
||||||
# four cardinal ogres
|
# four cardinal ogres, to test movement rotation and placement around a center point.
|
||||||
{id: 'Ogre N', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:0, y:8}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, scaleFactorX: 2 }
|
{id: 'Ogre N', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:0, y:8}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, scaleFactorX: 1.5 }
|
||||||
{id: 'Ogre W', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: 0, acts: true, scaleFactorY: 2 }
|
{id: 'Ogre W', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: 0, acts: true, scaleFactorY: 1.5 }
|
||||||
{id: 'Ogre E', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI, acts: true, alpha: 0.5, scaleFactorY: 3, scaleFactorX: 3 }
|
{id: 'Ogre E', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI, acts: true, alpha: 0.5 }
|
||||||
{id: 'Ogre S', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:0, y:-8}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI/2, acts: true }
|
{id: 'Ogre S', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:0, y:-8}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI/2, acts: true }
|
||||||
|
|
||||||
# ogres overlapping
|
# Set ogres side by side with different render strategies
|
||||||
|
{id: 'FROgre', spriteName: 'Full Render Ogre', exists: true, pos: {x:-10, y:-8}, action: 'idle', health: 10, maxHealth: 10, rotation: 0, acts: true }
|
||||||
|
{id: 'NotFROgre', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-8, y:-8}, action: 'idle', health: 10, maxHealth: 10, rotation: 0, acts: true }
|
||||||
|
|
||||||
|
# A line of ogres overlapping to test child ordering
|
||||||
{id: 'Ogre 1', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-14, y:0}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
{id: 'Ogre 1', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-14, y:0}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||||
{id: 'Ogre 2', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-13.5, y:1}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
{id: 'Ogre 2', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-13.5, y:1}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||||
{id: 'Ogre 3', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-13, y:2}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
{id: 'Ogre 3', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-13, y:2}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||||
{id: 'Ogre 4', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-12.5, y:3}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
{id: 'Ogre 4', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-12.5, y:3}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||||
|
|
||||||
|
# Throw in a ThangType that contains nested MovieClips
|
||||||
{id: 'Fangrider 1', spriteName: 'Ogre Fangrider', exists: true, pos: {x:8, y:8}, action: 'move', health: 20, maxHealth: 20, rotation: 0, acts: true }
|
{id: 'Fangrider 1', spriteName: 'Ogre Fangrider', exists: true, pos: {x:8, y:8}, action: 'move', health: 20, maxHealth: 20, rotation: 0, acts: true }
|
||||||
]
|
]
|
||||||
_.find(world.thangs, {id: 'Tree Will Disappear'}).exists = false
|
|
||||||
|
_.find(world.thangs, {id: 'Tree Will Disappear'}).exists = false
|
||||||
world.thangMap[thang.id] = thang for thang in world.thangs
|
world.thangMap[thang.id] = thang for thang in world.thangs
|
||||||
spriteBoss.update(true)
|
spriteBoss.update(true)
|
||||||
defaultLayer.once 'new-spritesheet', ->
|
defaultLayer.once 'new-spritesheet', ->
|
||||||
done()
|
done()
|
||||||
# showMe()
|
|
||||||
|
showMe() # Uncomment to display this world when you run any of these tests.
|
||||||
|
|
||||||
beforeEach (done) -> init(done)
|
beforeEach (done) -> init(done)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue