make npcs less annoying
This commit is contained in:
parent
7d83d31746
commit
276e11fb49
6 changed files with 45 additions and 30 deletions
|
@ -1,14 +1,12 @@
|
|||
import { distF, uuidv4 } from './util.js'
|
||||
import Entity from './entity.js';
|
||||
|
||||
class Player {
|
||||
class Player extends Entity {
|
||||
constructor(you, isPlayer, game = false) {
|
||||
let pos = { x: (Math.random() - 0.5) * (game ? game.width : 1000), y:(Math.random() - 0.5) * (game ? game.height : 1000) };
|
||||
let camera = { x: -pos.x, y: -pos.y };
|
||||
let vel = { x: 0, y: 0 };
|
||||
super(game);
|
||||
|
||||
this.camera = { x: -this.pos.x, y: -this.pos.y };
|
||||
|
||||
this.camera = camera;
|
||||
this.pos = pos;
|
||||
this.vel = vel;
|
||||
this.rot = 0;
|
||||
this.dir = 1;
|
||||
this.ticks = 0;
|
||||
|
@ -65,13 +63,7 @@ class Player {
|
|||
ent.pos.x = Math.max(Math.min(ent.pos.x, width / 2), - width / 2);
|
||||
ent.pos.y = Math.max(Math.min(ent.pos.y, height / 2), - height / 2);
|
||||
|
||||
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);
|
||||
}
|
||||
ent.bounce(game);
|
||||
|
||||
ent.vel.x *= 0.9;
|
||||
ent.vel.y *= 0.9;
|
||||
|
@ -97,7 +89,7 @@ class Player {
|
|||
dp /= Math.sqrt(dist + 0.1);
|
||||
|
||||
if (Math.sqrt(dist) < 128 && 1 / dp < -0.2) {
|
||||
if (target.type == 'NPC' && velness > 0.2) {
|
||||
if (target.type == 'NPC' && velness > 0.2 && ent.ticks >= 15) {
|
||||
ent.isMenu = true;
|
||||
ent.rot = 1.2;
|
||||
}
|
||||
|
@ -105,9 +97,9 @@ class Player {
|
|||
|
||||
let oldHealth = target.health
|
||||
|
||||
let dmg = Math.floor( (dp-0.001) * 10);
|
||||
let dmg = Math.floor((dp - 0.001) * 10);
|
||||
|
||||
target.health += Math.floor( (dp-0.001) * 10);
|
||||
target.health += Math.floor((dp - 0.001) * 10);
|
||||
|
||||
target.vel.x += (target.pos.x - ent.pos.x) * 0.1;
|
||||
target.vel.y += (target.pos.y - ent.pos.y) * 0.1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue