KO and HP above user
This commit is contained in:
parent
506e6be65d
commit
873102a927
5 changed files with 95 additions and 47 deletions
|
@ -1,4 +1,14 @@
|
|||
function Player(you) {
|
||||
function distF(ent, target) {
|
||||
return ((ent.pos.x - target.pos.x) ** 2) + ((ent.pos.y - target.pos.y) ** 2)
|
||||
}
|
||||
|
||||
function uuidv4() {
|
||||
return "#000000-000000".replace(/[018]/g, c =>
|
||||
(+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
|
||||
);
|
||||
}
|
||||
|
||||
function Player(you, isPlayer) {
|
||||
let pos = { x: Math.random() * 5000 - 50, y: Math.random() * 5000 - 50 };
|
||||
let camera = { x: -pos.x, y: -pos.y };
|
||||
let vel = { x: 0, y: 0 };
|
||||
|
@ -12,7 +22,11 @@ function Player(you) {
|
|||
|
||||
this.health = 100;
|
||||
|
||||
this.you = you;
|
||||
this.you = you || uuidv4();
|
||||
|
||||
this.isPlayer = isPlayer;
|
||||
|
||||
this.headCount = 0;
|
||||
}
|
||||
|
||||
Player.prototype.bump = function () {
|
||||
|
@ -31,11 +45,13 @@ Player.prototype.bump = function () {
|
|||
player.ticks = 0;
|
||||
}
|
||||
|
||||
Player.prototype.handleTick = function(game) {
|
||||
let { player } = game;
|
||||
Player.prototype.handleTick = function (game) {
|
||||
let { entities } = game;
|
||||
|
||||
let ent = this;
|
||||
|
||||
if (ent.health <= 0) return;
|
||||
|
||||
ent.pos.x += ent.vel.x;
|
||||
ent.pos.y += ent.vel.y;
|
||||
|
||||
|
@ -50,22 +66,22 @@ Player.prototype.handleTick = function(game) {
|
|||
|
||||
ent.ticks++;
|
||||
|
||||
let dist = ((ent.pos.x - player.pos.x) ** 2) + ((ent.pos.y - player.pos.y) ** 2);
|
||||
for (let target of entities) {
|
||||
if (target.you == ent.you) continue;
|
||||
|
||||
let dp = (Math.sin(ent.rot) * (ent.pos.x - player.pos.x))
|
||||
- (Math.cos(ent.rot) * (ent.pos.y - player.pos.y));
|
||||
let dist = distF(ent, target);
|
||||
|
||||
dp /= dist;
|
||||
let dp = (Math.sin(ent.rot) * (ent.pos.x - target.pos.x))
|
||||
- (Math.cos(ent.rot) * (ent.pos.y - target.pos.y));
|
||||
|
||||
dp *= 10;
|
||||
dp /= Math.sqrt(dist + 0.1);
|
||||
|
||||
if (ent.you) return;
|
||||
if (Math.sqrt(dist) < 128 && 1 / dp < -0.2) {
|
||||
target.health--;
|
||||
|
||||
if (Math.random() < -dp && Math.random() > 3 / (ent.ticks+2)) {
|
||||
ent.bump();
|
||||
}
|
||||
|
||||
if (Math.sqrt(dist) < 96 / 2) {
|
||||
player.health --;
|
||||
if (target.health == 0) {
|
||||
ent.headCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue