mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 10:06:08 -05:00
Added radii marks for voiceRange, visualRange and attackRange
This commit is contained in:
parent
4ad0fba860
commit
d186ae0a15
2 changed files with 81 additions and 4 deletions
|
@ -71,6 +71,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
@stillLoading = true
|
||||
@thangType.fetch()
|
||||
@thangType.once 'sync', @setupSprite, @
|
||||
@createMarks()
|
||||
|
||||
setupSprite: ->
|
||||
@stillLoading = false
|
||||
|
@ -410,12 +411,34 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
pos.y *= @thang.scaleFactorY ? scaleFactor
|
||||
pos
|
||||
|
||||
createMarks: ->
|
||||
if @thang
|
||||
allProps = []
|
||||
allProps = allProps.concat (@thang.hudProperties ? [])
|
||||
allProps = allProps.concat (@thang.programmableProperties ? [])
|
||||
allProps = allProps.concat (@thang.moreProgrammableProperties ? [])
|
||||
|
||||
@addMark('voiceradius') if 'voiceRange' in allProps
|
||||
@addMark('visualradius') if 'visualRange' in allProps
|
||||
@addMark('attackradius') if 'attackRange' in allProps
|
||||
|
||||
@addMark('bounds').toggle true if @thang?.drawsBounds
|
||||
@addMark('shadow').toggle true unless @thangType.get('shadow') is 0
|
||||
|
||||
updateMarks: ->
|
||||
return unless @options.camera
|
||||
@addMark 'repair', null, 'repair' if @thang?.errorsOut
|
||||
@marks.repair?.toggle @thang?.errorsOut
|
||||
@addMark('bounds').toggle true if @thang?.drawsBounds
|
||||
@addMark('shadow').toggle true unless @thangType.get('shadow') is 0
|
||||
|
||||
if @selected
|
||||
@marks.voiceradius?.toggle true
|
||||
@marks.visualradius?.toggle true
|
||||
@marks.attackradius?.toggle true
|
||||
else
|
||||
@marks.voiceradius?.toggle false
|
||||
@marks.visualradius?.toggle false
|
||||
@marks.attackradius?.toggle false
|
||||
|
||||
mark.update() for name, mark of @marks
|
||||
#@thang.effectNames = ['berserk', 'confuse', 'control', 'curse', 'fear', 'poison', 'paralyze', 'regen', 'sleep', 'slow', 'haste']
|
||||
@updateEffectMarks() if @thang?.effectNames?.length or @previousEffectNames?.length
|
||||
|
|
|
@ -55,6 +55,9 @@ module.exports = class Mark extends CocoClass
|
|||
if @name is 'bounds' then @buildBounds()
|
||||
else if @name is 'shadow' then @buildShadow()
|
||||
else if @name is 'debug' then @buildDebug()
|
||||
else if @name is 'voiceradius' then @buildRadius('voice')
|
||||
else if @name is 'visualradius' then @buildRadius('visual')
|
||||
else if @name is 'attackradius' then @buildRadius('attack')
|
||||
else if @thangType then @buildSprite()
|
||||
else console.error "Don't know how to build mark for", @name
|
||||
@mark?.mouseEnabled = false
|
||||
|
@ -114,8 +117,59 @@ module.exports = class Mark extends CocoClass
|
|||
@mark.layerIndex = 10
|
||||
#@mark.cache 0, 0, diameter, diameter # not actually faster than simple ellipse draw
|
||||
|
||||
buildRadius: ->
|
||||
return # not implemented
|
||||
buildRadius: (type) ->
|
||||
return if type is 'voice' and @sprite.thang.voiceRange > 9000
|
||||
return if type is 'visual' and @sprite.thang.visualRange > 9000
|
||||
return if type is 'attack' and @sprite.thang.attackRange > 9000
|
||||
|
||||
colors =
|
||||
voice: "rgba(0, 145, 0, alpha)"
|
||||
visual: "rgba(0, 0, 145, alpha)"
|
||||
attack: "rgba(145, 0, 0, alpha)"
|
||||
|
||||
color = colors[type]
|
||||
|
||||
@mark = new createjs.Shape()
|
||||
@mark.graphics.beginFill color.replace('alpha', 0.4)
|
||||
|
||||
if type is 'voice'
|
||||
r = @sprite.thang.voiceRange
|
||||
ranges = [
|
||||
r,
|
||||
if 'visualradius' of @sprite.marks and @sprite.thang.visualRange < 9001 then @sprite.thang.visualRange else 0,
|
||||
if 'attackradius' of @sprite.marks and @sprite.thang.attackRange < 9001 then @sprite.thang.attackRange else 0
|
||||
]
|
||||
else if type is 'visual'
|
||||
r = @sprite.thang.visualRange
|
||||
ranges = [
|
||||
r,
|
||||
if 'attackradius' of @sprite.marks and @sprite.thang.attackRange < 9001 then @sprite.thang.attackRange else 0,
|
||||
if 'voiceradius' of @sprite.marks and @sprite.thang.voiceRange < 9001 then @sprite.thang.voiceRange else 0,
|
||||
]
|
||||
else if type is 'attack'
|
||||
r = @sprite.thang.attackRange
|
||||
ranges = [
|
||||
r,
|
||||
if 'voiceradius' of @sprite.marks and @sprite.thang.voiceRange < 9001 then @sprite.thang.voiceRange else 0,
|
||||
if 'visualradius' of @sprite.marks and @sprite.thang.visualRange < 9001 then @sprite.thang.visualRange else 0
|
||||
]
|
||||
|
||||
# Draw the outer circle
|
||||
@mark.graphics.drawCircle 0, 0, r * Camera.PPM
|
||||
|
||||
# Cut out the inner circle
|
||||
if Math.max(ranges['1'], ranges['2']) < r
|
||||
@mark.graphics.arc 0, 0, Math.max(ranges['1'], ranges['2']) * Camera.PPM, Math.PI*2, 0, true
|
||||
else if Math.min(ranges['1'], ranges['2']) < r
|
||||
@mark.graphics.arc 0, 0, Math.min(ranges['1'], ranges['2']) * Camera.PPM, Math.PI*2, 0, true
|
||||
|
||||
# Add perspective
|
||||
@mark.scaleY *= @camera.y2x
|
||||
|
||||
@mark.graphics.endStroke()
|
||||
@mark.graphics.endFill()
|
||||
|
||||
return
|
||||
|
||||
buildDebug: ->
|
||||
@mark = new createjs.Shape()
|
||||
|
|
Loading…
Reference in a new issue