some fixes

This commit is contained in:
biglyderv 2024-11-25 14:14:20 -05:00
parent f8b014507f
commit 656f06291c
3 changed files with 31 additions and 19 deletions

View file

@ -11,13 +11,18 @@ class NPC {
this.you = you || uuidv4();
this.type = 'NPC';
this.immortal = true;
}
handleTick(game) {
let { entities } = game;
let rEntity = entities[Math.floor(Math.random() * entities.length)];
let rEntity, i = 0;
while ((!rEntity || rEntity.type != 'Player') && i < 100) {
rEntity = entities[Math.floor(Math.random() * entities.length)];
i++;
}
this.vel.x += (rEntity.pos.x - this.pos.x) * 0.0001;
this.vel.y += (rEntity.pos.y - this.pos.y) * 0.0001;