From 100bbecccbf7b5e09ee60d1c2934df09006344f1 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Fri, 1 Apr 2022 17:12:37 -0600 Subject: Fix sprites --- src/entities/bigblue.js | 13 +++++++++++++ src/entities/entity.js | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/entities/bigblue.js create mode 100644 src/entities/entity.js (limited to 'src/entities') diff --git a/src/entities/bigblue.js b/src/entities/bigblue.js new file mode 100644 index 0000000..475740e --- /dev/null +++ b/src/entities/bigblue.js @@ -0,0 +1,13 @@ +game.createBigBlue = () => { + const bigBlue = game.Entity(); + bigBlue.addComponent(game.components.Position({x: 0, y: 0})); + bigBlue.addComponent(game.components.Appearance({rot: 0, width: 100, height: 100})); + bigBlue.sprite = game.graphics.Sprite({ + image: game.assets.bigblue, + spriteHeight: 24, + spriteWidth: 24, + numFrames: 3, + timePerFrame: 100, + }); + return bigBlue; +} \ No newline at end of file diff --git a/src/entities/entity.js b/src/entities/entity.js new file mode 100644 index 0000000..33d1031 --- /dev/null +++ b/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 removeComponent = (component) => { + delete components[component.name]; + } + const hasComponent = (component) => { + components[component.name] !== undefined; + } + + return { + id, + components, + addComponent, + removeComponent, + hasComponent + }; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2