Switching connection to a barycenter approach
This commit is contained in:
parent
5ffc5a420e
commit
2a8e3ea323
3 changed files with 60 additions and 36 deletions
|
@ -1,6 +1,6 @@
|
|||
import {MessageUserPosition} from "./Websocket/MessageUserPosition";
|
||||
import { World } from "./World";
|
||||
import { UserInterface } from "./UserInterface";
|
||||
import {PositionInterface} from "_Model/PositionInterface";
|
||||
|
||||
export class Group {
|
||||
static readonly MAX_PER_GROUP = 4;
|
||||
|
@ -24,6 +24,25 @@ export class Group {
|
|||
return this.users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the barycenter of all users (i.e. the center of the group)
|
||||
*/
|
||||
getPosition(): PositionInterface {
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
// Let's compute the barycenter of all users.
|
||||
this.users.forEach((user: UserInterface) => {
|
||||
x += user.position.x;
|
||||
y += user.position.y;
|
||||
});
|
||||
x /= this.users.length;
|
||||
y /= this.users.length;
|
||||
return {
|
||||
x,
|
||||
y
|
||||
};
|
||||
}
|
||||
|
||||
isFull(): boolean {
|
||||
return this.users.length >= Group.MAX_PER_GROUP;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue