make npcs less annoying

This commit is contained in:
biglyderv 2024-11-25 14:14:21 -05:00
parent 7d83d31746
commit 276e11fb49
6 changed files with 45 additions and 30 deletions

View file

@ -1,12 +1,9 @@
import { distF, uuidv4 } from './util.js'
import Entity from "./entity.js";
class NPC {
constructor(you) {
let pos = { x: Math.random() * 1000 - 50, y: Math.random() * 1000 - 50 };
let vel = { x: 0, y: 0 };
this.pos = pos;
this.vel = vel;
class NPC extends Entity {
constructor(you, game = false) {
super(game);
this.you = you || uuidv4();
@ -38,14 +35,16 @@ class NPC {
let distX = (this.destX - this.pos.x);
let distY = (this.destY - this.pos.y)
this.vel.x += (distX + distY * this.rFac / 1000) * 0.001;
this.vel.y += (distY - distX * this.rFac / 1000) * 0.001;
this.vel.x += (distX + distY * this.rFac / 1000) * 0.0003;
this.vel.y += (distY - distX * this.rFac / 1000) * 0.0003;
this.vel.x *= 0.8;
this.vel.y *= 0.8;
this.vel.x *= 0.98;
this.vel.y *= 0.98;
this.pos.x += this.vel.x;
this.pos.y += this.vel.y;
this.bounce(game);
}
}