From 10af6cf109ff4ab3ef08efb4615c08dfb36bb04e Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Tue, 26 May 2020 15:37:24 +0200 Subject: [PATCH] Added Gamestates (wip) and EasyStarJS --- lib/State.js | 29 +++++++++++++++++++++++++++++ lib/index.js | 2 ++ package-lock.json | 13 +++++++++++++ package.json | 3 +++ 4 files changed, 47 insertions(+) create mode 100644 lib/State.js 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" } }