some major game changes
This commit is contained in:
parent
c5da98238d
commit
7456abf80c
3 changed files with 26 additions and 7 deletions
|
@ -96,7 +96,7 @@ class Player extends Entity {
|
|||
handleTick(game) {
|
||||
let { entities, width, height } = game;
|
||||
|
||||
this.headCount += 1 / 200;
|
||||
this.headCount += 1 / 40;
|
||||
|
||||
this.headCount = Math.round(this.headCount * 1000) / 1000;
|
||||
|
||||
|
|
21
game.js
21
game.js
|
@ -9,6 +9,10 @@ import { createHash } from "crypto";
|
|||
|
||||
let db = await initDb();
|
||||
|
||||
function sround(n) {
|
||||
return Math.round(n * 1000) / 1000;
|
||||
}
|
||||
|
||||
class Game extends GameBasic {
|
||||
constructor() {
|
||||
super();
|
||||
|
@ -100,13 +104,22 @@ class Game extends GameBasic {
|
|||
let { entities } = this;
|
||||
let entList = [];
|
||||
for (let entity of entities) {
|
||||
entity.pos = { x: Math.round(entity.pos.x), y: Math.round(entity.pos.y) };
|
||||
entity.vel = { x: Math.round(entity.vel.x), y: Math.round(entity.vel.y) };
|
||||
entity.camera = entity.camera ? { x: Math.round(entity.camera.x), y: Math.round(entity.camera.y) } : false;
|
||||
entity.camera = entity.camera || false;
|
||||
|
||||
let props = entity.serverProps;
|
||||
let basic = props.map(prop => entity[prop]);
|
||||
let str = JSON.stringify(basic);
|
||||
for (let posn in basic) {
|
||||
let posp = basic[posn];
|
||||
if (!posp) continue;
|
||||
if (posp.x && posp.y) {
|
||||
posp.x = sround(posp.x);
|
||||
posp.y = sround(posp.y);
|
||||
}
|
||||
if (typeof posp == 'number') {
|
||||
basic[posn] = sround(posp);
|
||||
}
|
||||
}
|
||||
let str = JSON.stringify(basic,null);
|
||||
|
||||
entList.push({ entity, str, basic });
|
||||
}
|
||||
|
|
|
@ -131,6 +131,9 @@ class Game extends GameBasic {
|
|||
textArgs = [`XY: ${-Math.round(player.camera.x)}, ${-Math.round(player.camera.y)}`, 25, 25];
|
||||
ctx.strokeText(...textArgs);
|
||||
ctx.fillText(...textArgs);
|
||||
textArgs = [`PT: ${Math.round(player.headCount)}`, 25, 75];
|
||||
ctx.strokeText(...textArgs);
|
||||
ctx.fillText(...textArgs);
|
||||
|
||||
if (player.health <= 0 || player.isMenu) {
|
||||
this.doMenu();
|
||||
|
@ -145,7 +148,10 @@ class Game extends GameBasic {
|
|||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.font = "bold 48px sans-serif";
|
||||
if (player.health <= 0) ctx.fillText('You died! Click to respawn', cs / 2, cs / 2);
|
||||
if (player.health <= 0) {
|
||||
ctx.fillText(`You died! Click to respawn\n`, cs / 2, cs / 2);
|
||||
return;
|
||||
}
|
||||
if (player.isMenu) {
|
||||
let r = Math.floor(Math.abs(player.rot / 1.2) % emojis.length);
|
||||
ctx.fillText(`Click to react ${emojis[r]}`, cs / 2, cs / 2)
|
||||
|
|
Loading…
Reference in a new issue