Skip to content

Instantly share code, notes, and snippets.

@TheSeamau5
Created December 30, 2014 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheSeamau5/129cf4e0ebd327c7622e to your computer and use it in GitHub Desktop.
Save TheSeamau5/129cf4e0ebd327c7622e to your computer and use it in GitHub Desktop.
Example of using updateComponent
Vector = (x,y) ->
x : x || 0,
y : y || 0
vAdd = (v,w) -> Vector (v.x + w.x), (v.y + w.y)
clone = (obj) ->
if not obj? or typeof obj isnt 'object'
return obj
newInstance = new obj.constructor()
for key of obj
newInstance[key] = clone obj[key]
return newInstance
updateComponent = (updater, componentName, entity, requirementList) ->
requirementList = requirementList || [];
if (requirementList[requirement] for requirement in requirementList)?
output = clone entity
output[componentName] = updater output[componentName], output
return output
updatePosition = (entity) ->
updateComponent ((component, entity) -> vAdd component , entity.velocity) ,
"position" ,
entity ,
["position", "velocity"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment