bump sync fix for real
This commit is contained in:
parent
6c05369ef8
commit
e84027150e
3 changed files with 14 additions and 12 deletions
|
@ -34,10 +34,12 @@ function Player(you, isPlayer) {
|
||||||
Player.prototype.bump = function () {
|
Player.prototype.bump = function () {
|
||||||
let player = this;
|
let player = this;
|
||||||
|
|
||||||
if (player.ticks < 10) {
|
if (player.ticks < 7) {
|
||||||
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;
|
||||||
|
|
||||||
|
|
4
index.js
4
index.js
|
@ -30,8 +30,8 @@ app.ws('/', function (ws, req) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
data = {};
|
data = {};
|
||||||
}
|
}
|
||||||
let { vel, dir, you } = data;
|
let { vel, dir, you, ticks } = data;
|
||||||
let data2 = { vel, dir, you };
|
let data2 = { vel, dir, you, ticks };
|
||||||
game.entities[playerI] = Object.assign(game.entities[playerI], data2);
|
game.entities[playerI] = Object.assign(game.entities[playerI], data2);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Game extends GameBasic {
|
||||||
|
|
||||||
ctx.translate(player.camera.x + cs / 2, player.camera.y + cs / 2);
|
ctx.translate(player.camera.x + cs / 2, player.camera.y + cs / 2);
|
||||||
|
|
||||||
ctx.drawImage(assetsIn[2],-width/2,-height/2,width,height);
|
ctx.drawImage(assetsIn[2], -width / 2, -height / 2, width, height);
|
||||||
|
|
||||||
for (let ent of entities) {
|
for (let ent of entities) {
|
||||||
if (ent.health <= 0) continue;
|
if (ent.health <= 0) continue;
|
||||||
|
@ -50,7 +50,7 @@ class Game extends GameBasic {
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
|
|
||||||
ctx.drawImage(assetsIn[0], ent.pos.x - 64 / 2, ent.pos.y - 64 / 2, 64, 64);
|
ctx.drawImage(assetsIn[0], ent.pos.x - 64 / 2, ent.pos.y - 64 / 2, 64, 64);
|
||||||
|
|
||||||
ctx.fillStyle = ent.you.split('-')[0];
|
ctx.fillStyle = ent.you.split('-')[0];
|
||||||
ctx.strokeStyle = "rgb(255,255,255)";
|
ctx.strokeStyle = "rgb(255,255,255)";
|
||||||
ctx.lineWidth = "8";
|
ctx.lineWidth = "8";
|
||||||
|
@ -91,12 +91,12 @@ class Game extends GameBasic {
|
||||||
sync() {
|
sync() {
|
||||||
let { player } = this;
|
let { player } = this;
|
||||||
|
|
||||||
let { vel, dir, you } = player;
|
let { vel, dir, you, ticks } = player;
|
||||||
|
|
||||||
this.ws.send(JSON.stringify({ vel, dir, you }));
|
this.ws.send(JSON.stringify({ vel, dir, you, ticks }));
|
||||||
}
|
}
|
||||||
recv({data}) {
|
recv({ data }) {
|
||||||
let {player} = this;
|
let { player } = this;
|
||||||
let you = player.you;
|
let you = player.you;
|
||||||
|
|
||||||
let entList = JSON.parse(data);
|
let entList = JSON.parse(data);
|
||||||
|
@ -104,10 +104,10 @@ class Game extends GameBasic {
|
||||||
x.handleTick = Player.prototype.handleTick;
|
x.handleTick = Player.prototype.handleTick;
|
||||||
return x;
|
return x;
|
||||||
})
|
})
|
||||||
|
|
||||||
let matchingPlayer = entList.filter(x => x.you == you)
|
let matchingPlayer = entList.filter(x => x.you == you)
|
||||||
|
|
||||||
this.player = Object.assign(this.player || new Player(false,false),matchingPlayer[0]);
|
this.player = Object.assign(this.player || new Player(false, false), matchingPlayer[0]);
|
||||||
|
|
||||||
this.entities = entList;
|
this.entities = entList;
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ class Game extends GameBasic {
|
||||||
|
|
||||||
this.ws = new WebSocket(window.location.href);
|
this.ws = new WebSocket(window.location.href);
|
||||||
|
|
||||||
this.ws.addEventListener('message',function(e) { that.recv(e) });
|
this.ws.addEventListener('message', function (e) { that.recv(e) });
|
||||||
|
|
||||||
setInterval(function () { that.render() }, 1000 / 60);
|
setInterval(function () { that.render() }, 1000 / 60);
|
||||||
setInterval(function () { that.sync() }, 1000 / 5);
|
setInterval(function () { that.sync() }, 1000 / 5);
|
||||||
|
|
Loading…
Reference in a new issue