some major game changes
This commit is contained in:
parent
edc5193746
commit
f0afee03ab
3 changed files with 26 additions and 7 deletions
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 });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue