mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 08:50:58 -05:00
Fix wall collision coalescing code
This commit is contained in:
parent
ab29f7e10e
commit
42e1ab6c99
1 changed files with 7 additions and 1 deletions
|
@ -72,8 +72,12 @@ module.exports.downTheChain = downTheChain = (obj, keyChain, newValue=undefined)
|
|||
module.exports.now = (if window?.performance?.now? then (-> window.performance.now()) else (-> new Date()))
|
||||
|
||||
module.exports.consolidateThangs = consolidateThangs = (thangs) ->
|
||||
# We can gain a performance increase by consolidating all regular walls into a minimal covering, non-intersecting set a la Gridmancer.
|
||||
debug = false
|
||||
isStructural = (t) -> t.stateless and t.collides and t.collisionCategory is 'obstacles' and t.shape in ['box', 'sheet'] and t.restitution is 1.5 and (t.pos.x - t.width / 2 >= 0) and (t.pos.y - t.height / 2 >= 0)
|
||||
isStructural = (t) ->
|
||||
t.stateless and t.collides and t.collisionCategory is 'obstacles' and t.shape in ['box', 'sheet'] and # Can only do wall-like obstacle Thangs.
|
||||
t.spriteName isnt 'Ice Wall' and t.restitution is 1.0 and # Fixed restitution value on 2016-03-15, but it causes discrepancies, so disabled for Kelvintaph levels.
|
||||
(t.pos.x - t.width / 2 >= 0) and (t.pos.y - t.height / 2 >= 0) # Grid doesn't handle negative numbers, so don't coalesce walls below/left of 0, 0.
|
||||
structural = _.remove thangs, isStructural
|
||||
return unless structural.length
|
||||
rightmost = _.max structural, (t) -> t.pos.x + t.width / 2
|
||||
|
@ -101,7 +105,9 @@ module.exports.consolidateThangs = consolidateThangs = (thangs) ->
|
|||
thang.pos.y = rect.y
|
||||
thang.width = rect.width
|
||||
thang.height = rect.height
|
||||
thang.destroyBody()
|
||||
thang.createBodyDef()
|
||||
thang.createBody()
|
||||
dissection.push thang
|
||||
|
||||
dissectRectangles grid, addStructuralThang, false, debug
|
||||
|
|
Loading…
Reference in a new issue