mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-09 13:10:59 +00:00
add writeOthers function
This commit is contained in:
parent
71d6c1fa8c
commit
5f9a006132
1 changed files with 19 additions and 16 deletions
31
app.js
31
app.js
|
|
@ -195,25 +195,28 @@ server.on('login', function(client) {
|
|||
sendRelativePositionChange(client,toFixedPosition(position),onGround);
|
||||
});
|
||||
|
||||
client.on('position_look', function(packet) {
|
||||
var position = new vec3(packet.x,packet.y,packet.z);
|
||||
var onGround=packet.onGround;
|
||||
sendRelativePositionChange(client,toFixedPosition(position),onGround);
|
||||
});
|
||||
|
||||
function writeOthers(packetName,packetFields)
|
||||
{
|
||||
getOtherClients().forEach(function (otherClient) {
|
||||
otherClient.write(packetName, packetFields);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function sendRelativePositionChange(client,newPosition,onGround) {
|
||||
if (uuidToPlayer[client.uuid].position) {
|
||||
var diff = newPosition.minus(uuidToPlayer[client.uuid].position);
|
||||
if(diff.distanceTo(new vec3(0,0,0))!=0)
|
||||
getOtherClients().forEach(function (otherClient) {
|
||||
otherClient.write('rel_entity_move', {
|
||||
entityId: uuidToPlayer[client.uuid].id,
|
||||
dX: diff.x,
|
||||
dY: diff.y,
|
||||
dZ: diff.z,
|
||||
onGround: onGround
|
||||
});
|
||||
if (diff.distanceTo(new vec3(0, 0, 0)) != 0) {
|
||||
|
||||
writeOthers('rel_entity_move', {
|
||||
entityId: client.id,
|
||||
dX: diff.x,
|
||||
dY: diff.y,
|
||||
dZ: diff.z,
|
||||
onGround: onGround
|
||||
});
|
||||
}
|
||||
}
|
||||
uuidToPlayer[client.uuid].position = newPosition;
|
||||
uuidToPlayer[client.uuid].onGround=onGround;
|
||||
|
|
|
|||
Loading…
Reference in a new issue