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;

View file

@ -68,6 +68,8 @@ class Player {
ent.ticks++;
let velness = Math.sqrt(ent.vel.x ** 2 + ent.vel.y ** 2);
for (let target of entities) {
if (target.you == ent.you) continue;
@ -79,7 +81,7 @@ class Player {
dp /= Math.sqrt(dist + 0.1);
if (Math.sqrt(dist) < 128 && 1 / dp < -0.2) {
if (target.type == 'NPC') {
if (target.type == 'NPC' && velness > 0.2) {
ent.isMenu = true;
}
if (target.immortal) continue;