Skip to content

Commit

Permalink
Reengage surrounding objects on door open
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Applegate committed Dec 1, 2012
1 parent 9ee3516 commit b430f94
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions public/coffee/models/DoorEntity.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ define ['cs!models/StaticEntity', 'image!/img/level-asset-door.png'], (StaticEnt
class DoorEntity extends StaticEntity

isOpen: false
engaged: false

template:
type: 'static'
Expand All @@ -28,16 +29,34 @@ define ['cs!models/StaticEntity', 'image!/img/level-asset-door.png'], (StaticEnt
eventNameBase = @entity._name
@canvas.bind(eventNameBase + '.open', @onOpen)
@canvas.bind(eventNameBase + '.close', @onClose)
@canvas.bind(eventNameBase + '.disengage', @onDisengage)
@

onOpen: =>
if @engaged then return
@engaged = true
@canvas.trigger 'door.sound' unless @isOpen
@isOpen = true
do @jostleNearby
@entity.position {x:9999, y:9999}
console.log @entity.position()

onClose: =>
if @engaged then return
@canvas.trigger 'door.sound' unless not @isOpen
@entity.position @originalPosition
@isOpen = false

onDisengage: =>
@engaged = false

jostleNearby: =>
pos = @entity.position()
x1 = pos.x - @overrides.width
x2 = pos.x + @overrides.width
y1 = pos.y - .3
y2 = pos.y + .3
targets = @world.find x1, y1, x2, y2
target.applyImpulse(1, 0, 1) for target in targets

return DoorEntity

0 comments on commit b430f94

Please sign in to comment.