Created
December 30, 2014 04:30
-
-
Save TheSeamau5/129cf4e0ebd327c7622e to your computer and use it in GitHub Desktop.
Example of using updateComponent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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