import { distF, uuidv4 } from './util.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; 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.001; this.vel.y += (distY - distX * this.rFac / 1000) * 0.001; this.vel.x *= 0.8; this.vel.y *= 0.8; this.pos.x += this.vel.x; this.pos.y += this.vel.y; } } export default NPC;