make npcs less annoying
This commit is contained in:
parent
7d83d31746
commit
276e11fb49
6 changed files with 45 additions and 30 deletions
23
common/entity.js
Normal file
23
common/entity.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
class Entity {
|
||||
constructor(game) {
|
||||
let pos = { x: (Math.random() - 0.5) * (game ? game.width : 1000), y: (Math.random() - 0.5) * (game ? game.height : 1000) };
|
||||
let vel = { x: 0, y: 0 };
|
||||
|
||||
this.pos = pos;
|
||||
this.vel = vel;
|
||||
}
|
||||
bounce(game) {
|
||||
let ent = this;
|
||||
let { width, height } = game;
|
||||
|
||||
if (Math.abs(ent.pos.x) >= width / 2) {
|
||||
ent.vel.x = (Math.abs(ent.vel.x) + 10) * -Math.sign(ent.pos.x);
|
||||
}
|
||||
|
||||
if (Math.abs(ent.pos.y) >= height / 2) {
|
||||
ent.vel.y = (Math.abs(ent.vel.y) + 10) * -Math.sign(ent.pos.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Entity;
|
Loading…
Add table
Add a link
Reference in a new issue