Added Gamestates (wip) and EasyStarJS

This commit is contained in:
Arne van Iterson 2020-05-26 15:37:24 +02:00
parent 782f2f6eff
commit 10af6cf109
4 changed files with 47 additions and 0 deletions

29
lib/State.js Normal file
View File

@ -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;

View File

@ -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,

13
package-lock.json generated
View File

@ -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",

View File

@ -20,5 +20,8 @@
"license": "ISC",
"devDependencies": {
"eslint": "^6.8.0"
},
"dependencies": {
"easystarjs": "^0.4.3"
}
}