mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Re-enabled shadows.
This commit is contained in:
parent
7f90ed18cc
commit
91f33e49dc
3 changed files with 43 additions and 30 deletions
|
@ -511,7 +511,6 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
pos
|
||||
|
||||
createMarks: ->
|
||||
return # TODO: get marks working again
|
||||
return unless @options.camera
|
||||
if @thang
|
||||
allProps = []
|
||||
|
@ -608,7 +607,6 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
@labels[name]
|
||||
|
||||
addMark: (name, layer, thangType=null) ->
|
||||
return # TODO: figure out how to recreate marks
|
||||
@marks[name] ?= new Mark name: name, sprite: @, camera: @options.camera, layer: layer ? @options.groundLayer, thangType: thangType
|
||||
@marks[name]
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ module.exports = class Mark extends CocoClass
|
|||
@camera = options.camera
|
||||
@layer = options.layer
|
||||
@thangType = options.thangType
|
||||
@listenTo @layer, 'new-spritesheet', @onLayerMadeSpriteSheet
|
||||
console.error @toString(), 'needs a name.' unless @name
|
||||
console.error @toString(), 'needs a camera.' unless @camera
|
||||
console.error @toString(), 'needs a layer.' unless @layer
|
||||
|
@ -29,6 +30,13 @@ module.exports = class Mark extends CocoClass
|
|||
|
||||
toString: -> "<Mark #{@name}: Sprite #{@sprite?.thang?.id ? 'None'}>"
|
||||
|
||||
onLayerMadeSpriteSheet: ->
|
||||
return unless @mark
|
||||
@mark = null
|
||||
@build()
|
||||
@layer.addChild @mark
|
||||
@layer.updateLayerOrder()
|
||||
|
||||
toggle: (to) ->
|
||||
return @ if to is @on
|
||||
return @toggleTo = to unless @mark
|
||||
|
@ -119,7 +127,20 @@ module.exports = class Mark extends CocoClass
|
|||
@lastHeight = @sprite.thang.height
|
||||
|
||||
buildShadow: ->
|
||||
alpha = @sprite.thang?.alpha ? 1
|
||||
shapeName = if @sprite.thang.shape in ['ellipsoid', 'disc'] then 'ellipse' else 'rect'
|
||||
key = "#{shapeName}-shadow"
|
||||
SHADOW_SIZE = 10
|
||||
unless key in @layer.spriteSheet.getAnimations()
|
||||
shape = new createjs.Shape()
|
||||
shape.graphics.beginFill "rgba(0,0,0)"
|
||||
bounds = [-SHADOW_SIZE/2, - SHADOW_SIZE/2, SHADOW_SIZE, SHADOW_SIZE]
|
||||
if shapeName is 'ellipse'
|
||||
shape.graphics.drawEllipse bounds...
|
||||
else
|
||||
shape.graphics.drawRect bounds...
|
||||
shape.graphics.endFill()
|
||||
@layer.addCustomGraphic(key, shape, bounds)
|
||||
alpha = @sprite.thang?.alpha ? 1
|
||||
width = (@sprite.thang?.width ? 0) + 0.5
|
||||
height = (@sprite.thang?.height ? 0) + 0.5
|
||||
longest = Math.max width, height
|
||||
|
@ -128,17 +149,12 @@ module.exports = class Mark extends CocoClass
|
|||
height = height * actualLongest / longest
|
||||
width *= Camera.PPM
|
||||
height *= Camera.PPM * @camera.y2x # TODO: doesn't work with rotation
|
||||
@mark = new createjs.Shape()
|
||||
@mark = new createjs.Sprite(@layer.spriteSheet)
|
||||
@mark.gotoAndStop(key)
|
||||
@mark.mouseEnabled = false
|
||||
@mark.graphics.beginFill "rgba(0,0,0,#{alpha})"
|
||||
if @sprite.thang.shape in ['ellipsoid', 'disc']
|
||||
@mark.graphics.drawEllipse 0, 0, width, height
|
||||
else
|
||||
@mark.graphics.drawRect 0, 0, width, height
|
||||
@mark.graphics.endFill()
|
||||
@mark.regX = width / 2
|
||||
@mark.regY = height / 2
|
||||
@mark.cache -1, -1, width + 2, height + 2 # not actually faster than simple ellipse draw
|
||||
@mark.alpha = alpha
|
||||
@baseScaleX = @mark.scaleX = width / (@layer.resolutionFactor * SHADOW_SIZE)
|
||||
@baseScaleY = @mark.scaleY = height / (@layer.resolutionFactor * SHADOW_SIZE)
|
||||
|
||||
buildRadius: (range) ->
|
||||
alpha = 0.15
|
||||
|
@ -217,7 +233,6 @@ module.exports = class Mark extends CocoClass
|
|||
@listenToOnce(@thangType, 'sync', @onLoadedThangType)
|
||||
@thangType.fetch()
|
||||
markThangTypes[name] = @thangType
|
||||
window.mtt = markThangTypes
|
||||
|
||||
onLoadedThangType: ->
|
||||
@build()
|
||||
|
@ -279,8 +294,8 @@ module.exports = class Mark extends CocoClass
|
|||
@markSprite.updateScale()
|
||||
|
||||
if @name is 'shadow' and thang = @sprite.thang
|
||||
@mark.scaleX = thang.scaleFactor ? thang.scaleFactorX ? 1
|
||||
@mark.scaleY = thang.scaleFactor ? thang.scaleFactorY ? 1
|
||||
@mark.scaleX = @baseScaleX * (thang.scaleFactor ? thang.scaleFactorX ? 1)
|
||||
@mark.scaleY = @baseScaleY * (thang.scaleFactor ? thang.scaleFactorY ? 1)
|
||||
|
||||
return unless @name in ['selection', 'target', 'repair', 'highlight']
|
||||
|
||||
|
|
|
@ -26,11 +26,11 @@ describe 'SpriteBoss', ->
|
|||
world = new World()
|
||||
world.thangs = [
|
||||
# Set trees side by side with different render strategies
|
||||
{id: 'Segmented Tree', spriteName: 'Segmented Tree', exists: true, pos: {x:10, y:-8}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
||||
{id: 'Singular Tree', spriteName: 'Singular Tree', exists: true, pos: {x:8, y:-8}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
||||
{id: 'Segmented Tree', spriteName: 'Segmented Tree', exists: true, shape: 'disc', depth: 2, pos: {x:10, y:-8, z: 1}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
||||
{id: 'Singular Tree', spriteName: 'Singular Tree', exists: true, shape: 'disc', depth: 2, pos: {x:8, y:-8, z: 1}, 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: 'Disappearing Tree', spriteName: 'Singular Tree', exists: true, pos: {x:0, y:0}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
||||
{id: 'Disappearing Tree', spriteName: 'Singular Tree', exists: true, shape: 'disc', depth: 2, pos: {x:0, y:0, z: 1}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true }
|
||||
]
|
||||
world.thangMap = {}
|
||||
world.thangMap[thang.id] = thang for thang in world.thangs
|
||||
|
@ -79,23 +79,23 @@ describe 'SpriteBoss', ->
|
|||
# Now make the world a little more complicated.
|
||||
world.thangs = world.thangs.concat [
|
||||
# four cardinal ogres, to test movement rotation and placement around a center point.
|
||||
{id: 'Ogre N', spriteName: 'Segmented Munchkin', exists: true, pos: {x:0, y:8}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, scaleFactorX: 1.5, hudProperties: ['health'] }
|
||||
{id: 'Ogre W', spriteName: 'Segmented Munchkin', exists: true, pos: {x:-8, y:0}, action: 'move', health: 8, maxHealth: 10, rotation: 0, acts: true, scaleFactorY: 1.5, hudProperties: ['health'] }
|
||||
{id: 'Ogre E', spriteName: 'Segmented Munchkin', exists: true, pos: {x:8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI, acts: true, alpha: 0.5, hudProperties: ['health'] }
|
||||
{id: 'Ogre S', spriteName: 'Segmented Munchkin', exists: true, pos: {x:0, y:-8}, action: 'move', health: 2, maxHealth: 10, rotation: Math.PI/2, acts: true, hudProperties: ['health'] }
|
||||
{id: 'Ogre N', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:0, y:8, z: 1}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, scaleFactorX: 1.5, hudProperties: ['health'] }
|
||||
{id: 'Ogre W', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:-8, y:0, z: 1}, action: 'move', health: 8, maxHealth: 10, rotation: 0, acts: true, scaleFactorY: 1.5, hudProperties: ['health'] }
|
||||
{id: 'Ogre E', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:8, y:0, z: 1}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI, acts: true, alpha: 0.5, hudProperties: ['health'] }
|
||||
{id: 'Ogre S', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:0, y:-8, z: 1}, action: 'move', health: 2, maxHealth: 10, rotation: Math.PI/2, acts: true, hudProperties: ['health'] }
|
||||
|
||||
# Set ogres side by side with different render strategies
|
||||
{id: 'Singular Ogre', spriteName: 'Singular Munchkin', exists: true, pos: {x:-10, y:-8}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, alpha: 0.5 }
|
||||
{id: 'Segmented Ogre', spriteName: 'Segmented Munchkin', exists: true, pos: {x:-8, y:-8}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true }
|
||||
{id: 'Singular Ogre', spriteName: 'Singular Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:-10, y:-8, z: 1}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, alpha: 0.5 }
|
||||
{id: 'Segmented Ogre', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:-8, y:-8, z: 1}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true }
|
||||
|
||||
# A line of ogres overlapping to test child ordering
|
||||
{id: 'Dying Ogre 1', spriteName: 'Segmented Munchkin', exists: true, pos: {x:-14, y:0}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||
{id: 'Dying Ogre 2', spriteName: 'Segmented Munchkin', exists: true, pos: {x:-13.5, y:1}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||
{id: 'Dying Ogre 3', spriteName: 'Segmented Munchkin', exists: true, pos: {x:-13, y:2}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||
{id: 'Dying Ogre 4', spriteName: 'Segmented Munchkin', exists: true, pos: {x:-12.5, y:3}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||
{id: 'Dying Ogre 1', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:-14, y:0, z: 1}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||
{id: 'Dying Ogre 2', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:-13.5, y:1, z: 1}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||
{id: 'Dying Ogre 3', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:-13, y:2, z: 1}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||
{id: 'Dying Ogre 4', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:-12.5, y:3, z: 1}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true }
|
||||
|
||||
# Throw in a ThangType that contains nested MovieClips
|
||||
{id: 'Fangrider', spriteName: 'Fangrider', exists: true, pos: {x:8, y:8}, action: 'move', health: 20, maxHealth: 20, rotation: 0, acts: true, currentEvents: ['aoe-' + JSON.stringify([0, 0, 8, '#00F'])] }
|
||||
{id: 'Fangrider', spriteName: 'Fangrider', exists: true, shape: 'disc', depth: 2, pos: {x:8, y:8, z: 1}, action: 'move', health: 20, maxHealth: 20, rotation: 0, acts: true, currentEvents: ['aoe-' + JSON.stringify([0, 0, 8, '#00F'])] }
|
||||
]
|
||||
|
||||
_.find(world.thangs, {id: 'Disappearing Tree'}).exists = false
|
||||
|
|
Loading…
Reference in a new issue