setting up status effecs on mobs

This commit is contained in:
lilgreenland
2020-03-06 14:28:21 -08:00
parent 1fa80ecc79
commit d13c4e1ca8
5 changed files with 33 additions and 14 deletions

View File

@@ -7,6 +7,11 @@ const mobs = {
while (i--) {
if (mob[i].alive) {
mob[i].do();
// let j = mob[i].status.length;
// while (j--) {
// mob[i].status[j].effect();
// if (mob[i].status[j].endCycle > game.cycle) mob[i].status.splice(j, 0);
// }
} else {
mob[i].replace(i); //removing mob and replace with body, this is done here to avoid an array index bug with drawing I think
}
@@ -97,6 +102,14 @@ const mobs = {
x: xPos,
y: yPos
},
status: [], // [ { effect(), endCycle } ]
checkStatus() {
let j = this.status.length;
while (j--) {
this.status[j].effect();
if (this.status[j].endCycle < game.cycle) this.status.splice(j, 1);
}
},
seeAtDistance2: 4000000, //sqrt(4000000) = 2000 = max seeing range
distanceToPlayer() {
const dx = this.position.x - player.position.x;