diff --git a/lib/State.js b/lib/State.js new file mode 100644 index 0000000..8e0b082 --- /dev/null +++ b/lib/State.js @@ -0,0 +1,29 @@ +class State { + constructor(state) { + this.set(state); + } + + set(state) { + this.last = this.state; + this.state = state; + this.time = 0; + this.justSetState = true; + } + + update(dt) { + this.first = this.justSetState; + this.justSetStrate = false; + + this.time += this.first ? 0 : dt; + } + + is(state) { + return this.state === state; + } + + isIn(...states) { + return states.some(s => this.is(s)); + } +} + +module.exports = State; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 69dbb61..eb5557f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,6 +7,7 @@ var AnimManager = require("./AnimManager.js"), entity = require("./utilities/entity.js"), wallslide = require("./movement/wallslide.js"), deadInTracks = require("./movement/deadInTracks.js"), + State = require("./State.js"), Sound = require("./sound/Sound.js"), Rect = require("./Rect.js"), KeyControls = require("./controls/KeyControls.js"), @@ -31,6 +32,7 @@ module.exports = { entity, wallslide, deadInTracks, + State, Sound, Rect, KeyControls, diff --git a/package-lock.json b/package-lock.json index 5c6eebe..c5fc41a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -227,6 +227,14 @@ "esutils": "^2.0.2" } }, + "easystarjs": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/easystarjs/-/easystarjs-0.4.3.tgz", + "integrity": "sha512-1h+ICk/I8gmdwaDjlP7q02LgOfcMH01FMDpJVD1ig//oYPmfFMnCZR2DNqajTD9v7JfVrJdqZuZO7TX2DdNQ6A==", + "requires": { + "heap": "0.2.6" + } + }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -470,6 +478,11 @@ "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "dev": true }, + "heap": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/heap/-/heap-0.2.6.tgz", + "integrity": "sha1-CH4fELBGky/IWU3Z5tN4r8nR5aw=" + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", diff --git a/package.json b/package.json index b164c0b..2d79854 100644 --- a/package.json +++ b/package.json @@ -20,5 +20,8 @@ "license": "ISC", "devDependencies": { "eslint": "^6.8.0" + }, + "dependencies": { + "easystarjs": "^0.4.3" } }