Skip to content

Instantly share code, notes, and snippets.

@nakosung
Created August 16, 2013 05:35
Show Gist options
  • Save nakosung/6247548 to your computer and use it in GitHub Desktop.
Save nakosung/6247548 to your computer and use it in GitHub Desktop.
Layer.tick : (dT) ->
sprite_nodes.map (s) ->
loc = s.getLocation()
unless s.vel?
s.vel = cc.p (Math.random() - 0.5) * 10, (Math.random() - 0.5) * 10
s.setLocation cc.p loc.x + s.vel.x * dT, loc.y + s.vel.y * dT
bboxes = sprite_nodes.map (n) -> n.getBoundingBox()
for i in [0..bbox.length-1]
for j in [i+1...bbox.length-1]
if cc.rectContainsRect bboxes[i], bboxes[j]
sprite_nodes[i].vel = cc.p 0, 0
sprite_nodes[j].vel = cc.p 0, 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment