add emotes and npcs. this really needs a cleanup
This commit is contained in:
parent
da4b0f5df8
commit
f8b014507f
11 changed files with 267 additions and 85 deletions
30
common/npc.js
Normal file
30
common/npc.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
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;
|
||||
}
|
||||
handleTick(game) {
|
||||
let { entities } = game;
|
||||
|
||||
let rEntity = entities[Math.floor(Math.random() * entities.length)];
|
||||
|
||||
this.vel.x += (rEntity.pos.x - this.pos.x) * 0.0001;
|
||||
this.vel.y += (rEntity.pos.y - this.pos.y) * 0.0001;
|
||||
|
||||
this.pos.x += this.vel.x;
|
||||
this.pos.y += this.vel.y;
|
||||
}
|
||||
}
|
||||
|
||||
export default NPC;
|
Loading…
Add table
Add a link
Reference in a new issue