mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-26 05:53:39 -04:00
Added a screen darkener for when the spell is casting.
This commit is contained in:
parent
e48bdfa1a7
commit
052d35afe7
6 changed files with 82 additions and 2 deletions
|
@ -96,4 +96,4 @@ module.exports = class LoadingScreen extends CocoClass
|
|||
|
||||
destroy: ->
|
||||
@stage.canvas = null
|
||||
super()
|
||||
super()
|
48
app/lib/surface/CastingScreen.coffee
Normal file
48
app/lib/surface/CastingScreen.coffee
Normal file
|
@ -0,0 +1,48 @@
|
|||
CocoClass = require 'lib/CocoClass'
|
||||
|
||||
module.exports = class CastingScreen extends CocoClass
|
||||
subscriptions:
|
||||
'tome:cast-spells': 'onCastingBegins'
|
||||
'god:new-world-created': 'onCastingEnds'
|
||||
|
||||
constructor: (options) ->
|
||||
super()
|
||||
options ?= {}
|
||||
@camera = options.camera
|
||||
@layer = options.layer
|
||||
console.error @toString(), "needs a camera." unless @camera
|
||||
console.error @toString(), "needs a layer." unless @layer
|
||||
@build()
|
||||
|
||||
onCastingBegins: ->
|
||||
@show()
|
||||
|
||||
onCastingEnds: ->
|
||||
@hide()
|
||||
|
||||
toString: -> "<CastingScreen>"
|
||||
|
||||
build: ->
|
||||
@dimLayer = new createjs.Container()
|
||||
@dimLayer.mouseEnabled = @dimLayer.mouseChildren = false
|
||||
@dimLayer.layerIndex = -11
|
||||
@dimLayer.addChild @dimScreen = new createjs.Shape()
|
||||
@dimScreen.graphics.beginFill("rgba(0,0,0,0.5)").rect 0, 0, @camera.canvasWidth, @camera.canvasHeight
|
||||
@dimLayer.cache 0, 0, @camera.canvasWidth, @camera.canvasHeight
|
||||
@dimLayer.alpha = 0
|
||||
@layer.addChild @dimLayer
|
||||
|
||||
show: ->
|
||||
return if @on
|
||||
@on = true
|
||||
|
||||
@dimLayer.alpha = 0
|
||||
createjs.Tween.removeTweens @dimLayer
|
||||
createjs.Tween.get(@dimLayer).to({alpha:1}, 500)
|
||||
|
||||
hide: ->
|
||||
return unless @on
|
||||
@on = false
|
||||
|
||||
createjs.Tween.removeTweens @dimLayer
|
||||
createjs.Tween.get(@dimLayer).to({alpha:0}, 500)
|
|
@ -157,6 +157,14 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
show: ->
|
||||
@hiding = false
|
||||
@updateAlpha()
|
||||
|
||||
stop: ->
|
||||
@imageObject?.stop?()
|
||||
mark.stop() for name, mark of @marks
|
||||
|
||||
play: ->
|
||||
@imageObject?.play?()
|
||||
mark.play() for name, mark of @marks
|
||||
|
||||
update: ->
|
||||
# Gets the sprite to reflect what the current state of the thangs and surface are
|
||||
|
|
|
@ -174,3 +174,7 @@ module.exports = class Mark extends CocoClass
|
|||
@mark.scaleX = @mark.scaleY = Math.min 1, scale
|
||||
if @name in ['selection', 'target', 'repair']
|
||||
@mark.scaleY *= @camera.y2x # code applies perspective
|
||||
|
||||
stop: -> @markSprite?.stop()
|
||||
play: -> @markSprite?.play()
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ module.exports = class SpriteBoss extends CocoClass
|
|||
'level-lock-select': 'onSetLockSelect'
|
||||
'level:restarted': 'onLevelRestarted'
|
||||
'god:new-world-created': 'onNewWorld'
|
||||
'tome:cast-spells': 'onCastSpells'
|
||||
|
||||
constructor: (@options) ->
|
||||
super()
|
||||
|
@ -205,6 +206,14 @@ module.exports = class SpriteBoss extends CocoClass
|
|||
|
||||
onNewWorld: (e) ->
|
||||
@world = @options.world = e.world
|
||||
sprite.imageObject.play() for thangID, sprite of @sprites
|
||||
@selectionMark?.play()
|
||||
@targetMark?.play()
|
||||
|
||||
onCastSpells: ->
|
||||
sprite.imageObject.stop() for thangID, sprite of @sprites
|
||||
@selectionMark?.stop()
|
||||
@targetMark?.stop()
|
||||
|
||||
# Selection
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ CameraBorder = require './CameraBorder'
|
|||
Layer = require './Layer'
|
||||
Letterbox = require './Letterbox'
|
||||
Dimmer = require './Dimmer'
|
||||
CastingScreen = require './CastingScreen'
|
||||
DebugDisplay = require './DebugDisplay'
|
||||
CoordinateDisplay = require './CoordinateDisplay'
|
||||
SpriteBoss = require './SpriteBoss'
|
||||
|
@ -88,6 +89,7 @@ module.exports = Surface = class Surface extends CocoClass
|
|||
@spriteBoss.destroy()
|
||||
@chooser?.destroy()
|
||||
@dimmer?.destroy()
|
||||
@castingScreen?.destroy()
|
||||
@stage.clear()
|
||||
@musicPlayer?.destroy()
|
||||
@stage.removeAllChildren()
|
||||
|
@ -299,11 +301,18 @@ module.exports = Surface = class Surface extends CocoClass
|
|||
@lastFrame = @currentFrame
|
||||
|
||||
onCastSpells: (event) ->
|
||||
@casting = true
|
||||
@wasPlayingWhenCastingBegan = @playing
|
||||
Backbone.Mediator.publish 'level-set-playing', { playing: false }
|
||||
|
||||
createjs.Tween.removeTweens(@surfaceLayer)
|
||||
createjs.Tween.get(@surfaceLayer).to({alpha:0.9}, 1000, createjs.Ease.getPowOut(4.0))
|
||||
|
||||
onNewWorld: (event) ->
|
||||
return unless event.world.name is @world.name
|
||||
@casting = false
|
||||
Backbone.Mediator.publish 'level-set-playing', { playing: @wasPlayingWhenCastingBegan }
|
||||
|
||||
fastForwardTo = null
|
||||
if @playing
|
||||
fastForwardTo = Math.min event.world.firstChangedFrame, @currentFrame
|
||||
|
@ -340,6 +349,7 @@ module.exports = Surface = class Surface extends CocoClass
|
|||
@surfaceLayer.addChild @cameraBorder = new CameraBorder bounds: @camera.bounds
|
||||
@screenLayer.addChild new Letterbox canvasWidth: canvasWidth, canvasHeight: canvasHeight
|
||||
@spriteBoss = new SpriteBoss camera: @camera, surfaceLayer: @surfaceLayer, surfaceTextLayer: @surfaceTextLayer, world: @world, thangTypes: @options.thangTypes, choosing: @options.choosing, navigateToSelection: @options.navigateToSelection, showInvisible: @options.showInvisible
|
||||
@castingScreen ?= new CastingScreen camera: @camera, layer: @screenLayer
|
||||
@stage.enableMouseOver(10)
|
||||
@stage.addEventListener 'stagemousemove', @onMouseMove
|
||||
@stage.addEventListener 'stagemousedown', @onMouseDown
|
||||
|
@ -497,7 +507,7 @@ module.exports = Surface = class Surface extends CocoClass
|
|||
updateState: (frameChanged) ->
|
||||
# world state must have been restored in @updateSpriteSounds
|
||||
@camera.updateZoom()
|
||||
@spriteBoss.update frameChanged
|
||||
@spriteBoss.update frameChanged unless @casting
|
||||
@dimmer?.setSprites @spriteBoss.sprites
|
||||
|
||||
drawCurrentFrame: (e) ->
|
||||
|
@ -508,6 +518,7 @@ module.exports = Surface = class Surface extends CocoClass
|
|||
|
||||
updatePaths: ->
|
||||
return unless @options.paths
|
||||
return if @casting
|
||||
@hidePaths()
|
||||
selectedThang = @spriteBoss.selectedSprite?.thang
|
||||
return if @world.showPaths is 'never'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue