diff options
Diffstat (limited to 'Homework/cs5410/bbiy/src/entities/entity.js')
| -rw-r--r-- | Homework/cs5410/bbiy/src/entities/entity.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Homework/cs5410/bbiy/src/entities/entity.js b/Homework/cs5410/bbiy/src/entities/entity.js new file mode 100644 index 0000000..3da032c --- /dev/null +++ b/Homework/cs5410/bbiy/src/entities/entity.js @@ -0,0 +1,23 @@ +game.nextId = 0; + +game.Entity = (id=game.nextId++) => { + const components = {}; + + const addComponent = (component) => { + components[component.name] = component; + }; + const hasComponent = (componentName) => components[componentName] !== undefined; + const removeComponent = (componentName) => { + if (hasComponent(componentName)) { + delete components[componentName]; + } + }; + + return { + id, + components, + addComponent, + removeComponent, + hasComponent + }; +}
\ No newline at end of file |
