refactors, fix username check
This commit is contained in:
parent
60e579c349
commit
0a9fd2faf9
4 changed files with 196 additions and 166 deletions
113
common/player.js
113
common/player.js
|
@ -50,76 +50,77 @@ class Player extends Entity {
|
|||
|
||||
player.ticks = 0;
|
||||
}
|
||||
handleInt(target) {
|
||||
if (target.you == this.you) return;
|
||||
|
||||
let dist = distF(this, target);
|
||||
|
||||
let dp = (Math.sin(this.rot) * (this.pos.x - target.pos.x))
|
||||
- (Math.cos(this.rot) * (this.pos.y - target.pos.y));
|
||||
|
||||
dp /= Math.sqrt(dist + 0.1);
|
||||
|
||||
if (!(Math.sqrt(dist) < 128 && 1 / dp < -0.2)) return;
|
||||
|
||||
let velness = Math.sqrt(this.vel.x ** 2 + this.vel.y ** 2);
|
||||
|
||||
if (target.type == 'NPC' && velness > 0.2 && this.ticks >= 15) {
|
||||
this.isMenu = true;
|
||||
this.rot = 1.2;
|
||||
}
|
||||
|
||||
if (target.type == 'Shooter') {
|
||||
this.health -= 1;
|
||||
}
|
||||
|
||||
if (target.immortal) return;
|
||||
|
||||
let oldHealth = target.health
|
||||
|
||||
let dmg = Math.floor((dp - 0.001) * 10);
|
||||
|
||||
target.health += Math.floor((dp - 0.001) * 10);
|
||||
|
||||
target.vel.x += (target.pos.x - this.pos.x) * 0.1;
|
||||
target.vel.y += (target.pos.y - this.pos.y) * 0.1;
|
||||
|
||||
if (target.health <= 0 && oldHealth > 0) {
|
||||
console.log(`Player ${target.you} died to a player ${this.you}`);
|
||||
this.health -= dmg;
|
||||
if (this.health > 100) this.health = 100;
|
||||
this.headCount += 500;
|
||||
}
|
||||
}
|
||||
handleTick(game) {
|
||||
|
||||
let { entities, width, height } = game;
|
||||
|
||||
let ent = this;
|
||||
ent.headCount += 1/200;
|
||||
this.headCount += 1 / 200;
|
||||
|
||||
ent.headCount = Math.round(ent.headCount * 1000) / 1000;
|
||||
this.headCount = Math.round(this.headCount * 1000) / 1000;
|
||||
|
||||
if (ent.health <= 0) return;
|
||||
if (this.health <= 0) return;
|
||||
|
||||
ent.pos.x += ent.vel.x;
|
||||
ent.pos.y += ent.vel.y;
|
||||
this.pos.x += this.vel.x;
|
||||
this.pos.y += this.vel.y;
|
||||
|
||||
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);
|
||||
this.pos.x = Math.max(Math.min(this.pos.x, width / 2), - width / 2);
|
||||
this.pos.y = Math.max(Math.min(this.pos.y, height / 2), - height / 2);
|
||||
|
||||
ent.bounce(game);
|
||||
this.bounce(game);
|
||||
|
||||
ent.vel.x *= 0.9;
|
||||
ent.vel.y *= 0.9;
|
||||
this.vel.x *= 0.9;
|
||||
this.vel.y *= 0.9;
|
||||
|
||||
ent.rot += 0.03 * ent.dir;
|
||||
ent.rot = ent.rot % (Math.PI * 10);
|
||||
this.rot += 0.03 * this.dir;
|
||||
this.rot = this.rot % (Math.PI * 10);
|
||||
|
||||
ent.camera.x = -ent.pos.x * 0.1 + ent.camera.x * 0.9;
|
||||
ent.camera.y = -ent.pos.y * 0.1 + ent.camera.y * 0.9;
|
||||
this.camera.x = -this.pos.x * 0.1 + this.camera.x * 0.9;
|
||||
this.camera.y = -this.pos.y * 0.1 + this.camera.y * 0.9;
|
||||
|
||||
ent.ticks++;
|
||||
|
||||
let velness = Math.sqrt(ent.vel.x ** 2 + ent.vel.y ** 2);
|
||||
this.ticks++;
|
||||
|
||||
for (let target of entities) {
|
||||
if (target.you == ent.you) continue;
|
||||
|
||||
let dist = distF(ent, target);
|
||||
|
||||
let dp = (Math.sin(ent.rot) * (ent.pos.x - target.pos.x))
|
||||
- (Math.cos(ent.rot) * (ent.pos.y - target.pos.y));
|
||||
|
||||
dp /= Math.sqrt(dist + 0.1);
|
||||
|
||||
if (Math.sqrt(dist) < 128 && 1 / dp < -0.2) {
|
||||
if (target.type == 'NPC' && velness > 0.2 && ent.ticks >= 15) {
|
||||
ent.isMenu = true;
|
||||
ent.rot = 1.2;
|
||||
}
|
||||
|
||||
if (target.type == 'Shooter') {
|
||||
this.health -= 1;
|
||||
}
|
||||
|
||||
if (target.immortal) continue;
|
||||
|
||||
let oldHealth = target.health
|
||||
|
||||
let dmg = 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;
|
||||
|
||||
if (target.health <= 0 && oldHealth > 0) {
|
||||
console.log(`Player ${target.you} died to a player ${ent.you}`);
|
||||
ent.health -= dmg;
|
||||
if (ent.health > 100) ent.health = 100;
|
||||
ent.headCount += 500;
|
||||
}
|
||||
}
|
||||
this.handleInt(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue