import { distF, uuidv4 } from './util.js' import Entity from "./entity.js"; class NPC extends Entity { constructor(you, game = false) { super(game); this.you = you || uuidv4(); this.type = 'NPC'; this.immortal = true; this.serverProps = [ 'type', 'pos', 'vel', 'you', 'immortal', 'destX', 'destY', 'ticks', 'rFac' ]; this.ticks = 601; this.rFac = Math.random() * 100; this.destX = 0; this.destY = 0; } handleTick(game) { this.ticks++; if (this.ticks >= this.rFac * 10) { this.ticks = 0; this.rFac = (this.rFac * 2385 + 293) % 100; this.destX = Math.sin(this.rFac) * ((this.rFac / 100) ** 4) * game.width; this.destY = Math.cos(this.rFac) * ((this.rFac / 100) ** 4) * game.height; } let distX = (this.destX - this.pos.x); let distY = (this.destY - this.pos.y) this.vel.x += (distX + distY * this.rFac / 1000) * 0.0003; this.vel.y += (distY - distX * this.rFac / 1000) * 0.0003; 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); } } export default NPC;