better logging

This commit is contained in:
biglyderv 2024-11-25 14:14:20 -05:00
parent d9daef380e
commit 13cd3db387
3 changed files with 22 additions and 8 deletions

View file

@ -34,7 +34,7 @@ class Player {
]; ];
this.legalProps = [ this.legalProps = [
'vel', 'dir', 'camera', 'ticks', 'isMenu', 'r' 'vel', 'dir', 'camera', 'ticks', 'isMenu', 'r', 'ref'
]; ];
} }
bump() { bump() {
@ -44,8 +44,6 @@ class Player {
player.dir *= -1; player.dir *= -1;
} }
console.log(player.ticks)
player.vel.x *= 0.3; player.vel.x *= 0.3;
player.vel.y *= 0.3; player.vel.y *= 0.3;
@ -113,6 +111,7 @@ class Player {
target.vel.y += (target.pos.y - ent.pos.y) * 0.1; target.vel.y += (target.pos.y - ent.pos.y) * 0.1;
if (target.health <= 0 && oldHealth > 0) { if (target.health <= 0 && oldHealth > 0) {
console.log(`Player ${target.you} died to a player ${ent.you}`);
ent.headCount++; ent.headCount++;
} }
} }

View file

@ -25,7 +25,7 @@ app.ws('/', function (ws, req) {
ws.ent = player; ws.ent = player;
// This will only work under NGINX. // This will only work under NGINX.
console.log(`A player ${player.you} joined under IP ${req.headers["x-real-ip"]}`) console.log(`Player ${player.you} joined under IP ${req.headers["x-real-ip"]}`)
ws.on('message', function message(msg) { ws.on('message', function message(msg) {
let data = {}; let data = {};
@ -49,12 +49,17 @@ app.ws('/', function (ws, req) {
let you2 = newEnt.you; let you2 = newEnt.you;
if (you != you2) { if (you != you2) {
console.log(`A player ${you} now identifies as ${you2}`); console.log(`Player ${you} now identifies as ${you2}`);
}
if (newEnt.ref) {
console.log(`Player ${you2} discovered this game from ${newEnt.ref}`);
newEnt.ref = undefined;
} }
}) })
ws.on('close', function () { ws.on('close', function () {
console.log(`A player ${game.entities[playerI].you} left`); console.log(`Player ${game.entities[playerI].you} left`);
ws.active = false; ws.active = false;
player.health = -1; player.health = -1;
}) })

View file

@ -135,9 +135,15 @@ class Game extends GameBasic {
this.sync(); this.sync();
} }
} }
sync() { sync(first = false) {
let { player } = this; let { player } = this;
if (first) {
player.ref = new URL(window.location).searchParams.get('ref') || 'nobody';
} else {
player.ref = false;
}
this.ws.send(JSON.stringify(player.legalProps.map(prop => player[prop]))); this.ws.send(JSON.stringify(player.legalProps.map(prop => player[prop])));
} }
recv({ data }) { recv({ data }) {
@ -215,8 +221,12 @@ class Game extends GameBasic {
this.ws.addEventListener('message', function (e) { that.recv(e) }); this.ws.addEventListener('message', function (e) { that.recv(e) });
setInterval(function () { that.render() }, 1000 / 60); this.ws.addEventListener('open', function () {
that.sync(true);
setInterval(function () { that.sync() }, 1000 / 5); setInterval(function () { that.sync() }, 1000 / 5);
})
setInterval(function () { that.render() }, 1000 / 60);
game.canvas.onclick = () => that.click(); game.canvas.onclick = () => that.click();
} }